Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more examples to docs about how to integrate into Rails #8

Open
TylerRick opened this issue Jun 6, 2012 · 4 comments
Open

Add more examples to docs about how to integrate into Rails #8

TylerRick opened this issue Jun 6, 2012 · 4 comments

Comments

@TylerRick
Copy link

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!

@undr-rowr
Copy link

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.

@chrishough
Copy link

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

@ba1ash
Copy link

ba1ash commented Mar 17, 2017

Hi there!
Any updates according this issue?

@TylerRick
Copy link
Author

Add to this list:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants