Class: Bauxite::Loggers::FileLogger

Inherits:
NullLogger show all
Defined in:
lib/bauxite/loggers/file.rb

Overview

File logger.

This logger outputs the raw action text for every action executed to the file specified in the file logger option.

File logger options include:

file

Output file name.

verbose

Output all log (e.g. errors) to the file.

Instance Method Summary collapse

Methods inherited from NullLogger

#debug_prompt, #progress

Constructor Details

#initialize(options) ⇒ FileLogger

Constructs a new echo logger instance.



36
37
38
39
40
41
42
43
44
# File 'lib/bauxite/loggers/file.rb', line 36

def initialize(options)
  super(options)
  @file = options[:file]
  unless @file and @file != ''
    raise ArgumentError, "FileLogger configuration error: Undefined 'file' option."
  end
  @verbose = options[:verbose]
  @lines = []
end

Instance Method Details

#finalize(ctx) ⇒ Object

Completes the log execution.



47
48
49
# File 'lib/bauxite/loggers/file.rb', line 47

def finalize(ctx)
  File.open(ctx.output_path(@file), 'w') { |f| f.write(@lines.join("\n")) }
end

#log(s, type = :info) ⇒ Object

Logs the specified string.

type, if specified, should be one of :error, :warning, :info (default), :debug.



62
63
64
65
66
67
68
# File 'lib/bauxite/loggers/file.rb', line 62

def log(s, type = :info)
  if @verbose
    @lines << s
  else
    super
  end
end

#log_cmd(action) ⇒ Object

Echoes the raw action text.



52
53
54
55
# File 'lib/bauxite/loggers/file.rb', line 52

def log_cmd(action)
  @lines << action.text
  yield
end