Class: Hoodoo::Logger::FileWriter

Inherits:
SlowWriter show all
Includes:
FlattenerMixin
Defined in:
lib/hoodoo/logger/writers/file_writer.rb

Overview

Writes unstructured messages to a file. Hoodoo::Logger::SlowWriter subclass. See also Hoodoo::Logger.

Instance Method Summary collapse

Methods included from FlattenerMixin

#flatten

Constructor Details

#initialize(pathname) ⇒ FileWriter

Create a file writer instance. Files are written by opening, adding a log message and closing again, to provide reliability. For this reason, this is a Hoodoo::Logger::SlowWriter subclass.

If you want faster file access at the expense of immediate updates / reliability due to buffering, open a file externally to create an I/O stream and pass this persistently-open file’s stream to an Hoodoo::Logger::StreamWriter class instead.

pathname

Full pathname of a file that can be opened in “ab” (append for writing at end-of-file) mode.



32
33
34
# File 'lib/hoodoo/logger/writers/file_writer.rb', line 32

def initialize( pathname )
  @pathname = pathname
end

Instance Method Details

#report(log_level, component, code, data) ⇒ Object

See Hoodoo::Logger::WriterMixin#report.



38
39
40
41
42
# File 'lib/hoodoo/logger/writers/file_writer.rb', line 38

def report( log_level, component, code, data )
  File.open( @pathname, 'ab' ) do | file |
    file.puts( flatten( log_level, component, code, data ) )
  end
end