Rails 3.2 Logger

44 views
Skip to first unread message

Erwin

unread,
Nov 19, 2012, 8:11:58 AM11/19/12
to rubyonra...@googlegroups.com
I read the Rails doc about Tagged logger, it seems great , but I am missing some stuff :

- where should I define the Logger class :
        Logger = ActiveSupport::TaggedLogging.new( File.join(Rails.root, "log", "new_logger_#{Rails.env}.log)

- is it possible to define multiple Logger classes to output into different log files ?
        LoggerA = ActiveSupport::TaggedLogging.new( File.join(Rails.root, "log", "new_logger_A_#{Rails.env}.log)
        LoggerB = ActiveSupport::TaggedLogging.new( File.join(Rails.root, "log", "new_logger_B_#{Rails.env}.log)

thanks for feedback

Erwin

unread,
Nov 19, 2012, 10:59:42 AM11/19/12
to rubyonra...@googlegroups.com
I can use the standard buffer class  :

MyBufferedLogger = ActiveSupport::BufferedLogger.new(Rails.root.join('log/my_buffered.log'))

MyBufferedLogger.info "Hello World!"   # => OK

but I cannot do it using the TaggedLogging buffer class

MyTaggedLogger = ActiveSupport::TaggedLogging.new(Rails.root.join('log/my_tagged.log'))

MyTaggedLogger.tagged("BCX") { MyTaggedLogger.info "Hello World!" } # error
NoMethodError: undefined method `add' for #<Pathname:/Users/yves/github/local/yoogroop/log/my_tagged.log>

I guess I a wrong somewhere ....


thanks for feedback

Erwin

unread,
Nov 19, 2012, 11:05:03 AM11/19/12
to rubyonra...@googlegroups.com
[SOLVED]   in doc :  TaggedLogging  is a wrapper ...

so 
MyTaggedLogger = ActiveSupport::BufferedLogger.new(Rails.root.join('log/my_tagged.log'))
MyTaggedLogger = ActiveSupport::TaggedLogging.new(MyTaggedLogger)

and
MyTaggedLogger.tagged("BCX") { MyTaggedLogger.info "Hello World!" }   #  OK



Le lundi 19 novembre 2012 16:59:42 UTC+1, Erwin a écrit :
I can use the standard buffer class  :

MyBufferedLogger = ActiveSupport::BufferedLogger.new(Rails.root.join('log/my_buffered.log'))

MyBufferedLogger.info "Hello World!"   # => OK

but I cannot do it using the   buffer class
Reply all
Reply to author
Forward
0 new messages