"Already initialized" warnings thrown by log4r-color #2

Open
surenm opened this Issue May 12, 2012 · 8 comments

Comments

Projects
None yet
3 participants

surenm commented May 12, 2012

Hi kristianmandrup,

Thanks for an excellent library. Really simple and extremely useful.

I use it with rails for logging my backend scripts and when I start console, it throws the following issues. Thought I should report it just in case.

Rails 3.2.0 and Ruby 1.9.2

/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/config.rb:6: warning: already initialized constant LogLevels
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/config.rb:7: warning: already initialized constant LoggerPathDelimiter
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/base.rb:5: warning: already initialized constant ALL
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/base.rb:6: warning: already initialized constant LNAMES
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/GDC.rb:11: warning: already initialized constant GDCNAME
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/MDC.rb:11: warning: already initialized constant MDCNAME
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/MDC.rb:12: warning: already initialized constant MDCNAMEMAXDEPTH
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/NDC.rb:9: warning: already initialized constant NDCNAME
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/NDC.rb:10: warning: already initialized constant NDCNAMEMAXDEPTH
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/NDC.rb:11: warning: already initialized constant NDCDEFAULTMAXDEPTH
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/formatter/patternformatter.rb:30: warning: already initialized constant DirectiveTable
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/formatter/patternformatter.rb:57: warning: already initialized constant DirectiveRegexp
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color/formatter/patternformatter.rb:60: warning: already initialized constant ISO8601
/Users/suren/.rvm/gems/ruby-1.9.2-p290/gems/log4r-color-1.2/lib/log4r-color.rb:19: warning: already initialized constant Log4rVersion

surenm commented May 12, 2012

These are just warning anyways and the library works as such.

noahsw commented Aug 28, 2013

Same issue here. Cool library but it's an annoyance.

Owner

kristianmandrup commented Aug 28, 2013

Try the new branch refactor. I'm trying to remove all those "nasty constants" and turn them into class methods.
See how it works and go from there... Cheers!

noahsw commented Aug 28, 2013

Thanks for the suggestion! Here's what I got when referencing that branch in my gemfile. I didn't make any changes to my code.

uninitialized constant Log4r::Logger::LoggerFactory::OFF
/Users/noah/.bundler/ruby/1.9.1/log4r-color-808e0368666b/lib/log4r-color/loggerfactory.rb:18:in `define_methods'
/Users/noah/.bundler/ruby/1.9.1/log4r-color-808e0368666b/lib/log4r-color/logger.rb:37:in `initialize'
/Users/noah/Projects/service/config/environments/development.rb:46:in `new'
/Users/noah/Projects/service/config/environments/development.rb:46:in `block in <top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:24:in `class_eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:24:in `configure'
/Users/noah/Projects/service/config/environments/development.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/engine.rb:571:in `block in <class:Engine>'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/noah/Projects/service/config/environment.rb:8:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/application.rb:103:in `require_environment!'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/usr/local/rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => task:name => environment
(See full trace by running task with --trace)

Here's where I setup Log4r in development.rb:

require 'log4r-color'
require 'log4r/formatter/log4jxmlformatter'
require 'log4r/outputter/udpoutputter'
require 'log4r/staticlogger'
require 'log4r/outputter/consoleoutputters'
include Log4r

Later on in development.rb

# Log4r
  config.logger = Log4r::Logger.new("Application Log")
  config.logger.level = Log4r::INFO
  config.logger.trace = true

  udpout = Log4r::UDPOutputter.new 'udpOutputter', {:name => "localhost", :port => 877}
  udpout.formatter = Log4r::Log4jXmlFormatter.new

  pattern_formatter = Log4r::PatternFormatter.new(:pattern => "[%l] %d :: %M => %t")

  file = Log4r::FileOutputter.new('fileOutputter', { :filename => './log/development.log', :trunc => false } )
  file.formatter = pattern_formatter

  stdout = Log4r::StdoutOutputter.new 'consoleStdOutputter'
  stdout.formatter = pattern_formatter

  color = ColorOutputter.new 'color', {
      :colors =>
          {
              :debug  => :gray,
              :info   => { color: :light_blue, background: :green},
              :warn   => :yellow,
              :error  => :red,
              :fatal  => {:color => :red, :background => :white}
          }
  }

  config.logger.outputters = [udpout, file, color]
Owner

kristianmandrup commented Aug 28, 2013

Hey, I only just started refactoring. I haven't even tested my changes yet. You are most welcome to help in the effort.
The key is to remove all those nasty constants and turn them into class methods.

Log4r::INFO, Log4r::OFF and similar will be no more... (IMO)

I haven't touched loggerfactory.rb, so please look into it and debug accordingly. You should be able to see a diff of my changes on my latest commit, see where I'm heading and go from there. Good luck ;)
The key is to not touch the current functionality, only refactor the infrastructure.

noahsw commented Aug 29, 2013

Oh okay, didn't realize you just started ;-)

I'm only a few months into Ruby so I may not be a huge help, but I'll take
a look.

On Wed, Aug 28, 2013 at 9:30 AM, Kristian Mandrup
notifications@github.comwrote:

Hey, I only just started refactoring. I haven't even tested my changes
yet. You are most welcome to help in the effort.
The key is to remove all those nasty constants and turn them into class
methods.

Log4r::INFO, Log4r::OFF and similar will be no more... (IMO)

I haven't touched loggerfactory.rb, so please look into it and debug
accordingly. You should be able to see a diff of my changes on my latest
commit, see where I'm heading and go from there. Good luck ;)
The key is to not touch the current functionality, only refactor the
infrastructure.


Reply to this email directly or view it on GitHubhttps://github.com/kristianmandrup/log4r-color/issues/2#issuecomment-23428549
.

Owner

kristianmandrup commented Aug 29, 2013

Haha :) I think this was the first gem I worked on, also as a newbie Rubyist. Since then I have created hundreds of gems... good practice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment