Class: Log4r::FileOutputter
- Inherits:
-
IOOutputter
- Object
- Monitor
- Outputter
- IOOutputter
- Log4r::FileOutputter
- Defined in:
- lib/log4r/outputter/fileoutputter.rb
Overview
Convenience wrapper for File. Additional hash arguments are:
:filename
-
Name of the file to log to.
:trunc
-
Truncate the file?
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#trunc ⇒ Object
readonly
Returns the value of attribute trunc.
Attributes inherited from Outputter
Instance Method Summary collapse
-
#initialize(_name, hash = {}) ⇒ FileOutputter
constructor
A new instance of FileOutputter.
Methods inherited from IOOutputter
Methods inherited from Outputter
[], []=, each, each_outputter, #flush, #only_at, stderr, stdout
Constructor Details
#initialize(_name, hash = {}) ⇒ FileOutputter
Returns a new instance of FileOutputter.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/log4r/outputter/fileoutputter.rb', line 16 def initialize(_name, hash={}) super(_name, nil, hash) @trunc = Log4rTools.decode_bool(hash, :trunc, false) _filename = (hash[:filename] or hash['filename']) @create = Log4rTools.decode_bool(hash, :create, true) if _filename.class != String raise TypeError, "Argument 'filename' must be a String", caller end # file validation if FileTest.exist?( _filename ) if not FileTest.file?( _filename ) raise StandardError, "'#{_filename}' is not a regular file", caller elsif not FileTest.writable?( _filename ) raise StandardError, "'#{_filename}' is not writable!", caller end else # ensure directory is writable dir = File.dirname( _filename ) if not FileTest.writable?( dir ) raise StandardError, "'#{dir}' is not writable!" end end @filename = _filename if ( @create == true ) then @out = File.new(@filename, (@trunc ? "w" : "a")) Logger.log_internal { "FileOutputter '#{@name}' writing to #{@filename}" } else Logger.log_internal { "FileOutputter '#{@name}' called with :create == false, #{@filename}" } end end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
14 15 16 |
# File 'lib/log4r/outputter/fileoutputter.rb', line 14 def filename @filename end |
#trunc ⇒ Object (readonly)
Returns the value of attribute trunc.
14 15 16 |
# File 'lib/log4r/outputter/fileoutputter.rb', line 14 def trunc @trunc end |