Method: Logging::Layouts::Pattern#initialize
- Defined in:
- lib/logging/layouts/pattern.rb
#initialize(opts = {}) ⇒ Pattern
call-seq:
Pattern.new( opts )
Creates a new Pattern layout using the following options.
:pattern => "[%d] %-5l -- %c : %m\n"
:date_pattern => "%Y-%m-%d %H:%M:%S"
:date_method => "usec" or "to_s"
:utc_offset => "-06:00" or -21600 or "UTC"
:color_scheme => :default
If used, :date_method will supersede :date_pattern.
The :color_scheme is used to apply color formatting to the log messages. Individual tokens can be colorized witch the level token [%l] receiving distinct colors based on the level of the log event. The entire generated log message can also be colorized based on the level of the log event. See the ColorScheme documentation for more details.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/logging/layouts/pattern.rb', line 219 def initialize( opts = {} ) super @created_at = Time.now.freeze @date_pattern = opts.fetch(:date_pattern, nil) @date_method = opts.fetch(:date_method, nil) @date_pattern = ISO8601 if @date_pattern.nil? && @date_method.nil? @pattern = opts.fetch(:pattern, "[%d] %-#{::Logging::MAX_LEVEL_LENGTH}l -- %c : %m\n") cs_name = opts.fetch(:color_scheme, nil) @color_scheme = case cs_name when false, nil; nil when true; ::Logging::ColorScheme[:default] else ::Logging::ColorScheme[cs_name] end self.class.create_date_format_methods(self) self.class.create_format_method(self) end |