Module: Padrino::Logger::Extensions

### Home Classes Methods

### In Files

- lib/padrino-core/logger.rb

### Methods

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

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Application
- Padrino::ApplicationLoadError
- Padrino::ApplicationSetupError
- Padrino::Cli
- Padrino::Cli::Adapter
- Padrino::Cli::Base
- Padrino::Erubis
- Padrino::Erubis::SafeBufferEnhancer
- Padrino::Erubis::SafeBufferTemplate
- Padrino::Erubis::Template
- Padrino::Filter
- Padrino::Flash
- Padrino::Flash::Helpers
- Padrino::Flash::Storage
- Padrino::Logger
- Padrino::Logger::Colorize
- Padrino::Logger::Extensions
- Padrino::Logger::Rack
- Padrino::Module
- Padrino::Mounter
- Padrino::Mounter::MounterException
- Padrino::Reloader
- Padrino::Reloader::Rack
- Padrino::Rendering
- Padrino::Rendering::ClassMethods
- Padrino::Rendering::InstanceMethods
- Padrino::Rendering::SafeTemplate
- Padrino::Rendering::TemplateNotFound
- Padrino::Router
- Padrino::Routing
- Padrino::Routing::ClassMethods
- Padrino::Routing::InstanceMethods
- Padrino::Routing::Parent
- Padrino::Routing::UnrecognizedException
- Padrino::Server
- Padrino::ShowExceptions
- Padrino::Tasks
- Padrino::Utils
- HttpRouter
- HttpRouter::Node
- HttpRouter::Node::Path
- HttpRouter::Request
- HttpRouter::Route
- Haml
- Haml::Helpers
- Haml::Util
- Sinatra
- Sinatra::Request
- Slim
- Slim::Template
- Tilt
- Tilt::HamlTemplate
- FileSet
- Kernel
- Module
- Object
- ObjectSpace
- PadrinoTasks
- String
- SupportLite

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, :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.