Closed yourtallness closed 10 years ago
By the way, I have to say I'm confused as to how to configure an appender for a specific logger.
I'm probably misinterpreting something but it seems that appenders are added only globally (add_appender method in SemanticLogger module)?
// Add a new logging appender as a new destination for all log messages // emitted from Semantic Logger
// Appenders will be written to in the order that they are added
Correct, appenders are on a global basis. The gem rails_semantic_logger is designed to completely replace any existing loggers with a single solution that uses SemanticLogger.
Thanks for the feedback.
How would you recommend one defines a custom logger for their needs with an appender only for that particular logger?
My use case is:
For the time being I have set my @custom_logger directly to an SemanticLogger::Appender and in this manner not taking advantage of the logger 'registry' nor async logging.
If you are not using SemanticLogger anywhere else in your Rails application you can use it directly without using the rails_semantic_logger gem. Just create a Rails initializer to setup your SemanticLogger. The global instance just becomes your exclusive instance, without touching any of the existing loggers.
Actually, I am using the rails_semantic_logger gem in order to replace all native Rails loggers with SemanticLogger, since I like the async nature and the named loggers.
However, since the appenders are global and per the documentation, separation of what logs go to which appender can (to my understanding) only be determined via the log level of each appender, do I understand correctly that it is not possible to log via a specific appender on demand, without logging to all other defined appenders (assuming that they don't differ by log_level, to take that out of the equation)?
I stumbled upon this when implementing an appender for logging specific messages to a Kafka broker only (and not to file or STDOUT), however I saw that all other logs ended up in Kafka as well and the Kafka-specific logs also ended up in the Rails log output.
Would you recommend another gem for this (log4r, logging) or can SemanticLogger also cover this use case?
Yes, I can understand this requirement. The technique used by log4j is to allow each appended to limit the scope of what classes are logged to that appender.
It is definitely a feature I want to add to SemanticLogger and was really waiting for end-user demand before writing it. Along with this requirement is the need for a configuration file in which the appenders can be configured, class specific log levels can be set and appender specific filters applied.
Well, definitely a +1 from me for a per logger appender scope :-)
Thanks for the feedback
Re-opening and converting to a feature request.
Hello,
It is tempting to use the Loggable module in e.g. Rails controllers, but there may be confusion between the logger method and the logger provided by Rails / config.
Could you provide an example of defining a custom logger for a particular controller (with custom appender/s) in a singleton fashion and so that it does not collide with other loggers possibly used within the same controller?
Thank you