Class: Log4r::DateFileOutputter

Inherits:
FileOutputter show all
Defined in:
lib/log4r-color/outputter/datefileoutputter.rb

Overview

Additional hash arguments are:

:dirname

Directory of the log file

:date_pattern

Time.strftime format string (default is ā€œ%Y-%m-%dā€)

Constant Summary collapse

DEFAULT_DATE_FMT =
"%Y-%m-%d"

Instance Attribute Summary

Attributes inherited from FileOutputter

#filename, #trunc

Attributes inherited from Outputter

#colors, #formatter, #level, #name

Instance Method Summary collapse

Methods inherited from IOOutputter

#close, #closed?

Methods inherited from Outputter

[], []=, color, each, each_outputter, #flush, #level_key, #only_at, stderr, stdout

Constructor Details

#initialize(_name, hash = {}) ⇒ DateFileOutputter

Returns a new instance of DateFileOutputter.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/log4r-color/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