0.0
No commit activity in last 3 years
No release in over 3 years
Logger subclass to log to syslog using the RFC 5424 format, with support for STREAM- and DGRAM-mode domain sockets
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

SysLogger

Ruby Logger for interacting with syslog using RFC 5424 format.

CI Gem Version

Description

syslogger is a wrapper around the standard ruby Logger for logging via syslog. Messages passed to syslogger are formatted by default with RFC 5424. It allows for communication through sockets or files.

This work is licensed under the ISC license, a copy of which can be found in LICENSE.txt.

Install

gem install syslogger5424

or add the following line to Gemfile:

gem 'syslogger5424'

and run bundle install from your shell.

Usage

require 'syslogger'

log = SysLogger.new
log.info("Hello\nWorld")
# <190>1 2014-10-02T11:59:52.524177-07:00 HOSTNAME - - - [meta x-group="79748942"] Hello
# <190>1 2014-10-02T11:59:52.524177-07:00 HOSTNAME - - - [meta x-group="79748942"] World

When strings containing newlines are logged, lines are seperated and written. These lines are grouped together by the meta SD-ID under the x-group parameter.

The default facility is local7 (23). To change this or any other information in the header, set the logger's formatter after creation.

require 'syslogger'

log = SysLogger.new
log.formatter = SysLogger::Formatter::RFC5424.new("APP-NAME", "PROCID", "MSGID", "kern")

log.info("Hello\nWorld")
# <6>1 2014-10-02T12:16:54.222893-07:00 HOSTNAME APP-NAME PROCID MSGID [meta x-group="78784030"] Hello
# <6>1 2014-10-02T12:16:54.222893-07:00 HOSTNAME APP-NAME PROCID MSGID [meta x-group="78784030"] World

By default, SysLogger will write to $stdout. To override, either pass a device to the constructor or a block that can be called to create the device.

require 'syslogger'

log = SysLogger.new(&SysLogger::Creators::unix_dgram_socket("/path/to/datagram/socket"))
log.info("Hello\nWorld")