Class: FileLogger
- Inherits:
-
LoggerBase
- Object
- LoggerBase
- FileLogger
- Defined in:
- lib/debugtrace/loggers.rb
Overview
A logger class that outputs the file.
Instance Method Summary collapse
-
#initialize(config, log_path) ⇒ FileLogger
constructor
A new instance of FileLogger.
- #print(message) ⇒ Object
-
#to_s ⇒ Object
Returns a string representation of this object.
Constructor Details
#initialize(config, log_path) ⇒ FileLogger
Returns a new instance of FileLogger.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/debugtrace/loggers.rb', line 104 def initialize(config, log_path) @config = Common::check_type("config", config, Config) Common::check_type("log_path", log_path, String) dir_path = File.dirname(log_path) if Dir.exist?(dir_path) @log_path = log_path else $stderr.puts "DebugTrace-rb: FileLogger: The directory '#{dir_path}' cannot be found." @log_path = '' end end |
Instance Method Details
#print(message) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/debugtrace/loggers.rb', line 116 def print() Common::check_type("message", , String) if @log_path != '' File.open(@log_path, 'a') {|file| datetime_str = Time.now().strftime(@config.logging_datetime_format) file.puts "#{datetime_str} #{}" } end end |
#to_s ⇒ Object
Returns a string representation of this object.
128 129 130 |
# File 'lib/debugtrace/loggers.rb', line 128 def to_s "File logger: '#{@log_path}" end |