Class: Bovem::Logger
- Inherits:
-
Logger
- Object
- Logger
- Bovem::Logger
- Defined in:
- lib/bovem/logger.rb
Overview
A custom logger.
Instance Attribute Summary (collapse)
-
- (Object) device
readonly
The file or device to log messages to.
Class Method Summary (collapse)
-
+ (Logger) create(file = nil, level = Logger::INFO, formatter = nil)
Creates a new logger.
-
+ (String|IO) default_file
The default file for logging.
-
+ (Proc) default_formatter
The default formatter for logging.
-
+ (String|IO) get_real_file(file)
Translates a file to standard input or standard ouput in some special cases.
-
+ (Time) start_time
The log time of the first logger.
Instance Method Summary (collapse)
-
- (Logger) initialize(logdev, shift_age = 0, shift_size = 1048576)
constructor
Creates a new logger.
Constructor Details
- (Logger) initialize(logdev, shift_age = 0, shift_size = 1048576)
Creates a new logger.
23 24 25 26 |
# File 'lib/bovem/logger.rb', line 23 def initialize(logdev, shift_age = 0, shift_size = 1048576) @device = logdev super(logdev, shift_age, shift_size) end |
Instance Attribute Details
- (Object) device (readonly)
The file or device to log messages to.
14 15 16 |
# File 'lib/bovem/logger.rb', line 14 def device @device end |
Class Method Details
+ (Logger) create(file = nil, level = Logger::INFO, formatter = nil)
Creates a new logger.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bovem/logger.rb', line 34 def self.create(file = nil, level = Logger::INFO, formatter = nil) file ||= self.default_file begin rv = self.new(self.get_real_file(file)) rescue raise Bovem::Errors::InvalidLogger end rv.level = level.to_i rv.formatter = formatter || self.default_formatter rv end |
+ (String|IO) default_file
The default file for logging.
62 63 64 |
# File 'lib/bovem/logger.rb', line 62 def self.default_file @default_file ||= $stdout end |
+ (Proc) default_formatter
The default formatter for logging.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bovem/logger.rb', line 68 def self.default_formatter @default_formatter ||= ::Proc.new {|severity, datetime, progname, msg| color = case severity when "DEBUG" then :cyan when "INFO" then :green when "WARN" then :yellow when "ERROR" then :red when "FATAL" then :magenta else :white end header = ::Bovem::Console.replace_markers("{mark=bright-#{color}}[%s T+%0.5f] %s:{/mark}" %[datetime.strftime("%Y/%b/%d %H:%M:%S"), [datetime.to_f - self.start_time.to_f, 0].max, severity.rjust(5)]) "%s %s\n" % [header, msg] } end |
+ (String|IO) get_real_file(file)
Translates a file to standard input or standard ouput in some special cases.
52 53 54 55 56 57 58 |
# File 'lib/bovem/logger.rb', line 52 def self.get_real_file(file) case file when "STDOUT" then $stdout when "STDERR" then $stderr else file end end |
+ (Time) start_time
The log time of the first logger. This allows to show a T+0.1234
information into the log.
86 87 88 |
# File 'lib/bovem/logger.rb', line 86 def self.start_time @start_time ||= ::Time.now end |