LaLogger: A general logger module wraps Fluentd-logger
Require: ruby 1.9.x, fluent-logger (not working on JRuby without modification).
Concepts
Initialize a logger object with
label
and log level:class LoggerUser def logger # initialize tag and log level, default level is 'WARN' LaLogger.new('la.logger.tag', LaLogger::ERROR) end
def logger_this # use warn, error, fatal, ... to log messages with optional # extra information in hash format: logger.error('oops! an error happend!', 'data')
# send (post) message using fluent-logger object directly logger.post('custom.tag', {custom: 'message'})
end end
Silently fails-over to
STDOUT
ifENV['FLUENTD']
not defined.
To use fluentd service, define: ENV[FLUENTD] = 'localhost:24224:label'
somewhere in your code before use the logger.
Default port 24224
is optional, label
is also optional (default is nil
).
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
.
Develop or Test
Run foreman start
to start the fluentd
server fro test.
Production
Set up your fluentd conf file, set
<match lalogger.**>
where lalogger
equals the tag parts you set in your ENV['FLUENTD']
variable.
Optionally set remove_tag_prefix lalogger.
to remove tag from collection names.