Method: Padrino::Logger#initialize

Defined in:
padrino-core/lib/padrino-core/logger.rb

#initialize(options = {}) ⇒ Logger

To initialize the logger you create a new object, proxies to set_log.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :stream (Symbol) — default: $stdout

    Either an IO object or a name of a logfile. Defaults to $stdout

  • :log_level (Symbol) — default: :production in the production environment and :debug otherwise

    The log level from, e.g. :fatal or :info.

  • :auto_flush (Symbol) — default: true

    Whether the log should automatically flush after new messages are added. Defaults to true.

  • :format_datetime (Symbol) — default: " [%d/%b/%Y %H:%M:%S] "

    Format of datetime.

  • :format_message (Symbol) — default: "%s -%s%s"

    Format of message.

  • :log_static (Symbol) — default: false

    Whether or not to show log messages for static files.

  • :colorize_logging (Symbol) — default: true

    Whether or not to colorize log messages. Defaults to: true.

  • :sanitize_encoding (Symbol) — default: false

    Logger will replace undefined or broken characters with “uFFFD” for Unicode and “?” otherwise. Can be an encoding, false or true. If it’s true, logger sanitizes to Encoding.default_external.



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'padrino-core/lib/padrino-core/logger.rb', line 408

def initialize(options={})
  @buffer           = []
  @auto_flush       = options.has_key?(:auto_flush) ? options[:auto_flush] : true
  @level            = options[:log_level] ? Padrino::Logger::Levels[options[:log_level]] : Padrino::Logger::Levels[:debug]
  @log              = options[:stream]  || $stdout
  @log.sync         = true
  @format_datetime  = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
  @format_message   = options[:format_message]  || "%s - %s %s"
  @log_static       = options.has_key?(:log_static) ? options[:log_static] : false
  @colorize_logging = options.has_key?(:colorize_logging) ? options[:colorize_logging] : true
  @source_location  = options[:source_location]
  @sanitize_encoding = options[:sanitize_encoding] || false
  @sanitize_encoding = Encoding.default_external if @sanitize_encoding == true
  colorize! if @colorize_logging
end