Permalink
Browse files

add logging option for :colorize_logging

In case not want to use escape sequence, use this option.
  • Loading branch information...
tyabe committed Aug 8, 2012
1 parent 7b2f208 commit 14ebe6db68b91f8830fc06d63514295ef491cf88
Showing with 34 additions and 1 deletion.
  1. +7 −1 padrino-core/lib/padrino-core/logger.rb
  2. +27 −0 padrino-core/test/test_logger.rb
@@ -206,14 +206,14 @@ def stylized_level(level)
end
include Extensions
include Colorize
attr_accessor :level
attr_accessor :auto_flush
attr_reader :buffer
attr_reader :log
attr_reader :init_args
attr_accessor :log_static
attr_reader :colorize_logging
##
# Configuration for a given environment, possible options are:
@@ -229,6 +229,7 @@ def stylized_level(level)
# :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
#
# @example
# Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
@@ -320,6 +321,9 @@ def self.setup!
# @option options [Symbol] :log_static (false)
# Whether or not to show log messages for static files.
#
# @option options [Symbol] :colorize_logging (true)
# Whether or not to colorize log messages. Defaults to: true
#
def initialize(options={})
@buffer = []
@auto_flush = options.has_key?(:auto_flush) ? options[:auto_flush] : true
@@ -329,6 +333,8 @@ def initialize(options={})
@format_datetime = options[:format_datetime] || "%d/%b/%Y %H:%M:%S"
@format_message = options[:format_message] || "%s -%s%s"
@log_static = options.has_key?(:log_static) ? options[:log_static] : false
@colorize_logging = options.has_key?(:colorize_logging) ? options[:colorize_logging] : true
colorize! if @colorize_logging
end
##
@@ -152,3 +152,30 @@ def setup_logger
assert_match /\e\[1m200\e\[0m OK/, @log.string
end
end
describe "options :colorize_logging" do
def access_to_mock_app
mock_app do
enable :logging
get("/"){ "Foo" }
end
get "/"
end
context 'default' do
should 'use colorize logging' do
Padrino::Logger.setup!
access_to_mock_app
assert_match /\e\[1m200\e\[0m OK/, Padrino.logger.log.string
end
end
context 'set value is false' do
should 'not use colorize logging' do
Padrino::Logger::Config[:test][:colorize_logging] = false
Padrino::Logger.setup!
access_to_mock_app
assert_match /200 OK/, Padrino.logger.log.string
end
end
end

0 comments on commit 14ebe6d

Please sign in to comment.