Class: Yell::Formatter
- Inherits:
-
Object
- Object
- Yell::Formatter
- Defined in:
- lib/yell/formatter.rb
Overview
The Formatter
provides a handle to configure your log message style.
Defined Under Namespace
Modules: Helpers
Constant Summary collapse
- PatternTable =
{ "m" => "message(*event.messages)", # Message "l" => "level(event.level)[0,1]", # Level (short), e.g.'I', 'W' "L" => "level(event.level)", # Level, e.g. 'INFO', 'WARN' "d" => "date(event.time)", # ISO8601 Timestamp "h" => "event.hostname", # Hostname "p" => "event.pid", # PID "P" => "event.progname", # Progname "t" => "event.thread_id", # Thread ID "F" => "event.file", # Path with filename where the logger was called "f" => "File.basename(event.file)", # Filename where the loger was called "M" => "event.method", # Method name where the logger was called "n" => "event.line" # Line where the logger was called }
- PatternRegexp =
/([^%]*)(%\d*)?(#{PatternTable.keys.join('|')})?(.*)/
Instance Method Summary collapse
-
#initialize(pattern = nil, date_pattern = nil) ⇒ Formatter
constructor
Initializes a new
Yell::Formatter
. -
#inspect ⇒ String
Get a pretty string representation of the formatter, including the pattern and date pattern.
Constructor Details
#initialize(pattern = nil, date_pattern = nil) ⇒ Formatter
Initializes a new Yell::Formatter
.
Upon initialization it defines a format method. ‘format` takes a Event instance as agument in order to apply for desired log message formatting.
86 87 88 89 90 91 |
# File 'lib/yell/formatter.rb', line 86 def initialize( pattern = nil, date_pattern = nil ) @pattern = pattern || Yell::DefaultFormat @date_pattern = date_pattern || :iso8601 define! end |
Instance Method Details
#inspect ⇒ String
Get a pretty string representation of the formatter, including the pattern and date pattern.
100 101 102 |
# File 'lib/yell/formatter.rb', line 100 def inspect "#<#{self.class.name} pattern: #{@pattern.inspect}, date_pattern: #{@date_pattern.inspect}>" end |