LaLogger: A general logger module wraps Fluentd-logger

Require: ruby 1.9.x, fluent-logger (not working on JRuby without modification).

Concepts

  • Include into any class, expose a singleton logger object and log_xxx functions:

    class LoggerUser def logger # initialize tag and log level, default level is 'WARN' LaLogger.new('la.logger.tag', LaLogger::ERROR) end

    def logger_this logger.error('oops! an error happend!', 'data') logger.post('custom.tag', 'message') end end

  • Silently fails-over to STDOUT if ENV['FLUENTD'] not defined.

To use fluentd service, define: ENV[FLUENTD] = 'localhost:24224' somewhere in your code before use the logger. Default port 24224 is optional.

You can use an additional ENV['FLUENTD_TAG'] to initialize default tag for the fluent-logger.

Note: as logger object is wrapped by a singleton class, there is no effect to change this setting after logger object has created.

Severities

Imported from ruby's default Logger::Severity, namely: debug, info, warn, error, fatal, unknown.