{"action":"created","issue":{"url":"https://api.github.com/repos/uber-go/fx/issues/647","repository_url":"https://api.github.com/repos/uber-go/fx","labels_url":"https://api.github.com/repos/uber-go/fx/issues/647/labels{/name}","comments_url":"https://api.github.com/repos/uber-go/fx/issues/647/comments","events_url":"https://api.github.com/repos/uber-go/fx/issues/647/events","html_url":"https://github.com/uber-go/fx/issues/647","id":365526558,"node_id":"MDU6SXNzdWUzNjU1MjY1NTg=","number":647,"title":"Should a provided Logger be useable within fx.Logger() ?","user":{"login":"DavyJ0nes","id":7294200,"node_id":"MDQ6VXNlcjcyOTQyMDA=","avatar_url":"https://avatars1.githubusercontent.com/u/7294200?v=4","gravatar_id":"","url":"https://api.github.com/users/DavyJ0nes","html_url":"https://github.com/DavyJ0nes","followers_url":"https://api.github.com/users/DavyJ0nes/followers","following_url":"https://api.github.com/users/DavyJ0nes/following{/other_user}","gists_url":"https://api.github.com/users/DavyJ0nes/gists{/gist_id}","starred_url":"https://api.github.com/users/DavyJ0nes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavyJ0nes/subscriptions","organizations_url":"https://api.github.com/users/DavyJ0nes/orgs","repos_url":"https://api.github.com/users/DavyJ0nes/repos","events_url":"https://api.github.com/users/DavyJ0nes/events{/privacy}","received_events_url":"https://api.github.com/users/DavyJ0nes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-01T15:51:23Z","updated_at":"2018-10-02T17:53:20Z","closed_at":null,"author_association":"NONE","body":"Firstly thank you for creating this package! It has been super useful in creating easily configured applications by allowing dependencies to be defined at runtime.\r\n\r\nThis issue is a question/request that I think might be useful for other users. The question is:\r\n\r\n> Do we think that it is a good idea to allow `fx.Logger` to use a logger that has been provided, similar to the behaviour of `fx.Invoke`?\r\n\r\n### More Info\r\nI have a logger that can be configured from environment variables that I am using within my application. The parsing of the environment variables into configuration settings is also used by other components of the application.\r\n\r\nIn order to use the same configuration of logger for `fx` and my application I need to instantiate the environment settings twice, both within `fx.Provide` and outside so that I can create `logger` that will be used both as a dependency for `router` and `server` as well as for `fx`. e.g.\r\n\r\n```go\r\nfunc StartApplication() {\r\n\tlogSettings, err := config.NewLoggerSettings(config.GetEnvironmentSettings)\r\n\tlogger := config.NewLogger(logSettings)\r\n\r\n\tfx.New(\r\n\t\tfx.Provide(\r\n                        config.GetEnvironmentSettings,\r\n                        logger,\r\n\t\t\tconfig.NewServerSettings,\r\n\t\t\trouter.New,\r\n\t\t\tserver.New,\r\n\t\t),\r\n\t\tfx.Logger(logger),\r\n\t\tfx.Invoke(server.Start),\r\n\t).Run()\r\n}\r\n```\r\n\r\nIdeally I would like to be able to do something like the following:\r\n\r\n```go\r\nfunc StartApplication() {\r\n\tfx.New(\r\n\t\tfx.Provide(\r\n                        config.GetEnvironmentSettings,\r\n                        config.NewLoggerSettings,\r\n                        config.NewLogger,\r\n\t\t\tconfig.NewServerSettings,\r\n\t\t\trouter.New,\r\n\t\t\tserver.New,\r\n\t\t),\r\n\t\tfx.Logger(config.NewLogger),\r\n\t\tfx.Invoke(server.Start),\r\n\t).Run()\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/uber-go/fx/issues/comments/426369537","html_url":"https://github.com/uber-go/fx/issues/647#issuecomment-426369537","issue_url":"https://api.github.com/repos/uber-go/fx/issues/647","id":426369537,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNjM2OTUzNw==","user":{"login":"abhinav","id":41730,"node_id":"MDQ6VXNlcjQxNzMw","avatar_url":"https://avatars0.githubusercontent.com/u/41730?v=4","gravatar_id":"","url":"https://api.github.com/users/abhinav","html_url":"https://github.com/abhinav","followers_url":"https://api.github.com/users/abhinav/followers","following_url":"https://api.github.com/users/abhinav/following{/other_user}","gists_url":"https://api.github.com/users/abhinav/gists{/gist_id}","starred_url":"https://api.github.com/users/abhinav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhinav/subscriptions","organizations_url":"https://api.github.com/users/abhinav/orgs","repos_url":"https://api.github.com/users/abhinav/repos","events_url":"https://api.github.com/users/abhinav/events{/privacy}","received_events_url":"https://api.github.com/users/abhinav/received_events","type":"User","site_admin":false},"created_at":"2018-10-02T17:53:20Z","updated_at":"2018-10-02T17:53:20Z","author_association":"COLLABORATOR","body":"Hello and thank you! We're glad people found it useful.\r\n\r\nThis is a valid idea but it presents some difficulties: In many scenarios, and\r\ncertainly in our own internal usage of Fx, we need to instantiate some other\r\nmodules (environment inspection, configuration loading, etc.) before we can set\r\nup the logger correctly. Much of Fx's logging happens before we\r\ninvoke/instantiate anything (\"here is everything I know about\") followed by the\r\ninvokes (\"here is what I actually ran and why\"), followed by the lifecycle\r\noperations. If acquiring the logger requires an invoke-like operation, we'll be\r\nunable to log anything before that phase.\r\n\r\nThat said, I think this is a valid problem and we are open to a better solution\r\nto this. Meanwhile, the way you're doing this currently is a reasonable\r\nworkaround.\r\n\r\nThanks!\r\n"}}
{"actor":{"display_login":"abhinav"}}