Module: Padrino::Logger::Extensions

### Home Classes Methods

### In Files

- lib/padrino-core/logger.rb

### Methods

- #bench
- #colorize
- #colorize!
- #exception
- #format
- #push
- #stylized_level

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Application
- Padrino::ApplicationLoadError
- Padrino::ApplicationSetup
- Padrino::ApplicationSetup::ClassMethods
- Padrino::AuthenticityToken
- Padrino::Cli
- Padrino::Cli::Adapter
- Padrino::Cli::Base
- Padrino::Cli::Launcher
- Padrino::Filter
- Padrino::Flash
- Padrino::Flash::Helpers
- Padrino::Flash::Storage
- Padrino::Loader
- Padrino::Logger
- Padrino::Logger::Colorize
- Padrino::Logger::Extensions
- Padrino::Logger::Rack
- Padrino::Module
- Padrino::Mounter
- Padrino::Mounter::ApplicationWrapper
- Padrino::Mounter::MounterException
- Padrino::ParamsProtection
- Padrino::ParamsProtection::ClassMethods
- Padrino::ParamsProtection::InstanceMethods
- Padrino::Reloader
- Padrino::Reloader::Rack
- Padrino::Reloader::Storage
- Padrino::Router
- Padrino::Routing
- Padrino::Routing::ClassMethods
- Padrino::Routing::InstanceMethods
- Padrino::Routing::Parent
- Padrino::Routing::UnrecognizedException
- Padrino::Server
- Padrino::ShowExceptions
- Padrino::Tasks
- HttpRouter
- HttpRouter::Node
- HttpRouter::Node::FreeRegex
- HttpRouter::Node::Glob
- HttpRouter::Node::Path
- HttpRouter::Node::SpanningRegex
- HttpRouter::Request
- HttpRouter::Route
- Sinatra
- Sinatra::Base
- Sinatra::Request
- Kernel
- Object
- PadrinoTasks

No matching classes.

# 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, color, :bold)
      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

exception(boom, verbosity = :long, level = :error) click to toggle source

Logs an exception.

@param [Exception] exception

    The exception to log

@param [Symbol] verbosity

    :short or :long, default is :long

@example

    Padrino.logger.exception e
    Padrino.logger.exception(e, :short)

    # File lib/padrino-core/logger.rb, line 188
    def exception(boom, verbosity = :long, level = :error)
      return unless Levels.has_key?(level)
      text = ["#{boom.class} - #{boom.message}:"]
      trace = boom.backtrace
      case verbosity
      when :long
        text += trace
      when :short
        text << trace.first
      end if trace.kind_of?(Array)
      send level, text.join("\n ")
    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.