Files

Padrino::Logger::Extensions

Public Instance Methods

bench(action, began_at, message, level=:debug, color=:yellow) click to toggle source

Append a to development logger a given action with time

@param [string] action

The action

@param [float] time

Time duration for the given action

@param [message] string

The message that you want to log

@example

logger.bench 'GET', started_at, '/blog/categories'
# => DEBUG - GET (0.0056s) - /blog/categories
# File lib/padrino-core/logger.rb, line 98
def bench(action, began_at, message, level=:debug, color=:yellow)
  @_pad  ||= 8
  @_pad    = action.to_s.size if action.to_s.size > @_pad
  duration = Time.now - began_at
  color    = :red if duration > 1
  action   = colorize(action.to_s.upcase.rjust(@_pad), color)
  duration = colorize('%0.4fs' % duration, :bold, color)
  push "#{action} (#{duration}) #{message}", level
end
colorize(string, *colors) click to toggle source

Colorizes a string for colored console output. This is a noop and can be reimplemented to colorize the string as needed.

@see

ColorizedLogger

@param [string]

The string to be colorized.

@param [Array<Symbol>]

The colors to use. Should be applied in the order given.
# File lib/padrino-core/logger.rb, line 161
def colorize(string, *colors)
  string
end
colorize!() click to toggle source

Turns a logger with LoggingExtensions into a logger with colorized output.

@example

Padrino.logger = Logger.new($stdout)
Padrino.logger.colorize!
Padrino.logger.debug("Fancy Padrino debug string")
# File lib/padrino-core/logger.rb, line 172
def colorize!
  self.extend(Colorize)
end
format(message, level) click to toggle source

Formats the log message. This method is a noop and should be implemented by other logger components such as {Padrino::Logger}.

@param [String] message

The message to format

@param [String,Symbol] level

The log level, one of :debug, :warn...
# File lib/padrino-core/logger.rb, line 132
def format(message, level)
  message
end
push(message = nil, level = nil) click to toggle source

Appends a message to the log. The methods yield to an optional block and the output of this block will be appended to the message.

@param [String] message

The message that you want write to your stream

@param [String] level

The level one of :debug, :warn etc...
# File lib/padrino-core/logger.rb, line 119
def push(message = nil, level = nil)
  add(Padrino::Logger::Levels[level], format(message, level))
end
stylized_level(level) click to toggle source

The debug level, with some style added. May be reimplemented.

@example

stylized_level(:debug) => DEBUG

@param [String,Symbol] level

The log level
# File lib/padrino-core/logger.rb, line 145
def stylized_level(level)
  level.to_s.upcase.rjust(7)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.