No commit activity in last 3 years
No release in over 3 years
Plugin for semantic_logger that adds appender to send logs into journald. It depends on journald-native gem that provides the C-bindings
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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.