Reputation: 4963
I'm trying create a log specifically for logging user account activity. I created this inside the initializer folder:
class UserTraceLogger < Logger
def format_message(severity, timestamp, progname, msb)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\r\n"
end
end
logfile = File.open("#{RAILS_ROOT}/log/user.log", 'a')
userlog = AuditLogger.new(logfile)
userlog.sync = true
I would like to be able to then use it in my code with:
userlog.info 'my message'
Right now I am getting this error message when I start the rails server:
config/initializers/usertrace_logger.rb:10:in `<top (required)>': uninitialized constant AuditLogger (NameError)
I'm pretty new to rails. I'm not entirely sure this is the correct way to create a global instance or know what exactly I'm missing.
What am I doing wrong?
Upvotes: 2
Views: 417
Reputation: 4311
Did you mean UserTraceLogger.new(logfile)
instead of AuditLogger.new(logfile)
?
Otherwise you may be missing require 'audit_logger'
somewhere.
Upvotes: 4