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

Continue writing to log file? #52

Closed
oystersauce8 opened this issue Jul 15, 2015 · 8 comments
Closed

Continue writing to log file? #52

oystersauce8 opened this issue Jul 15, 2015 · 8 comments

Comments

@oystersauce8
Copy link
Contributor

Is it possible to continue writing to the regular environment.log file, in the default non-json rails log format?

we use logstash logger like this
config.logstash = [ { type: :file, path: 'log/development.log' }, { type: :file, path: '/var/log/development.log' } ]

@dwbutler
Copy link
Owner

Hi,

It's not possible to do this from a single Ruby Logger instance. A single Logger has a single Formatter.

I'm not saying it's impossible, but it's not something that LogStashLogger supports out of the box.

@oystersauce8
Copy link
Contributor Author

i work next door to UCLA! :)

anyway, can the railtie.rb be tweaked to accomplish this?

I see app.config.logger = logger

@dwbutler
Copy link
Owner

That's cool! I graduated from UCLA in 2006 in physics. Now I live in Pasadena and work as a software engineer.

Back to the topic - The Ruby Logger class is designed to only log a single format. Internally, LogStashLogger only creates a single logger, that logs to multiple output devices. It can only log what is output by the formatter.

An alternative design we could explore would be to instead have multiple loggers, each with a configurable formatter.

@ghost
Copy link

ghost commented Sep 4, 2015

Alternatively you can use https://github.com/ffmike/multilogger as a shim in front of multiple logger instances - one from LogStashLogger and one from ActiveSupport.

@dwbutler
Copy link
Owner

dwbutler commented Sep 5, 2015

@ffmike Thanks for the tip! I was planning to offer similar functionality in an upcoming release. Now that I've seen MultiLogger, I might just pull it in as a dependency instead of rolling my own.

@dwbutler
Copy link
Owner

dwbutler commented Sep 7, 2015

@ffmike I was planning to pull in your code, but it doesn't appear to be released as a gem on rubygems.org. Mind if I vendor in your code and credit you?

dwbutler added a commit that referenced this issue Sep 7, 2015
The new :multi_logger type writes log messages to multiple loggers. Each logger can have its own formatter.

Fixes #52
@ghost
Copy link

ghost commented Sep 7, 2015

Sure, help yourself. I banged that together quickly for use in one of our internal projects and haven't bothered to gemify it.

@dwbutler
Copy link
Owner

dwbutler commented Sep 7, 2015

@ffmike Thanks! I credited you in the readme.

Support for this released in 0.13.0. Example configuration:

config.logstash.type = :multi_logger
config.logstash.outputs = [
  { type: :file, path: 'log/development.log', formatter: ::Logger::Formatter },
  { type: :file, path: '/var/log/development.log' }
] 

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

No branches or pull requests

2 participants