Search code examples
rubylog4r

syslog output for log4r example


Can some one post an example of using syslog outputter for log4r, I am currently using stdout but want to log to syslog.

mylog = Logger.new 'mylog'
mylog.outputters = Outputter.stdout
mylog.info "Starting up."

raj


Thanks also to the following blog posts.

Angrez's blog: Log4r - Usage and Examples

ProgrammingStuff: Log4r


Solution

  • Kind of lame answering my own question, but I found answer to this and adding it for later searches.

    For some reason I need to require log4r/outputter/syslogoutputter explicitly other wise SyslogOutputter would cause "uninitialized constant SyslogOutputter (NameError)" error. Other outputters do not seem to have this problem.

    require 'rubygems'
    require 'log4r'
    require 'log4r/outputter/syslogoutputter'
    mylog = Logger.new 'mylog'
    mylog.outputters = SyslogOutputter.new("f1", :ident => "myscript")
    mylog.info "Starting up."
    

    raj