diff options
author | sonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-17 14:15:25 +0000 |
---|---|---|
committer | sonots <sonots@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-17 14:15:25 +0000 |
commit | 398abe4c51a5b30ed0aede285a69f73f05d629ca (patch) | |
tree | ff59c1238c3918182fbffaa0a3cc0c1dbc89986d /lib | |
parent | f952570bddc07e87b7c5a3f62dd5fbe390b7fe48 (diff) | |
download | ruby-398abe4c51a5b30ed0aede285a69f73f05d629ca.tar.gz |
* lib/logger.rb: support symbol and string log level setting
[fix GH-1101]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/logger.rb | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/logger.rb b/lib/logger.rb index 475ec2a9bf..d17896f841 100644 --- a/lib/logger.rb +++ b/lib/logger.rb @@ -176,6 +176,13 @@ require 'monitor' # # # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN # +# 3. Symbol or String (case insensitive) +# +# logger.level = :info +# logger.level = 'INFO' +# +# # :debug < :info < :warn < :error < :fatal < :unknown +# # == Format # # Log messages are rendered in the output stream in a certain format by @@ -234,7 +241,34 @@ class Logger include Severity # Logging severity threshold (e.g. <tt>Logger::INFO</tt>). - attr_accessor :level + attr_reader :level + + # Set logging severity threshold. + # + # +severity+:: The Severity of the log message. + def level=(severity) + if severity.is_a?(Integer) + @level = severity + else + _severity = severity.to_s.downcase + case _severity + when 'debug'.freeze + @level = DEBUG + when 'info'.freeze + @level = INFO + when 'warn'.freeze + @level = WARN + when 'error'.freeze + @level = ERROR + when 'fatal'.freeze + @level = FATAL + when 'unknown'.freeze + @level = UNKNOWN + else + raise ArgumentError, "invalid log level: #{severity}" + end + end + end # Program name to include in log messages. attr_accessor :progname |