Project

General

Profile

Actions

Bug #12238

closed

Logger writes progname if log message is nil

Bug #12238: Logger writes progname if log message is nil

Added by Soilent (Konstantin x) almost 10 years ago. Updated almost 10 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
[ruby-core:74755]

Description

Please consider the following example:

logger = Logger.new($stdout)

# Log message is nil
logger.info
# I, [2016-03-31T22:04:36.684636 #4019]  INFO -- : nil

logger.progname = 'prog'

# Now log message is changed to progname, is this a bug?
logger.info
# I, [2016-03-31T22:04:51.418510 #4019]  INFO -- prog: prog

logger.info 'test'
# I, [2016-03-31T22:05:03.345434 #4019]  INFO -- prog: test

Logger writes progname if log message is nil. Is this a bug or a known feature?

Updated by nobu (Nobuyoshi Nakada) almost 10 years ago Actions #1 [ruby-core:74760]

  • Assignee set to sonots (Naotoshi Seo)

Seems intended,

Logger#add(severity, message = nil, progname = nil) { ... }

Args

progname::
Program name string. Can be omitted. Treated as a message if no
message and block are given.

but maybe a bug.

diff --git a/lib/logger.rb b/lib/logger.rb
index 8393806..9a05518 100644
--- a/lib/logger.rb
+++ b/lib/logger.rb
@@ -421,14 +421,16 @@
     if @logdev.nil? or severity < @level
       return true
     end
-    progname ||= @progname
     if message.nil?
       if block_given?
         message = yield
+        progname ||= @progname
       else
         message = progname
         progname = @progname
       end
+    else
+      progname ||= @progname
     end
     @logdev.write(
       format_message(format_severity(severity), Time.now, progname, message))

Updated by Soilent (Konstantin x) almost 10 years ago Actions #2 [ruby-core:74890]

Thanks

I see that it is supposed to be like this. Seems a bit weird though.

Updated by sonots (Naotoshi Seo) almost 10 years ago Actions #3 [ruby-core:75004]

Seems intended, so let me close.
(It is okay to change the behavior, but it looks also okay not to change the behavior)

Updated by sonots (Naotoshi Seo) almost 10 years ago Actions #4 [ruby-core:75005]

  • Status changed from Open to Rejected
Actions

Also available in: PDF Atom