Skip to content

Why don't you instantiate a custom logger that you would inject as a dependency? #36

Answered by benbjohnson
lobre asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @lobre, great questions.

I was often being told that loggers are explicit dependencies like any other and that it was a good idea to inject them the same way as a DB or any other application dependency. I know it is not a general rule, and that it always depends on context but I wanted to know why you decided to use the global logger of the log package instead of defining your own?

I used to inject loggers as dependencies to everything but I've found that's it's overly complicated in most cases—especially for small/medium-sized projects. Simply having a log available globally from anywhere makes things easier. I'll usually switch to an injected logger once I have a good reason.

Why …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lobre
Comment options

Answer selected by benbjohnson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants