Repository: uber-go/fx
Pull request #774 (2021-08-16 21:26:07)

Change when we log `fxevent.Invoking` and `fxevent.Invoked` events
For `fxevent` console implementation: no longer log non-error case for `fxevent.Invoke` event, while for zap implementation, start logging `fx.Invoking` case without stack.

codecov[bot]: # [Codecov](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) Report
> Merging [#774](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (6944dfd) into [master](https://codecov.io/gh/uber-go/fx/commit/77bb69762537355286ef4ed6ed773d79fb3b95e7?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) (77bb697) will **increase** coverage by `0.12%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/uber-go/fx/pull/774/graphs/tree.svg?width=650&height=150&src=pr&token=PYY9PSfaC6&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)

```diff
@@            Coverage Diff             @@
##           master     #774      +/-   ##
==========================================
+ Coverage   98.32%   98.44%   +0.12%     
==========================================
  Files          24       24              
  Lines         775      771       -4     
==========================================
- Hits          762      759       -3     
+ Misses         10        9       -1     
  Partials        3        3              
```


| [Impacted Files](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go) | Coverage Δ | |
|---|---|---|
| [fxevent/console.go](https://codecov.io/gh/uber-go/fx/pull/774/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZnhldmVudC9jb25zb2xlLmdv) | `100.00% <ø> (ø)` | |
| [fxevent/zap.go](https://codecov.io/gh/uber-go/fx/pull/774/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go#diff-ZnhldmVudC96YXAuZ28=) | `100.00% <100.00%> (+1.26%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go). Last update [77bb697...6944dfd](https://codecov.io/gh/uber-go/fx/pull/774?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=uber-go).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1d15f0e..fda9ca7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
 
 ## Unreleased
--  No changes yet.
+### Changed
+-  For `fxevent` console implementation: no longer log non-error case for `fxevent.Invoke`
+   event, while for zap implementation, start logging `fx.Invoking` case without stack.
 
 ## [1.14.1] - 2021-08-16
 ### Changed
diff --git a/fxevent/console.go b/fxevent/console.go
index 5f16815..88d1465 100644
--- a/fxevent/console.go
+++ b/fxevent/console.go
@@ -77,8 +77,6 @@ func (l *ConsoleLogger) LogEvent(event Event) {
 	case *Invoked:
 		if e.Err != nil {
 			l.logf("ERROR\t\tfx.Invoke(%v) called from:\n%+vFailed: %v", e.FunctionName, e.Trace, e.Err)
-		} else {
-			l.logf("fx.Invoke(%v) called from:\n%v", e.FunctionName, e.Trace)
 		}
 	case *Stopping:
 		l.logf("%v", strings.ToUpper(e.Signal.String()))
diff --git a/fxevent/zap.go b/fxevent/zap.go
index daeab9e..f28bb6d 100644
--- a/fxevent/zap.go
+++ b/fxevent/zap.go
@@ -88,18 +88,15 @@ func (l *ZapLogger) LogEvent(event Event) {
 				zap.Error(e.Err))
 		}
 	case *Invoking:
-		// Do nothing. Will log on Invoked.
-
+		// Do not log stack as it will make logs hard to read.
+		l.Logger.Info("invoking",
+			zap.String("function", e.FunctionName))
 	case *Invoked:
 		if e.Err != nil {
 			l.Logger.Error("invoke failed",
 				zap.Error(e.Err),
 				zap.String("stack", e.Trace),
 				zap.String("function", e.FunctionName))
-		} else {
-			l.Logger.Info("invoked",
-				zap.String("stack", e.Trace),
-				zap.String("function", e.FunctionName))
 		}
 	case *Stopping:
 		l.Logger.Info("received signal",


Test patch:
diff --git a/fxevent/console_test.go b/fxevent/console_test.go
index cf5b5a1..e866947 100644
--- a/fxevent/console_test.go
+++ b/fxevent/console_test.go
@@ -120,18 +120,6 @@ func TestConsoleLogger(t *testing.T) {
 			give: &Invoking{FunctionName: "bytes.NewBuffer()"},
 			want: "[Fx] INVOKE		bytes.NewBuffer()\n",
 		},
-		{
-			name: "Invoked/Success",
-			give: &Invoked{
-				FunctionName: "bytes.NewBuffer()",
-				Trace:        "foo()\n\tbar/baz.go:42\n",
-			},
-			want: joinLines(
-				"[Fx] fx.Invoke(bytes.NewBuffer()) called from:",
-				"foo()",
-				"	bar/baz.go:42\n",
-			),
-		},
 		{
 			name: "Invoked/Error",
 			give: &Invoked{
diff --git a/fxevent/zap_test.go b/fxevent/zap_test.go
index 0a03529..222eca2 100644
--- a/fxevent/zap_test.go
+++ b/fxevent/zap_test.go
@@ -164,12 +164,11 @@ func TestZapLogger(t *testing.T) {
 			},
 		},
 		{
-			name:        "Invoked/Success",
-			give:        &Invoked{FunctionName: "bytes.NewBuffer()"},
-			wantMessage: "invoked",
+			name:        "Invoking/Success",
+			give:        &Invoking{FunctionName: "bytes.NewBuffer()"},
+			wantMessage: "invoking",
 			wantFields: map[string]interface{}{
 				"function": "bytes.NewBuffer()",
-				"stack":    "",
 			},
 		},
 		{