Skip to content

Plugin for semantic_logger gem providing systemd-journal appender

License

Notifications You must be signed in to change notification settings

scarfacedeb/semantic_logger_journald

Repository files navigation

SemanticLoggerJournald

Plugin for semantic_logger that adds appender to send logs into journald.

It uses journald-logger under the hood.

Installation

gem "semantic_logger_journald", "~> 0.1"

Usage

To add journald appender to semantic_logger:

require "semantic_logger_journald"

journald_appender = SemanticLoggerJournald::Appender.new(syslog_id: "my_service")
SemanticLogger.add_appender(appender: journald_appender)

logger = SemanticLogger[MyClass]
logger.info "Signed In", user_id: 1

You can also directly pass a journald-logger instance:

jlogger = Journald::Logger.new("my_service")
journald_appender = SemanticLoggerJournald::Appender.new(logger: jlogger)
SemanticLogger.add_appender(appender: journald_appender)

Formatter

By default, SemanticLoggerJournald::Formatter flattens the payload keys to convert them into individual fields:

logger.info "Paid", order: { id: 1, status: "new" }

It'll produce the following journald fields:

MESSAGE=Paid
ORDER__ID=1
ORDER__STATUS=new

If you'd rather keep the payload intact, pass a custom formatter:

formatter = SemanticLoggerJournald::Formatter.new(flatten_payload: false)

journald_appender = SemanticLoggerJournald::Appender.new(
  syslog_id: "my_service", 
  formatter: formatter
)

SemanticLogger.add_appender(appender: journald_appender)

logger.info "Paid", order: { id: 1, status: "new" }

It'll produce the following journald fields:

MESSAGE=Paid
ORDER={ id: 1, status: "new" }

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/scarfacedeb/semantic_logger_journald.

License

The gem is available as open source under the terms of the MIT License.

About

Plugin for semantic_logger gem providing systemd-journal appender

Topics

Resources

License

Stars

Watchers

Forks

Languages