rudionrails / yell

Yell - Your Extensible Logging Library
MIT License
311 stars 21 forks source link

misleading wiki example, no-arg constructor #29

Closed jrochkind closed 10 years ago

jrochkind commented 10 years ago

Thanks for yell, it's awesome!

On the bottom of this wiki page: https://github.com/rudionrails/yell/wiki/101-different-adapters-for-different-log-levels

Is this example:

logger = Yell.new do |l|
  l.level = :info # will only pass :info and above to the adapters

  l.adapter :datefile, 'production.log', :level => Yell.level.lte(:warn)
  l.adapter :datefile, 'error.log', :level => Yell.level.gte(:error)
end

The example is mis-leading, you think you're going to get just production.log and error.log, but you also get a (by default) development.log, the Yell::Logger with no arguments will use it's default logic to pick a log location, and then the two l.adapter lines are on top of that. (It'll also be fixed to the default level of 'info', so none of the extra adapters will be able to log anything more generous than that)

I'm not sure what to replace the example with, I'm honestly not sure what the cleanest way is to do what the example is trying to show? Suggestions?

One way would be:

logger = Yell.new(:null) do |l|
  l.level = :info # will only pass :info and above to the adapters

  l.adapter :datefile, 'production.log', :level => Yell.level.lte(:warn)
  l.adapter :datefile, 'error.log', :level => Yell.level.gte(:error)
end

But I'm not sure that's what you'd want to suggest as a best practice. The whole Yell.new ... do syntax seems a bit less useful, when you realize the logger will do default things if you don't give it args.

rudionrails commented 10 years ago

Hey there, as you are passing a block to the Yell::Logger#initialize method, you do not get any default adapter. As one would expect, Yell only creates 'production.log' and 'error.log' (depending on the log level).

I am not sure which line you are referring to, exactly. Can you give me some more information on this?

jrochkind commented 10 years ago

Hmm, you're right,now I can't reproduce now. In my actual app, using this pattern, I was getting a development.log logfile created as a 'default log' even though. But now I can't reproduce with a simple test case; I guess I must have been doing something slightly different in my actual app, not sure.