Separate logger for my application?

I want my application (library) to use a different logger than the logger in the project it’s included in. Not sure I’m explaining that well. Maybe code will help…

# config.exs
config :logger, level: :debug
config :my_cool_library, logger: { level: :info }

So that would mean the logger for my_cool_library is different from the main project. How to do this? Logger doesn’t seem to provide a way to “instantiate” (there is no start_link function).

Any ideas?

did you find a solution to this?

1 Like

Instead of using different loggers you should instead filter based on different metadata, an easy way for a project is to just filter based on the modules or so.

@OvermindDL1, than you! Every other resource I stumbled upon in the last few days, are pointing to the same or very similar solution. But I failed to find any concrete examples. Is it filtering so simple and obvious, that nobody was caring to put some more examples on the wild? I am pretty sure I don’t know where to look for them :frowning:

Agree with @Florin about the concrete examples.

Also, how would one say “I want warning level logging for MyCoolApp, but debug level logging for Phoenix”?


You ‘filter’ based on warning level per ‘output’. Some outputs, like the logger_file_backend one can take additional filters (that I really think should be built in to Elixir’s Logger) that let’s you refine based on meta-information as well (that I use excessively). :slight_smile:

I’m having issues with windows freezing at the moment so cannot toss a link, but it is in the Logger documentation. :slight_smile:

1 Like

(that I really think should be built in to Elixir’s Logger)

That’s what I was hoping to find too, for example:, "and a message")

but Logger was not designed like that :frowning:

Eh that reeks of a pending bug to send to a specific backend at the log location to me… What if you suddenly want to log all logs from a certain, say, module to a specific file as you debug something in production, you couldn’t then… I really like the way logger_file_backend handles metadata for filtering, simple but powerful enough for everything I’ve needed to date.

sure, you’re right. See, definitely smarter people than me, spent a lot of their time to come out with the current (filtering) solution, which probably is the best?! But damn, it is hard to find the selling points for what they did, in a way that every noob (myself included) will understand it and embrace it unconditionally. And if that was the case, you’d never see this level of confusion all around the Logger topic, especially in the less skilled audience; me being part of it. Just reading the Logger docs, which btw they are very good, like any other Elixir docs, you won’t just see the filtering goodness w/o talking with more experienced devs. So thank you for feedback and for opening our eyes :slight_smile:

1 Like

This blog post might help you: Elixir Logger And The Power Of Metadata