mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/logger.rb: Updated typos and output to match modern Logger
output. Patch by Marcus Stollsteimer. [Bug #6738] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
08f46f0818
commit
fe6aa0e16a
2 changed files with 58 additions and 51 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jul 18 09:26:45 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/logger.rb: Updated typos and output to match modern Logger
|
||||
output. Patch by Marcus Stollsteimer. [Bug #6738]
|
||||
|
||||
Wed Jul 18 07:59:29 2012 Takeyuki FUJIOKA <xibbar@ruby-lang.org>
|
||||
|
||||
* lib/cgi/util.rb (CGI.escapeHTML,unescapeHTML): Add ' for HTML5 escaping.
|
||||
|
|
104
lib/logger.rb
104
lib/logger.rb
|
@ -18,18 +18,19 @@ require 'monitor'
|
|||
#
|
||||
# The messages have associated levels, such as +INFO+ or +ERROR+ that indicate
|
||||
# their importance. You can then give the Logger a level, and only messages
|
||||
# at that level of higher will be printed.
|
||||
# at that level or higher will be printed.
|
||||
#
|
||||
# The levels are:
|
||||
#
|
||||
# +FATAL+:: an unhandleable error that results in a program crash
|
||||
# +ERROR+:: a handleable error condition
|
||||
# +WARN+:: a warning
|
||||
# +INFO+:: generic (useful) information about system operation
|
||||
# +DEBUG+:: low-level information for developers
|
||||
# +UNKNOWN+:: An unknown message that should always be logged.
|
||||
# +FATAL+:: An unhandleable error that results in a program crash.
|
||||
# +ERROR+:: A handleable error condition.
|
||||
# +WARN+:: A warning.
|
||||
# +INFO+:: Generic (useful) information about system operation.
|
||||
# +DEBUG+:: Low-level information for developers.
|
||||
#
|
||||
# For instance, in a production system, you may have your Logger set to
|
||||
# +INFO+ or even +WARN+
|
||||
# +INFO+ or even +WARN+.
|
||||
# When you are developing the system, however, you probably
|
||||
# want to know about the program's internal state, and would set the Logger to
|
||||
# +DEBUG+.
|
||||
|
@ -51,7 +52,10 @@ require 'monitor'
|
|||
#
|
||||
# === Example
|
||||
#
|
||||
# This creates a logger to the standard output stream, with a level of +WARN+
|
||||
# This creates a Logger that outputs to the standard output stream, with a
|
||||
# level of +WARN+:
|
||||
#
|
||||
# require 'logger'
|
||||
#
|
||||
# log = Logger.new(STDOUT)
|
||||
# log.level = Logger::WARN
|
||||
|
@ -102,16 +106,16 @@ require 'monitor'
|
|||
# 3. Create a logger for the specified file.
|
||||
#
|
||||
# file = File.open('foo.log', File::WRONLY | File::APPEND)
|
||||
# # To create new (and to remove old) logfile, add File::CREAT like;
|
||||
# # file = open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
|
||||
# # To create new (and to remove old) logfile, add File::CREAT like:
|
||||
# # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
|
||||
# logger = Logger.new(file)
|
||||
#
|
||||
# 4. Create a logger which ages logfile once it reaches a certain size. Leave
|
||||
# 10 "old log files" and each file is about 1,024,000 bytes.
|
||||
# 4. Create a logger which ages the logfile once it reaches a certain size.
|
||||
# Leave 10 "old" log files where each file is about 1,024,000 bytes.
|
||||
#
|
||||
# logger = Logger.new('foo.log', 10, 1024000)
|
||||
#
|
||||
# 5. Create a logger which ages logfile daily/weekly/monthly.
|
||||
# 5. Create a logger which ages the logfile daily/weekly/monthly.
|
||||
#
|
||||
# logger = Logger.new('foo.log', 'daily')
|
||||
# logger = Logger.new('foo.log', 'weekly')
|
||||
|
@ -124,13 +128,13 @@ require 'monitor'
|
|||
# +debug+. +add+ is used below to log a message of an arbitrary (perhaps
|
||||
# dynamic) level.
|
||||
#
|
||||
# 1. Message in block.
|
||||
# 1. Message in a block.
|
||||
#
|
||||
# logger.fatal { "Argument 'foo' not given." }
|
||||
#
|
||||
# 2. Message as a string.
|
||||
#
|
||||
# logger.error "Argument #{ @foo } mismatch."
|
||||
# logger.error "Argument #{@foo} mismatch."
|
||||
#
|
||||
# 3. With progname.
|
||||
#
|
||||
|
@ -168,8 +172,7 @@ require 'monitor'
|
|||
#
|
||||
# logger.level = Logger::INFO
|
||||
#
|
||||
# DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
|
||||
#
|
||||
# # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
|
||||
#
|
||||
# == Format
|
||||
#
|
||||
|
@ -177,22 +180,22 @@ require 'monitor'
|
|||
# default. The default format and a sample are shown below:
|
||||
#
|
||||
# Log format:
|
||||
# SeverityID, [Date Time mSec #pid] SeverityLabel -- ProgName: message
|
||||
# SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
|
||||
#
|
||||
# Log sample:
|
||||
# I, [Wed Mar 03 02:34:24 JST 1999 895701 #19074] INFO -- Main: info.
|
||||
# I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
|
||||
#
|
||||
# You may change the date and time format via #datetime_format=
|
||||
# You may change the date and time format via #datetime_format=.
|
||||
#
|
||||
# logger.datetime_format = "%Y-%m-%d %H:%M:%S"
|
||||
# logger.datetime_format = '%Y-%m-%d %H:%M:%S'
|
||||
# # e.g. "2004-01-03 00:54:26"
|
||||
#
|
||||
# Or, you may change the overall format with #formatter= method.
|
||||
# Or, you may change the overall format via the #formatter= method.
|
||||
#
|
||||
# logger.formatter = proc do |severity, datetime, progname, msg|
|
||||
# "#{datetime}: #{msg}\n"
|
||||
# end
|
||||
# # e.g. "Thu Sep 22 08:51:08 GMT+9:00 2005: hello world"
|
||||
# # e.g. "2005-09-22 08:51:08 +0900: hello world"
|
||||
#
|
||||
class Logger
|
||||
VERSION = "1.2.7"
|
||||
|
@ -213,17 +216,17 @@ class Logger
|
|||
|
||||
# Logging severity.
|
||||
module Severity
|
||||
# Low-level information, mostly for developers
|
||||
# Low-level information, mostly for developers.
|
||||
DEBUG = 0
|
||||
# generic, useful information about system operation
|
||||
# Generic (useful) information about system operation.
|
||||
INFO = 1
|
||||
# a warning
|
||||
# A warning.
|
||||
WARN = 2
|
||||
# a handleable error condition
|
||||
# A handleable error condition.
|
||||
ERROR = 3
|
||||
# an unhandleable error that results in a program crash
|
||||
# An unhandleable error that results in a program crash.
|
||||
FATAL = 4
|
||||
# an unknown message that should always be logged
|
||||
# An unknown message that should always be logged.
|
||||
UNKNOWN = 5
|
||||
end
|
||||
include Severity
|
||||
|
@ -231,7 +234,7 @@ class Logger
|
|||
# Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
|
||||
attr_accessor :level
|
||||
|
||||
# program name to include in log messages.
|
||||
# Program name to include in log messages.
|
||||
attr_accessor :progname
|
||||
|
||||
# Set date-time format.
|
||||
|
@ -249,9 +252,9 @@ class Logger
|
|||
# Logging formatter, as a +Proc+ that will take four arguments and
|
||||
# return the formatted message. The arguments are:
|
||||
#
|
||||
# +severity+:: The Severity of the log message
|
||||
# +time+:: A Time instance representing when the message was logged
|
||||
# +progname+:: The #progname configured, or passed to the logger method
|
||||
# +severity+:: The Severity of the log message.
|
||||
# +time+:: A Time instance representing when the message was logged.
|
||||
# +progname+:: The #progname configured, or passed to the logger method.
|
||||
# +msg+:: The _Object_ the user passed to the log message; not necessarily a
|
||||
# String.
|
||||
#
|
||||
|
@ -338,8 +341,8 @@ class Logger
|
|||
#
|
||||
# +true+ if successful, +false+ otherwise.
|
||||
#
|
||||
# When the given severity is not high enough (for this particular logger), log
|
||||
# no message, and return +true+.
|
||||
# When the given severity is not high enough (for this particular logger),
|
||||
# log no message, and return +true+.
|
||||
#
|
||||
# === Description
|
||||
#
|
||||
|
@ -358,7 +361,7 @@ class Logger
|
|||
#
|
||||
# * Logfile is not locked.
|
||||
# * Append open does not need to lock file.
|
||||
# * If the OS which supports multi I/O, records possibly be mixed.
|
||||
# * If the OS supports multi I/O, records possibly may be mixed.
|
||||
#
|
||||
def add(severity, message = nil, progname = nil, &block)
|
||||
severity ||= UNKNOWN
|
||||
|
@ -402,18 +405,17 @@ class Logger
|
|||
#
|
||||
# :call-seq:
|
||||
# info(message)
|
||||
# info(progname,&block)
|
||||
# info(progname, &block)
|
||||
#
|
||||
# Log an +INFO+ message.
|
||||
#
|
||||
# +message+:: the message to log; does not need to be a String
|
||||
# +progname+:: in the block form, this is the #progname to use in the
|
||||
# the log message. The default can be set with #progname=
|
||||
# <tt>&block</tt>:: evaluates to the message to log. This is not evaluated
|
||||
# unless the logger's level is sufficient
|
||||
# to log the message. This allows you to create
|
||||
# potentially expensive logging messages that are
|
||||
# only called when the logger is configured to show them.
|
||||
# +message+:: The message to log; does not need to be a String.
|
||||
# +progname+:: In the block form, this is the #progname to use in the
|
||||
# log message. The default can be set with #progname=.
|
||||
# +block+:: Evaluates to the message to log. This is not evaluated unless
|
||||
# the logger's level is sufficient to log the message. This
|
||||
# allows you to create potentially expensive logging messages that
|
||||
# are only called when the logger is configured to show them.
|
||||
#
|
||||
# === Examples
|
||||
#
|
||||
|
@ -463,7 +465,7 @@ class Logger
|
|||
|
||||
#
|
||||
# Log an +UNKNOWN+ message. This will be printed no matter what the logger's
|
||||
# level.
|
||||
# level is.
|
||||
#
|
||||
# See #info for more information.
|
||||
#
|
||||
|
@ -480,7 +482,7 @@ class Logger
|
|||
|
||||
private
|
||||
|
||||
# Severity label for logging. (max 5 char)
|
||||
# Severity label for logging (max 5 chars).
|
||||
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
|
||||
|
||||
def format_severity(severity)
|
||||
|
@ -492,7 +494,7 @@ private
|
|||
end
|
||||
|
||||
|
||||
# Default formatter for log messages
|
||||
# Default formatter for log messages.
|
||||
class Formatter
|
||||
Format = "%s, [%s#%d] %5s -- %s: %s\n"
|
||||
|
||||
|
@ -678,13 +680,13 @@ private
|
|||
#
|
||||
# == Description
|
||||
#
|
||||
# Application -- Add logging support to your application.
|
||||
# Application --- Add logging support to your application.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# 1. Define your application class as a sub-class of this class.
|
||||
# 2. Override 'run' method in your class to do many things.
|
||||
# 3. Instantiate it and invoke 'start'.
|
||||
# 2. Override the +run+ method in your class to do many things.
|
||||
# 3. Instantiate it and invoke #start.
|
||||
#
|
||||
# == Example
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue