Skip to content

Commit

Permalink
Allow setting log file from outside the module
Browse files Browse the repository at this point in the history
In case the bundle current working directory is not writable by
current non-root user, the logging will fail. This change keeps
the same default but allows overriding the logfile name and path
from outside the module.
Also helps in case user doesn't want logging by setting the logfile
to /dev/null
  • Loading branch information
Islam Amer committed Mar 17, 2013
1 parent 922207f commit 554fda0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/ruote/util/dlog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ module Ruote
#
module D

def self.set_logfile(fn)
f = File.open(fn, 'wb')
f.sync = true
f
@@logfile = f
end

def self.log(text, h, *args)

@@log ||=
begin
f = File.open("dlog_#{$$}.txt", 'wb')
f.sync = true
f
end
@@logfile ||= self.set_logfile("dlog_#{$$}.txt")

t = Time.now
t = "#{t.strftime('%H:%M:%S')}.#{sprintf('%06d', t.usec)}"
Expand Down Expand Up @@ -66,8 +68,8 @@ def self.log(text, h, *args)
m.concat(args)
m << "\n"

@@log.print(m.collect(&:to_s).join(' '))
@@log.flush # hard
@@logfile.print(m.collect(&:to_s).join(' '))
@@logfile.flush # hard
end
end
end
Expand Down

0 comments on commit 554fda0

Please sign in to comment.