Class: FileLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/file_logger.rb

Overview

The default logger writes to a file descriptor. This could be an actual file, or a stream such as STDOUT.

Instance Method Summary collapse

Constructor Details

#initialize(file = nil, *args) ⇒ FileLogger

Returns a new instance of FileLogger.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/file_logger.rb', line 4

def initialize(file = nil, *args)
  case
  when file.nil?
    @fd = STDOUT
    @needs_close = false
  when file.is_a?(String)
    @fd = File.new(file, "a")
    @needs_close = true
  else
    @fd = file
    @needs_close = false
  end
end

Instance Method Details

#closeObject



22
23
24
# File 'lib/file_logger.rb', line 22

def close
  @fd.close if @needs_close
end

#puts(msg) ⇒ Object Also known as: debug, info, notice, warning, err, error, alert, emerg, crit



18
19
20
# File 'lib/file_logger.rb', line 18

def puts(msg)
  @fd.puts msg
end