Class: Log4r::ExtendedRollingFileOutputter
- Inherits:
-
RollingFileOutputter
- Object
- RollingFileOutputter
- Log4r::ExtendedRollingFileOutputter
- Defined in:
- lib/log4r/outputter/extendedrollingfileoutputter.rb
Overview
ExtendedRollingFileOutputter - subclass of RollingFileOutputter that takes date pattern what is used to build the log file name.
Example: Default pattern ‘-%d%m%Y-%H%H%S’ creates log files like myapp-01082004-123150.log.
Additional hash arguments are:
:datepattern-
Pattern used in build log file name
Instance Method Summary collapse
-
#initialize(_name, hash = {}) ⇒ ExtendedRollingFileOutputter
constructor
A new instance of ExtendedRollingFileOutputter.
-
#makeNewFilename(counter = nil) ⇒ Object
construct a new filename from the count and baseFileName.
Constructor Details
#initialize(_name, hash = {}) ⇒ ExtendedRollingFileOutputter
Returns a new instance of ExtendedRollingFileOutputter.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/log4r/outputter/extendedrollingfileoutputter.rb', line 40 def initialize( _name, hash={} ) if ( hash['datepattern'] != nil ) @datePattern = hash['datepattern'] else @datePattern = '-%d%m%Y-%H%H%S' end super( _name, hash ) end |
Instance Method Details
#makeNewFilename(counter = nil) ⇒ Object
construct a new filename from the count and baseFileName
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/log4r/outputter/extendedrollingfileoutputter.rb', line 52 def makeNewFilename( counter=nil ) pad = Time.now.strftime( @datePattern ) pad << '-' + counter.to_s if counter != nil newbase = @baseFilename.sub(/(\.\w*)$/, pad + '\1') @filename = File.join(File.dirname(@filename), newbase) if ( File.exist?( @filename ) ) puts "exists " + @filename counter = 0 unless counter != nil counter = counter + 1 return makeNewFilename( counter ) end Logger.log_internal {"File #{@filename} created"} return @filename end |