Class: FileLogger
- Inherits:
-
LoggerBase
- Object
- LoggerBase
- FileLogger
- Defined in:
- lib/debugtrace/loggers.rb
Overview
A logger class that outputs the file.
Constant Summary collapse
- @@log_path_default =
'debugtrace.log'
Instance Method Summary collapse
-
#initialize(config) ⇒ FileLogger
constructor
Initializes this object.
-
#print(message) ⇒ String
Outputs the message.
-
#to_s ⇒ String
Returns a string representation of this object.
Constructor Details
#initialize(config) ⇒ FileLogger
Initializes this object.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/debugtrace/loggers.rb', line 116 def initialize(config) @log_path = @@log_path_default @config = Common::check_type("config", config, Config) Common::check_type("log_path", config.log_path, String) @log_path = config.log_path @append = false if @log_path.start_with?('+') @log_path = @log_path[1..-1] @append = true end dir_path = File.dirname(@log_path) if !Dir.exist?(dir_path) @log_path = @@log_path_default @append = true print("DebugTrace-rb: FileLogger: The directory '#{dir_path}' cannot be found.\n") end if !@append File.open(@log_path, 'w') { |file| } end end |
Instance Method Details
#print(message) ⇒ String
Outputs the message.
146 147 148 149 150 151 152 153 154 |
# File 'lib/debugtrace/loggers.rb', line 146 def print() if File.exist?(@log_path) File.open(@log_path, 'a') { |file| datetime_str = Time.now().strftime(@config.log_datetime_format) file.puts "#{datetime_str} #{}" } end return end |
#to_s ⇒ String
Returns a string representation of this object.
159 160 161 |
# File 'lib/debugtrace/loggers.rb', line 159 def to_s return "#{self.class.name} path: #{@log_path}, append: #{@append}" end |