Log4r's Redefine Warnings

B

Brian Takita

Hello,

Whenever I log a class using Log4r with full warnings on, I get a bunch
of warnings. Does anybody know how to resolve this? Is there a patch
out?

I Changed the LoggerFactory class, in /lib/LoggerFactory.rb, to
undefine these methods, but that did not seem to work.

Thank you,
Brian Takita

(eval):2: warning: redefine debug
(eval):1: warning: redefine debug?
(eval):2: warning: redefine info
(eval):1: warning: redefine info?
(eval):2: warning: redefine warn
(eval):1: warning: redefine warn?
(eval):2: warning: redefine error
(eval):1: warning: redefine error?
(eval):2: warning: redefine fatal
(eval):1: warning: redefine fatal?
(eval):1: warning: redefine all?
(eval):1: warning: redefine off?
(eval):1: warning: redefine debug
(eval):1: warning: redefine debug?
(eval):1: warning: redefine info
(eval):1: warning: redefine info?
(eval):1: warning: redefine warn
(eval):1: warning: redefine warn?
(eval):1: warning: redefine error
(eval):1: warning: redefine error?
(eval):1: warning: redefine fatal
(eval):1: warning: redefine fatal?
(eval):1: warning: redefine all?
(eval):1: warning: redefine off?
(eval):2: warning: redefine debug
(eval):1: warning: redefine debug?
(eval):2: warning: redefine info
(eval):1: warning: redefine info?
(eval):2: warning: redefine warn
(eval):1: warning: redefine warn?
(eval):2: warning: redefine error
(eval):1: warning: redefine error?
(eval):2: warning: redefine fatal
(eval):1: warning: redefine fatal?
(eval):1: warning: redefine all?
(eval):1: warning: redefine off?
(eval):2: warning: redefine debug
(eval):2: warning: redefine info
(eval):2: warning: redefine warn
(eval):2: warning: redefine error
(eval):2: warning: redefine fatal
 
B

Brian Takita

Does anybody know of a good way to find out where these warnings are
coming from?

I assume that set_trace_func is the way to go, but I am unable to
figure out what class or method to listen for.

I tried listening for :eval and :module_eval but was not able to catch
anything.

Thank you,
Brian Takita
 
D

daz

Brian said:
Hello,

Whenever I log a class using Log4r with full warnings on, I get a bunch
of warnings. Does anybody know how to resolve this? Is there a patch
out?


There's probably a correct way of doing this but it would mean
understanding more about the structure.


diff -u3pPr log4r_ORIG\loggerfactory.rb log4r\loggerfactory.rb
--- log4r_ORIG\loggerfactory.rb Sat Apr 09 09:23:52 2005
+++ log4r\loggerfactory.rb Mon Jul 11 07:21:20 2005
@@ -51,7 +51,9 @@ class Logger

def self.unset_log(logger, lname)
mstr="def logger.#{lname.downcase}(data=nil, propagated=false); end"
+ $VERBOSE, verbose = false, $VERBOSE
module_eval mstr
+ $VERBOSE = verbose
end

# Logger logging methods are defined here.
@@ -73,15 +75,21 @@ class Logger
#{parentcall}
end
-
+ $VERBOSE, verbose = false, $VERBOSE
module_eval mstr
+ $VERBOSE = verbose
end

def self.set_false(logger, lname)
+ $VERBOSE, verbose = false, $VERBOSE
module_eval "def logger.#{lname.downcase}?; false end"
+ $VERBOSE = verbose
end

def self.set_true(logger, lname)
+ $VERBOSE, verbose = false, $VERBOSE
module_eval "def logger.#{lname.downcase}?; true end"
+ $VERBOSE = verbose
end

end
diff -u3pPr log4r_ORIG\outputter\outputterfactory.rb log4r\outputter\outputterfactory.rb
--- log4r_ORIG\outputter\outputterfactory.rb Sat Apr 09 09:23:52 2005
+++ log4r\outputter\outputterfactory.rb Mon Jul 11 07:20:16 2005
@@ -45,13 +45,17 @@ class Outputter
canonical_log(logevent)
end
-
+ $VERBOSE, verbose = false, $VERBOSE
module_eval mstr
+ $VERBOSE = verbose
end

def self.undefine_log(mname, out)
return if mname == 'off' || mname == 'all'
mstr = "def out.#{mname}(logevent); end"
+ $VERBOSE, verbose = false, $VERBOSE
module_eval mstr
+ $VERBOSE = verbose
end
end





A short script to test would have been helpful !

#---------------------------------------------------
require 'log4r'
include Log4r

$VERBOSE=true
mylog = Logger.new 'mylog'
mylog.outputters = Outputter.stdout
mylog.debug "This is a message with level DEBUG"
p [:VERBOSE, $VERBOSE] #-> still true after flips
#---------------------------------------------------

daz
 
B

Brian Takita

A short script to test would have been helpful !

I'm sorry. I should have posted a test script. Thank you for providing
one.

Unfortunately, I'm still getting the warnings.
This seems to indicate that the warnings are generated somewhere else.

I grepped the log4r code and could not find any other eval statements
that relates to this message.
Maybe this has to do with an already existing class in ruby, such as
the standard Logger framework?

Could these warnings be caused by a class definition somewhere in the
Log4r framework?
 
D

daz

Brian said:
[...] Unfortunately, I'm still getting the warnings.


Before, I was seeing the same set of warnings as you
posted originally. After, all those warnings were gone.

You shouldn't be getting messages from the test script I posted
if the patches were applied correctly to the same log4r that
you're 'require'-ing.

Note that there were two patches:
\loggerfactory.rb
and
\outputter\outputterfactory.rb

If you're getting messages from your app, I'd need to see
a short script that produces them and/or a list of the methods
that are being warned as being redefined.


daz
 
B

Brian Takita

I found the problem. I had Log4r in gems and in my base install. I was
editing the gems Log4r, but nothing happened b/c it wasn't being used.

Thank you for your help.
 
B

Brian Takita

Instead of using the following to get rid of the warning:
$VERBOSE, verbose = false, $VERBOSE
and
$VERBOSE = verbose

one can use
class << obj; self end.send:)remove_method, method_name.to_sym)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top