Module: Padrino::Logger::Extensions
- Included in:
- Padrino::Logger
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb
Instance Method Summary collapse
-
#bench(action, began_at, message, level = :debug, color = :yellow) ⇒ Object
Append a to development logger a given action with time.
-
#colorize(string, *colors) ⇒ Object
Colorizes a string for colored console output.
-
#colorize! ⇒ Object
Turns a logger with LoggingExtensions into a logger with colorized output.
-
#format(message, level) ⇒ Object
Formats the log message.
-
#name ⇒ Object
Generate the logging methods for Padrino.logger for each log level.
-
#push(message = nil, level = nil) ⇒ Object
Appends a message to the log.
-
#stylized_level(level) ⇒ Object
The debug level, with some style added.
Instance Method Details
#bench(action, began_at, message, level = :debug, color = :yellow) ⇒ Object
Append a to development logger a given action with time
98 99 100 101 102 103 104 105 106 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 98 def bench(action, began_at, , 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}) #{}", level end |
#colorize(string, *colors) ⇒ Object
Colorizes a string for colored console output. This is a noop and can be reimplemented to colorize the string as needed.
161 162 163 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 161 def colorize(string, *colors) string end |
#colorize! ⇒ Object
Turns a logger with LoggingExtensions into a logger with colorized output.
172 173 174 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 172 def colorize! self.extend(Colorize) end |
#format(message, level) ⇒ Object
Formats the log message. This method is a noop and should be implemented by other logger components such as Padrino::Logger.
132 133 134 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 132 def format(, level) end |
#name ⇒ Object
Generate the logging methods for Padrino.logger for each log level.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 67 Padrino::Logger::Levels.each_pair do |name, number| define_method(name) do |*args| return if number < level if args.size > 1 bench(args[0], args[1], args[2], name) else push(args * '', name) end end define_method(:"#{name}?") do number >= level end end |
#push(message = nil, level = nil) ⇒ Object
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.
119 120 121 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 119 def push( = nil, level = nil) add(Padrino::Logger::Levels[level], format(, level)) end |
#stylized_level(level) ⇒ Object
The debug level, with some style added. May be reimplemented.
145 146 147 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/logger.rb', line 145 def stylized_level(level) level.to_s.upcase.rjust(7) end |