Topic: [SOLVED] Setting up a custom log

Hey folks,

i want to create a custom log so that i can write something like

myOwnLogger.debug("foo")

but i am stuck right now.

I found this interesting howto: http://maintainable.com/articles/rails_logging_tips

(Section: Create Audit Log)

The Howto is fantastic, but i am stuck at this point:

To use the new AuditLogger, instantiate it with a File  instance:

logfile = File.open('/path/to/audit.log', 'a')    
audit_log = AuditLogger.new(logfile)

This is fine for a quick try in the console, but how do i use this in rails?

To be specific, where do i have to put this

logfile = File.open('/path/to/audit.log', 'a')    
audit_log = AuditLogger.new(logfile)

in rails, so that i can use

audit_log.debug("foo")

?

Thx for every help!

Last edited by j0llyr0g3r (2008-10-24 12:56:22)

Re: [SOLVED] Setting up a custom log

Hmmm,

am i the only one trying to set up a custom log-file in the rails-world?

I would also appreciate a RTFM, if you tell me which one.......

Re: [SOLVED] Setting up a custom log

I also used the tips from http://maintainable.com/articles/rails_ … audit-logs

This goes to your environment.rb :

audit_logfile = File.open("#{RAILS_ROOT}/log/audit.log", 'a')
audit_logfile.sync = true
AUDIT_LOG = AuditLogger.new(audit_logfile)

To use it, simply call
AUDIT_LOG.error 'hello world'

Bye,
der_flo

Re: [SOLVED] Setting up a custom log

Hi and thx @der_flo.

Works like a charm, i still have to get use to the fact, that rails-config files are in ruby themselves.....