Class: Log4Ruby::FileAppender

Inherits:
StreamAppender show all
Defined in:
lib/log4ruby/appenders/file_appender.rb

Overview

Customizable file appender to log to a file.

Constant Summary collapse

DATE_ROLLERS =
{:hourly => DateRollers::HOURLY, :daily => DateRollers::DAILY,
:weekly => DateRollers::WEEKLY, :monthly => DateRollers::MONTHLY,
:yearly => DateRollers::YEARLY}

Instance Attribute Summary

Attributes inherited from Appender

#formatter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StreamAppender

#close, #footer, #header

Methods inherited from Appender

#close, #closed?, #process_log

Constructor Details

#initialize(level, options = {}) ⇒ FileAppender

New stream appender.

Configuration parameters specific to rollers. dont_roll:

:truncate - if true (the default), contents of the file are deleted before logging begins.

roll_using_size:

:max_size - the maximum allowed size for a log file (in bytes - default is 102400 bytes).

roll_using_date:

:frequency - the frequency with which to roll files (:hourly, :daily, :weekly, :monthly, :yearly).
Default is :daily.

Parameters:

  • options (Hash) (defaults to: {})

    configuration hash. Supports the following parameters. :formatter - the formatter this appender should use. Uses the DefaultFormatter if not specified. :directory - the directory into which the logs should be saved. Defaults to the current directory. :prefix - the file name prefix for the log files. required :suffix - the file name suffix for the log files. Defaults to ‘log’ :max_files - the maximum number of files to keep. Defaults to 5. :roll_type - the type of rolling required. Supports the following

    :dont_roll - the default type. Only one file is created.
    :roll_using_size - rolls files using the file's size.
    :roll_using_date - rolls files using the file's create date.
    

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/log4ruby/appenders/file_appender.rb', line 56

def initialize(level, options = {})
  set_option(options, :stream, nil, true)
  super(level, options)

  @directory = get_option(options, :directory, false, "./")
  @prefix = get_option(options, :prefix, true)
  @suffix = get_option(options, :suffix, false, "log")
  @max_files = get_option(options, :max_files, false, 5)
  @type = get_option(options, :roll_type, false, :dont_roll)

  type_method = "initialize_#@type"
  raise ArgumentError.new("Unrecognized type '#@type'!") unless respond_to?(type_method, true)
  send(type_method, options)
end

Class Method Details

.emit(string, log) ⇒ Object

Create the emit method that will roll using the file size as the trigger.



110
111
112
113
# File 'lib/log4ruby/appenders/file_appender.rb', line 110

def self.emit(string, log)
  roll_using_date
  super
end