class Log4r::DateFileOutputter
Additional hash arguments are:
:dirname
-
Directory of the log file
:date_pattern
-
Time.strftime format string (default is ā%Y-%m-%dā)
Constants
- DEFAULT_DATE_FMT
Public Class Methods
new(_name, hash={})
click to toggle source
Calls superclass method
# File lib/log4r/outputter/datefileoutputter.rb, line 47 def initialize(_name, hash={}) @DatePattern = (hash[:date_pattern] or hash['date_pattern'] or DEFAULT_DATE_FMT) @DateStamp = Time.now.strftime( @DatePattern); _dirname = (hash[:dirname] or hash['dirname']) # hash[:dirname] masks hash[:filename] if _dirname if not FileTest.directory?( _dirname) raise StandardError, "'#{_dirname}' must be a valid directory", caller end end _filename = (hash[:filename] or hash['filename']) if _filename.nil? @filebase = File.basename( $0, '.rb') + ".log" else @filebase = File.basename((hash[:filename] or hash['filename'] or "")) end # Get rid of the 'nil' in the path path = [_dirname, @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')].compact hash[:filename] = hash['filename'] = File.join(path) super(_name, hash) end
Private Instance Methods
change()
click to toggle source
change the file
# File lib/log4r/outputter/datefileoutputter.rb, line 101 def change begin @out.close rescue Logger.log_internal { "DateFileOutputter '#{@name}' could not close #{@filename}" } end makeNewFilename @out = File.new(@filename, (@trunc ? "w" : "a")) Logger.log_internal { "DateFileOutputter '#{@name}' now writing to #{@filename}" } end
makeNewFilename()
click to toggle source
construct a new filename from the DateStamp
# File lib/log4r/outputter/datefileoutputter.rb, line 84 def makeNewFilename @DateStamp = Time.now.strftime( @DatePattern); @filename = File.join(File.dirname(@filename), @filebase.sub(/(\.\w*)$/, "_#{@DateStamp}" + '\1')) end
requiresChange()
click to toggle source
does the file require a change?
# File lib/log4r/outputter/datefileoutputter.rb, line 91 def requiresChange _DateStamp = Time.now.strftime( @DatePattern); if not _DateStamp == @DateStamp @DateStamp = _DateStamp return true end false end
write(data)
click to toggle source
perform the write
Calls superclass method
# File lib/log4r/outputter/datefileoutputter.rb, line 78 def write(data) change if requiresChange super end