Project

General

Profile

Actions

Bug #13727

closed

Not able to set program_name for new Syslog::Logger

Added by printercu (Max Melentiev) almost 7 years ago. Updated almost 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:81949]

Description

Hi!

Every instance of syslog logger uses same program_name as first initialized one, because they all share single instance of Syslog (https://github.com/ruby/ruby/blob/trunk/ext/syslog/lib/syslog/logger.rb#L195)

logger1 = Syslog::Logger.new('tag-1', Syslog::LOG_LOCAL1)
logger2 = Syslog::Logger.new('tag-2', Syslog::LOG_LOCAL1)
logger.info { 'test' } # logged with tag-1

Updated by normalperson (Eric Wong) almost 7 years ago

wrote:

Hi!

Every instance of syslog logger uses same program_name as first initialized one, because they all share single instance of Syslog (https://github.com/ruby/ruby/blob/trunk/ext/syslog/lib/syslog/logger.rb#L195)

Yes, this is documented at the top of that file:

| NOTE! You can only set the Syslog::Logger program name when you initialize
| Syslog::Logger for the first time. This is a limitation of the way
| Syslog::Logger uses syslog (and in some ways, a limitation of the way
| syslog(3) works). Attempts to change Syslog::Logger's program name after the
| first initialization will be ignored.

If Ruby Syslog were to support different program names, it would
have to repeatedly make calls openlog(3)/closelog(3) C library
functions. That would still leave reentrancy + thread-safety
problems, and probably small performance ones, too.

I suggest using a short program name and perhaps using a
context-specific prefix (perhaps stored in Thread.current[])
for each call, instead.

Updated by printercu (Max Melentiev) almost 7 years ago

Thank you!

Sorry, I haven't noticed this documentation.

Actions #3

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0