Class: Appear::Output
- Inherits:
-
Object
- Object
- Appear::Output
- Defined in:
- lib/appear/output.rb
Overview
The Output service encapsulates writing logging information to log files and STDERR, and writing output to STDOUT.
Instance Method Summary collapse
-
#initialize(log_file_name, silent) ⇒ Output
constructor
Create a new Output service.
-
#log(*any) ⇒ Object
Log a message.
-
#log_error(err) ⇒ Object
Log an error.
-
#output(*any) ⇒ Object
Output a message to STDOUT, and also to the log file.
Constructor Details
#initialize(log_file_name, silent) ⇒ Output
Create a new Output service.
12 13 14 15 16 17 18 |
# File 'lib/appear/output.rb', line 12 def initialize(log_file_name, silent) @file_logger = nil @stderr_logger = nil @file_logger = Logger.new(log_file_name.to_s) if log_file_name @stderr_logger = Logger.new(STDERR) unless silent end |
Instance Method Details
#log(*any) ⇒ Object
Log a message.
23 24 25 26 |
# File 'lib/appear/output.rb', line 23 def log(*any) @stderr_logger.debug(*any) if @stderr_logger @file_logger.debug(*any) if @file_logger end |
#log_error(err) ⇒ Object
Log an error
31 32 33 34 35 36 |
# File 'lib/appear/output.rb', line 31 def log_error(err) log("Error #{err.inspect}: #{err.to_s.inspect}") if err.backtrace err.backtrace.each { |line| log(" " + line) } end end |
#output(*any) ⇒ Object
Output a message to STDOUT, and also to the log file.
41 42 43 44 |
# File 'lib/appear/output.rb', line 41 def output(*any) STDOUT.puts(*any) @file_logger.debug(*any) if @file_logger end |