lumberjack icon indicating copy to clipboard operation
lumberjack copied to clipboard

Add more examples to docs about how to integrate into Rails

Open TylerRick opened this issue 12 years ago • 4 comments

Lumberjack claims that it "can be a drop in replacement for Logger or ActiveSupport::BufferedLogger" -- but it doesn't give any instructions on how to use it as a drop-in replacement in Rails!

I finally figured it out (I think), but I would suggest adding some examples and instructions...

Under "Pluggable Devices", it lists a bunch of devices (such as Lumberjack::Device::SizeRollingLogFile) but doesn't actually tell you _how_ to instruct Lumberjack to use a different device other than the default. Perhaps add something like:

When you simply specify a file name, the default device that will be used is ____. To use a different device, just pass an instance of the device to Lumberjack.new, like this:

   logger = Lumberjack::Logger.new(Lumberjack::Device::SizeRollingLogFile.new("application.log")

Some questions to consider when integrating Lumberjack into a Rails app...

  1. How do I get it to use the default Rails log file locations (logs/development.log, etc.)?
  2. Is it compatible with ActiveSupport::TaggedLogging? How do I use it with TaggedLogging?
  3. Does it respect your app's config.log_level = :debug setting? (Apparently no...)

I think I finally figured out the answers to these questions...

This is what I ended up using in my config/application.rb:

    config.logger = Lumberjack::Logger.new(
      Lumberjack::Device::SizeRollingLogFile.new(
        Rails.root + 'log' + (Rails.env + ".log"),
        max_size: 100.megabytes,
        template: lambda{|e| "#{e.severity_label[0, 1]} #{e.message}"}
      ), level: :debug
    )
    config.logger = ActiveSupport::TaggedLogging.new(config.logger)
    config.log_tags = [ :uuid ]

Perhaps you could add that as an example to your Readme as an example of using it with TaggedLogging?

Here's an example of the output produced with this configuration...

Started GET "/test/logging" for 127.0.0.1 at 2012-06-05 16:25:15 -0700
I [dfa3ef2503ce27958205f3254552c6bf] Processing by TestController#logging as HTML
I [dfa3ef2503ce27958205f3254552c6bf] ... Rails.app.config.log_level=:debug
D [dfa3ef2503ce27958205f3254552c6bf] ... debug message
I [dfa3ef2503ce27958205f3254552c6bf] ... info message
W [dfa3ef2503ce27958205f3254552c6bf] ... warn message
E [dfa3ef2503ce27958205f3254552c6bf] ... error message
I [dfa3ef2503ce27958205f3254552c6bf]   Rendered text template (0.0ms)
I [dfa3ef2503ce27958205f3254552c6bf] Completed 200 OK in 184ms (Views: 183.3ms | ActiveRecord: 0.0ms)

Questions I still have:

  1. How do I make sure concurrent requests don't interleave their log output? Is this taken care of automatically by the flush in https://github.com/rails/rails/blob/master/railties/lib/rails/rack/logger.rb? Does it only work if buffer_size is greater than 0?
  2. How is Lumberjack different from ActiveSupport::TaggedLogging? How is it similar? When would I use one over the other?
  3. Is there any reason to need/use https://github.com/bdurand/lumberjack/blob/master/lib/lumberjack/rack/unit_of_work.rb if one is using ActiveSupport::TaggedLogging? They appear to have the same purpose. When would I need or want to use unit_of_work in a Rails app?
  4. Is there a way to configure my logger with Lumberjack so that it actually uses the value of config.log_level from your app's config/environments/{env}.rb file? The problem is, if I set config.logger in config/application.rb, that is before config/environments/{env}.rb has been loaded... But it works when using the default Rails logger so I assume it must be possible...

I really like Lumberjack so far -- especially like how modular it is. Keep up the good work!

TylerRick avatar Jun 06 '12 00:06 TylerRick

thank you, albeit it's a year late. ran across lumberjack and I was wondering the same thing after reading the README. again, thanks for the example.

undr-rowr avatar Jul 26 '13 13:07 undr-rowr

+1 to examples. I noticed quite a few pending issues with this gem, is it still being maintained?

chrishough avatar Oct 25 '13 04:10 chrishough

Hi there! Any updates according this issue?

ba1ash avatar Mar 17 '17 09:03 ba1ash

Add to this list:

  • Would like to see an example of how to use Lumberjack with ActiveSupport::TaggedLogging (see #33).

TylerRick avatar May 08 '18 18:05 TylerRick