Class: DedicatedLogger::Base
- Inherits:
-
Logger
- Object
- Logger
- DedicatedLogger::Base
- Defined in:
- lib/dedicated_logger/base.rb
Instance Method Summary collapse
- #format_message(severity, timestamp, progname, msg) ⇒ Object
-
#initialize(logger_name, filepath, options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(logger_name, filepath, options = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 |
# File 'lib/dedicated_logger/base.rb', line 7 def initialize logger_name, filepath, ={} @logger_name = logger_name filename = File.basename filepath dir_path = File.dirname(File.absolute_path(filepath)) FileUtils.mkdir_p(dir_path) unless File.exists? dir_path super File.join(dir_path, filename) end |
Instance Method Details
#format_message(severity, timestamp, progname, msg) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dedicated_logger/base.rb', line 17 def severity, , progname, msg msg = "#{.strftime("%Y-%m-%d %H:%M:%S")} #{@logger_name} [#{$$}] #{severity}: #{msg}\n" if %w(WARN ERROR FATAL).include?(severity.to_s) STDERR.puts(msg) else STDOUT.puts(msg) end msg end |