Skip to content

Commit

Permalink
Merge pull request #15 from carsonreinke/master
Browse files Browse the repository at this point in the history
SyslogOutputter Don't Keep Open Syslog
  • Loading branch information
colbygk committed Oct 2, 2013
2 parents 5fc9416 + 5fbeade commit 9814c73
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/log4r/outputter/syslogoutputter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,17 @@ class SyslogOutputter < Outputter
# [<tt>:facility</tt>] syslog facility, defaults to LOG_USER
def initialize(_name, hash={})
super(_name, hash)
ident = (hash[:ident] or hash['ident'] or _name)
logopt = (hash[:logopt] or hash['logopt'] or LOG_PID | LOG_CONS).to_i
facility = (hash[:facility] or hash['facility'] or LOG_USER).to_i
@ident = (hash[:ident] or hash['ident'] or _name)
@logopt = (hash[:logopt] or hash['logopt'] or LOG_PID | LOG_CONS).to_i
@facility = (hash[:facility] or hash['facility'] or LOG_USER).to_i
map_levels_by_name_to_syslog()
if ( Syslog.opened? ) then
Logger.log_internal { "Syslog already initialized, to alter, " +
"you must close first"}
end
@syslog = ( Syslog.opened? ) ? Syslog : Syslog.open(ident, logopt, facility)
end

def closed?
return !@syslog.opened?
@level == OFF
end

def close
@syslog.close unless @syslog.nil?
@level = OFF
OutputterFactory.create_methods(self)
Logger.log_internal {"Outputter '#{@name}' closed Syslog and set to OFF"}
Expand Down Expand Up @@ -124,7 +118,9 @@ def canonical_log(logevent)
msg = o.inspect
end

@syslog.log(pri, '%s', msg)
Syslog.open(@ident, @logopt, @facility) do |s|
s.log(pri, '%s', msg)
end
end
end
end

0 comments on commit 9814c73

Please sign in to comment.