The Logger.info/2 macro emits the provided message at the :info level. Note the arguments given to info/2 will only be evaluated if a message is logged. For instance, if the Logger level is set to :warning , :info messages are never logged and therefore the arguments given above won’t even be executed.
A buggy logger message expression escaped unit test checks due to the configured log level. Is there a way to force evaluation of all log messages? Ideally I’m thinking of something like
Yeah that’s an interesting idea, in particular because in tests you usually have a really high log level set since you don’t want to actually see the output.
Sounds like interesting concept. It shouldn’t be super hard to implement it, though I would worry a little about potential performance issues. Though I think that it could be compile time only flag and there would be no performance hit in such case.
Got bitten by this behaviour again: Logger.info("Failed foo: #{foo}") blew up on production, but was not caught by tests because the logging level is set to :warn for tests.
An alternative that I tried was setting the logging level to :debug in tests and doing ExUnit.start(capture_log: true). The disadvantage of this approach is that the ExUnit output is very noisy when a test fails - it prints out all logs.
@josevalim Any thoughts on what would be the best approach to handle this?
Quite a natural limitation of code injection at compile-time, I’m not sure about performance implications but I think that a logger option for runtime evaluation would be welcome.