-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
Support log format specifications directly from the configuration, without having to create a new formatter. #78
Comments
Sounds like a great idea. Inheriting from the default formatter, a Pattern formatter should not be difficult to implement. Essentially create a new formatter, for example: Then to use the formatter when creating a new appender: formatter = SemanticLogger::Formatter::Pattern.new('%d %l %m')
SemanticLogger.add_appender(io: STDOUT, formatter: formatter) Possibly add another option for the formatter to specify whether the output should be colorized. formatter = SemanticLogger::Formatter::Pattern.new('%d %l %m', color: true)
SemanticLogger.add_appender(io: STDOUT, formatter: formatter) Or if using Rails Semantic Logger: config.rails_semantic_logger.format = SemanticLogger::Formatter::Pattern.new('%d %l %m', color: true) I had not considered passing options to the formatter when adding the appender as above. SemanticLogger.add_appender(io: STDOUT, formatter: {pattern: {pattern: '%d %l %m', color: true}} ) |
cheers - flat out at work at the moment, and a beginner at Ruby, I'll see if I can nudge it along in spare time |
I wouldn't mind taking a stab at this, but I'm not familiar with the log format you're referring to, so I'd need some test fixtures to show what sort of data you're trying to capture. As an example, what does You'd need a way to get the data from a context, tag, or proc, but otherwise it looks more or less like an sprintf string, which shouldn't be too hard to implement if one knows the shape of the data and the format you expect out of it. |
This is a great example of how to do string interpolations: https://github.com/reidmorrison/secret_config/blob/master/lib/secret_config/setting_interpolator.rb We don't have to restrict ourselves to just single character replacements either. Especially since most command line interfaces have moved away from single character options like We would also need to copy the base class over: https://github.com/reidmorrison/secret_config/blob/master/lib/secret_config/string_interpolator.rb This approach should also make it much easier to fit within the current formatters, since the methods could line up with the string interpolation names. |
Currently using Log4R - which allows a Pattern Based Formatter - eg
class PatternFormatter < BasicFormatter
This is useful to me because I log to stdout (a simple message format for users) AND I log a timestamped message to a file as well (that may be at a different log level)
Is there a way to get this with Semantic Logger ? My first thought is to write a new Appender, but, maybe other appenders could use the 'custom formatter' as well
Cheers & Thanks
The text was updated successfully, but these errors were encountered: