TwP / logging

A flexible logging library for use in Ruby programs based on the design of Java's log4j library.
https://rubygems.org/gems/logging
MIT License
529 stars 100 forks source link

UDP appender #54

Open petemounce opened 11 years ago

petemounce commented 11 years ago

Would a UDP appender be possible?

We use statsd for our metrics collection endpoint, which wants UDP packets containing strings like dotted.bucket.name:value|bucket-type and I'd like to use logging to push messages.

Also, while I think about it - is it possible to transform messages? So when writing to appender A, it would apply a transform to the message (in this case, probably discard the English text and do something like transform the class into a dot-separated string, glue the log-level on the end, and maybe parse a value out of the message itself).

TwP commented 11 years ago

A UDP appender is definitely possible. With an appender, you give it a Layout object that will format messages however you desire. Take a look at the basic layout to get a feel for how they work. But you can go hog wild with layouts to get messages into the format you need.

The approach I would take for a UDP appender is to wrap a statsd Ruby gem with an appender. So all the heavy lifting would be done by the gem, and your appender would simply call methods provided by the library (I have not looked to see if a statsd gem is available).

troy commented 11 years ago

Part of this may be possible with the existing IO appender and remote_syslog_logger. It was written for Papertrail so it uses syslog framing, but has the guts of a UDP transmitter in RemoteSyslogLogger::UdpSender. I think with an additional alias_method :syswrite, :transmit, a RemoteSyslogLogger could be passed to the existing IO appender. Worst case it's an example.