W3cubDocs

/Padrino

Class: Padrino::Logger

Inherits:
Object
Includes:
Extensions

Overview

Padrinos internal logger, using all of Padrino log extensions.

Defined Under Namespace

Modules: Colorize, Extensions Classes: Rack

Constant Summary collapse

Levels =

Ruby (standard) logger levels:

:fatal

An not handleable error that results in a program crash

:error

A handleable error condition

:warn

A warning

:info

generic (useful) information about system operation

:debug

low-level information for developers

:devel

Development-related information that is unnecessary in debug mode

{
  :fatal =>  4,
  :error =>  3,
  :warn  =>  2,
  :info  =>  1,
  :debug =>  0,
  :devel => -1,
}
Config =

Configuration for a given environment, possible options are:

:log_level

Once of [:fatal, :error, :warn, :info, :debug]

:stream

Once of [:to_file, :null, :stdout, :stderr] our your custom stream

:log_path

Defines log file path or directory if :stream is :to_file

If it's a file, its location is created by mkdir_p.
If it's a directory, it must exist. In this case log name is '<env>.log'
:log_level

The log level from, e.g. :fatal or :info. Defaults to :warn in the production environment and :debug otherwise.

:auto_flush

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

:format_datetime

Format of datetime. Defaults to: “%d/%b/%Y %H:%M:%S”

:format_message

Format of message. Defaults to: “”%s - - [%s] "%s"“”

:log_static

Whether or not to show log messages for static files. Defaults to: false

:colorize_logging

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

Defaults are:

:production  => { :log_level => :warn, :stream => :to_file }
:development => { :log_level => :debug, :stream => :stdout }
:test        => { :log_level => :fatal, :stream => :null }

In some cases, configuring the loggers before loading the framework is necessary. You can do so by setting PADRINO_LOGGER:

PADRINO_LOGGER = { :staging => { :log_level => :debug, :stream => :to_file }}

Examples:

Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
# or you can edit our defaults
Padrino::Logger::Config[:development][:log_level] = :error
# or change log file path
Padrino::Logger::Config[:development][:log_path] = 'logs/app-development.txt'
# or change log file directory
Padrino::Logger::Config[:development][:log_path] = '/var/logs/padrino'
# or you can use your stream
Padrino::Logger::Config[:development][:stream] = StringIO.new
{
  :production  => { :log_level => :warn,  :stream => :to_file },
  :development => { :log_level => :debug, :stream => :stdout, :format_datetime => '' },
  :test        => { :log_level => :debug, :stream => :null }
}
@@mutex =
Mutex.new

Constants included from Extensions

Extensions::SOURCE_LOCATION_REGEXP

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Methods included from Extensions

#bench, #colorize, #colorize!, #enable_source_location?, #exception, #name, #push, #resolve_source_location, #stylized_level

Constructor Details

#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.

Instance Attribute Details

#auto_flush ⇒ Object

Returns the value of attribute auto_flush

#buffer ⇒ Object (readonly)

Returns the value of attribute buffer

#colorize_logging ⇒ Object (readonly)

Returns the value of attribute colorize_logging

#init_args ⇒ Object (readonly)

Returns the value of attribute init_args

#level ⇒ Object

Returns the value of attribute level

#log ⇒ Object (readonly)

Returns the value of attribute log

#log_static ⇒ Object

Returns the value of attribute log_static

Class Method Details

.logger ⇒ Object

.logger=(logger) ⇒ Object

.setup! ⇒ Padrino::Logger

Setup a new logger.

Returns:

Instance Method Details

#<<(message = nil) ⇒ Object Also known as: write

Directly append message to the log.

Parameters:

  • message (String) (defaults to: nil) — The message

#add(level, message = nil) ⇒ Object

Adds a message to the log - for compatibility with other loggers.

#close ⇒ NilClass

Close and remove the current log object.

Returns:

  • (NilClass)

#flush ⇒ Object

Flush the entire buffer to the log object.

#format(message, level) ⇒ Object

#source_location? ⇒ Boolean

Returns:

  • (Boolean)

© 2010–2019 Padrino
Licensed under the MIT License.
https://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Logger