Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: logger.rb
# logger.rb - simple logging utility
[0] Fix | Delete
# Copyright (C) 2000-2003, 2005, 2008, 2011 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
[1] Fix | Delete
#
[2] Fix | Delete
# Documentation:: NAKAMURA, Hiroshi and Gavin Sinclair
[3] Fix | Delete
# License::
[4] Fix | Delete
# You can redistribute it and/or modify it under the same terms of Ruby's
[5] Fix | Delete
# license; either the dual license version in 2003, or any later version.
[6] Fix | Delete
# Revision:: $Id: logger.rb 56504 2016-10-27 07:47:14Z usa $
[7] Fix | Delete
#
[8] Fix | Delete
# A simple system for logging messages. See Logger for more documentation.
[9] Fix | Delete
[10] Fix | Delete
require 'monitor'
[11] Fix | Delete
[12] Fix | Delete
# == Description
[13] Fix | Delete
#
[14] Fix | Delete
# The Logger class provides a simple but sophisticated logging utility that
[15] Fix | Delete
# you can use to output messages.
[16] Fix | Delete
#
[17] Fix | Delete
# The messages have associated levels, such as +INFO+ or +ERROR+ that indicate
[18] Fix | Delete
# their importance. You can then give the Logger a level, and only messages
[19] Fix | Delete
# at that level or higher will be printed.
[20] Fix | Delete
#
[21] Fix | Delete
# The levels are:
[22] Fix | Delete
#
[23] Fix | Delete
# +UNKNOWN+:: An unknown message that should always be logged.
[24] Fix | Delete
# +FATAL+:: An unhandleable error that results in a program crash.
[25] Fix | Delete
# +ERROR+:: A handleable error condition.
[26] Fix | Delete
# +WARN+:: A warning.
[27] Fix | Delete
# +INFO+:: Generic (useful) information about system operation.
[28] Fix | Delete
# +DEBUG+:: Low-level information for developers.
[29] Fix | Delete
#
[30] Fix | Delete
# For instance, in a production system, you may have your Logger set to
[31] Fix | Delete
# +INFO+ or even +WARN+.
[32] Fix | Delete
# When you are developing the system, however, you probably
[33] Fix | Delete
# want to know about the program's internal state, and would set the Logger to
[34] Fix | Delete
# +DEBUG+.
[35] Fix | Delete
#
[36] Fix | Delete
# *Note*: Logger does not escape or sanitize any messages passed to it.
[37] Fix | Delete
# Developers should be aware of when potentially malicious data (user-input)
[38] Fix | Delete
# is passed to Logger, and manually escape the untrusted data:
[39] Fix | Delete
#
[40] Fix | Delete
# logger.info("User-input: #{input.dump}")
[41] Fix | Delete
# logger.info("User-input: %p" % input)
[42] Fix | Delete
#
[43] Fix | Delete
# You can use #formatter= for escaping all data.
[44] Fix | Delete
#
[45] Fix | Delete
# original_formatter = Logger::Formatter.new
[46] Fix | Delete
# logger.formatter = proc { |severity, datetime, progname, msg|
[47] Fix | Delete
# original_formatter.call(severity, datetime, progname, msg.dump)
[48] Fix | Delete
# }
[49] Fix | Delete
# logger.info(input)
[50] Fix | Delete
#
[51] Fix | Delete
# === Example
[52] Fix | Delete
#
[53] Fix | Delete
# This creates a Logger that outputs to the standard output stream, with a
[54] Fix | Delete
# level of +WARN+:
[55] Fix | Delete
#
[56] Fix | Delete
# require 'logger'
[57] Fix | Delete
#
[58] Fix | Delete
# logger = Logger.new(STDOUT)
[59] Fix | Delete
# logger.level = Logger::WARN
[60] Fix | Delete
#
[61] Fix | Delete
# logger.debug("Created logger")
[62] Fix | Delete
# logger.info("Program started")
[63] Fix | Delete
# logger.warn("Nothing to do!")
[64] Fix | Delete
#
[65] Fix | Delete
# path = "a_non_existent_file"
[66] Fix | Delete
#
[67] Fix | Delete
# begin
[68] Fix | Delete
# File.foreach(path) do |line|
[69] Fix | Delete
# unless line =~ /^(\w+) = (.*)$/
[70] Fix | Delete
# logger.error("Line in wrong format: #{line.chomp}")
[71] Fix | Delete
# end
[72] Fix | Delete
# end
[73] Fix | Delete
# rescue => err
[74] Fix | Delete
# logger.fatal("Caught exception; exiting")
[75] Fix | Delete
# logger.fatal(err)
[76] Fix | Delete
# end
[77] Fix | Delete
#
[78] Fix | Delete
# Because the Logger's level is set to +WARN+, only the warning, error, and
[79] Fix | Delete
# fatal messages are recorded. The debug and info messages are silently
[80] Fix | Delete
# discarded.
[81] Fix | Delete
#
[82] Fix | Delete
# === Features
[83] Fix | Delete
#
[84] Fix | Delete
# There are several interesting features that Logger provides, like
[85] Fix | Delete
# auto-rolling of log files, setting the format of log messages, and
[86] Fix | Delete
# specifying a program name in conjunction with the message. The next section
[87] Fix | Delete
# shows you how to achieve these things.
[88] Fix | Delete
#
[89] Fix | Delete
#
[90] Fix | Delete
# == HOWTOs
[91] Fix | Delete
#
[92] Fix | Delete
# === How to create a logger
[93] Fix | Delete
#
[94] Fix | Delete
# The options below give you various choices, in more or less increasing
[95] Fix | Delete
# complexity.
[96] Fix | Delete
#
[97] Fix | Delete
# 1. Create a logger which logs messages to STDERR/STDOUT.
[98] Fix | Delete
#
[99] Fix | Delete
# logger = Logger.new(STDERR)
[100] Fix | Delete
# logger = Logger.new(STDOUT)
[101] Fix | Delete
#
[102] Fix | Delete
# 2. Create a logger for the file which has the specified name.
[103] Fix | Delete
#
[104] Fix | Delete
# logger = Logger.new('logfile.log')
[105] Fix | Delete
#
[106] Fix | Delete
# 3. Create a logger for the specified file.
[107] Fix | Delete
#
[108] Fix | Delete
# file = File.open('foo.log', File::WRONLY | File::APPEND)
[109] Fix | Delete
# # To create new (and to remove old) logfile, add File::CREAT like:
[110] Fix | Delete
# # file = File.open('foo.log', File::WRONLY | File::APPEND | File::CREAT)
[111] Fix | Delete
# logger = Logger.new(file)
[112] Fix | Delete
#
[113] Fix | Delete
# 4. Create a logger which ages the logfile once it reaches a certain size.
[114] Fix | Delete
# Leave 10 "old" log files where each file is about 1,024,000 bytes.
[115] Fix | Delete
#
[116] Fix | Delete
# logger = Logger.new('foo.log', 10, 1024000)
[117] Fix | Delete
#
[118] Fix | Delete
# 5. Create a logger which ages the logfile daily/weekly/monthly.
[119] Fix | Delete
#
[120] Fix | Delete
# logger = Logger.new('foo.log', 'daily')
[121] Fix | Delete
# logger = Logger.new('foo.log', 'weekly')
[122] Fix | Delete
# logger = Logger.new('foo.log', 'monthly')
[123] Fix | Delete
#
[124] Fix | Delete
# === How to log a message
[125] Fix | Delete
#
[126] Fix | Delete
# Notice the different methods (+fatal+, +error+, +info+) being used to log
[127] Fix | Delete
# messages of various levels? Other methods in this family are +warn+ and
[128] Fix | Delete
# +debug+. +add+ is used below to log a message of an arbitrary (perhaps
[129] Fix | Delete
# dynamic) level.
[130] Fix | Delete
#
[131] Fix | Delete
# 1. Message in a block.
[132] Fix | Delete
#
[133] Fix | Delete
# logger.fatal { "Argument 'foo' not given." }
[134] Fix | Delete
#
[135] Fix | Delete
# 2. Message as a string.
[136] Fix | Delete
#
[137] Fix | Delete
# logger.error "Argument #{@foo} mismatch."
[138] Fix | Delete
#
[139] Fix | Delete
# 3. With progname.
[140] Fix | Delete
#
[141] Fix | Delete
# logger.info('initialize') { "Initializing..." }
[142] Fix | Delete
#
[143] Fix | Delete
# 4. With severity.
[144] Fix | Delete
#
[145] Fix | Delete
# logger.add(Logger::FATAL) { 'Fatal error!' }
[146] Fix | Delete
#
[147] Fix | Delete
# The block form allows you to create potentially complex log messages,
[148] Fix | Delete
# but to delay their evaluation until and unless the message is
[149] Fix | Delete
# logged. For example, if we have the following:
[150] Fix | Delete
#
[151] Fix | Delete
# logger.debug { "This is a " + potentially + " expensive operation" }
[152] Fix | Delete
#
[153] Fix | Delete
# If the logger's level is +INFO+ or higher, no debug messages will be logged,
[154] Fix | Delete
# and the entire block will not even be evaluated. Compare to this:
[155] Fix | Delete
#
[156] Fix | Delete
# logger.debug("This is a " + potentially + " expensive operation")
[157] Fix | Delete
#
[158] Fix | Delete
# Here, the string concatenation is done every time, even if the log
[159] Fix | Delete
# level is not set to show the debug message.
[160] Fix | Delete
#
[161] Fix | Delete
# === How to close a logger
[162] Fix | Delete
#
[163] Fix | Delete
# logger.close
[164] Fix | Delete
#
[165] Fix | Delete
# === Setting severity threshold
[166] Fix | Delete
#
[167] Fix | Delete
# 1. Original interface.
[168] Fix | Delete
#
[169] Fix | Delete
# logger.sev_threshold = Logger::WARN
[170] Fix | Delete
#
[171] Fix | Delete
# 2. Log4r (somewhat) compatible interface.
[172] Fix | Delete
#
[173] Fix | Delete
# logger.level = Logger::INFO
[174] Fix | Delete
#
[175] Fix | Delete
# # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
[176] Fix | Delete
#
[177] Fix | Delete
# == Format
[178] Fix | Delete
#
[179] Fix | Delete
# Log messages are rendered in the output stream in a certain format by
[180] Fix | Delete
# default. The default format and a sample are shown below:
[181] Fix | Delete
#
[182] Fix | Delete
# Log format:
[183] Fix | Delete
# SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
[184] Fix | Delete
#
[185] Fix | Delete
# Log sample:
[186] Fix | Delete
# I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
[187] Fix | Delete
#
[188] Fix | Delete
# You may change the date and time format via #datetime_format=.
[189] Fix | Delete
#
[190] Fix | Delete
# logger.datetime_format = '%Y-%m-%d %H:%M:%S'
[191] Fix | Delete
# # e.g. "2004-01-03 00:54:26"
[192] Fix | Delete
#
[193] Fix | Delete
# Or, you may change the overall format via the #formatter= method.
[194] Fix | Delete
#
[195] Fix | Delete
# logger.formatter = proc do |severity, datetime, progname, msg|
[196] Fix | Delete
# "#{datetime}: #{msg}\n"
[197] Fix | Delete
# end
[198] Fix | Delete
# # e.g. "2005-09-22 08:51:08 +0900: hello world"
[199] Fix | Delete
#
[200] Fix | Delete
class Logger
[201] Fix | Delete
VERSION = "1.2.7"
[202] Fix | Delete
_, name, rev = %w$Id: logger.rb 56504 2016-10-27 07:47:14Z usa $
[203] Fix | Delete
if name
[204] Fix | Delete
name = name.chomp(",v")
[205] Fix | Delete
else
[206] Fix | Delete
name = File.basename(__FILE__)
[207] Fix | Delete
end
[208] Fix | Delete
rev ||= "v#{VERSION}"
[209] Fix | Delete
ProgName = "#{name}/#{rev}"
[210] Fix | Delete
[211] Fix | Delete
class Error < RuntimeError # :nodoc:
[212] Fix | Delete
end
[213] Fix | Delete
# not used after 1.2.7. just for compat.
[214] Fix | Delete
class ShiftingError < Error # :nodoc:
[215] Fix | Delete
end
[216] Fix | Delete
[217] Fix | Delete
# Logging severity.
[218] Fix | Delete
module Severity
[219] Fix | Delete
# Low-level information, mostly for developers.
[220] Fix | Delete
DEBUG = 0
[221] Fix | Delete
# Generic (useful) information about system operation.
[222] Fix | Delete
INFO = 1
[223] Fix | Delete
# A warning.
[224] Fix | Delete
WARN = 2
[225] Fix | Delete
# A handleable error condition.
[226] Fix | Delete
ERROR = 3
[227] Fix | Delete
# An unhandleable error that results in a program crash.
[228] Fix | Delete
FATAL = 4
[229] Fix | Delete
# An unknown message that should always be logged.
[230] Fix | Delete
UNKNOWN = 5
[231] Fix | Delete
end
[232] Fix | Delete
include Severity
[233] Fix | Delete
[234] Fix | Delete
# Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
[235] Fix | Delete
attr_accessor :level
[236] Fix | Delete
[237] Fix | Delete
# Program name to include in log messages.
[238] Fix | Delete
attr_accessor :progname
[239] Fix | Delete
[240] Fix | Delete
# Set date-time format.
[241] Fix | Delete
#
[242] Fix | Delete
# +datetime_format+:: A string suitable for passing to +strftime+.
[243] Fix | Delete
def datetime_format=(datetime_format)
[244] Fix | Delete
@default_formatter.datetime_format = datetime_format
[245] Fix | Delete
end
[246] Fix | Delete
[247] Fix | Delete
# Returns the date format being used. See #datetime_format=
[248] Fix | Delete
def datetime_format
[249] Fix | Delete
@default_formatter.datetime_format
[250] Fix | Delete
end
[251] Fix | Delete
[252] Fix | Delete
# Logging formatter, as a +Proc+ that will take four arguments and
[253] Fix | Delete
# return the formatted message. The arguments are:
[254] Fix | Delete
#
[255] Fix | Delete
# +severity+:: The Severity of the log message.
[256] Fix | Delete
# +time+:: A Time instance representing when the message was logged.
[257] Fix | Delete
# +progname+:: The #progname configured, or passed to the logger method.
[258] Fix | Delete
# +msg+:: The _Object_ the user passed to the log message; not necessarily a
[259] Fix | Delete
# String.
[260] Fix | Delete
#
[261] Fix | Delete
# The block should return an Object that can be written to the logging
[262] Fix | Delete
# device via +write+. The default formatter is used when no formatter is
[263] Fix | Delete
# set.
[264] Fix | Delete
attr_accessor :formatter
[265] Fix | Delete
[266] Fix | Delete
alias sev_threshold level
[267] Fix | Delete
alias sev_threshold= level=
[268] Fix | Delete
[269] Fix | Delete
# Returns +true+ iff the current severity level allows for the printing of
[270] Fix | Delete
# +DEBUG+ messages.
[271] Fix | Delete
def debug?; @level <= DEBUG; end
[272] Fix | Delete
[273] Fix | Delete
# Returns +true+ iff the current severity level allows for the printing of
[274] Fix | Delete
# +INFO+ messages.
[275] Fix | Delete
def info?; @level <= INFO; end
[276] Fix | Delete
[277] Fix | Delete
# Returns +true+ iff the current severity level allows for the printing of
[278] Fix | Delete
# +WARN+ messages.
[279] Fix | Delete
def warn?; @level <= WARN; end
[280] Fix | Delete
[281] Fix | Delete
# Returns +true+ iff the current severity level allows for the printing of
[282] Fix | Delete
# +ERROR+ messages.
[283] Fix | Delete
def error?; @level <= ERROR; end
[284] Fix | Delete
[285] Fix | Delete
# Returns +true+ iff the current severity level allows for the printing of
[286] Fix | Delete
# +FATAL+ messages.
[287] Fix | Delete
def fatal?; @level <= FATAL; end
[288] Fix | Delete
[289] Fix | Delete
#
[290] Fix | Delete
# :call-seq:
[291] Fix | Delete
# Logger.new(logdev, shift_age = 7, shift_size = 1048576)
[292] Fix | Delete
# Logger.new(logdev, shift_age = 'weekly')
[293] Fix | Delete
#
[294] Fix | Delete
# === Args
[295] Fix | Delete
#
[296] Fix | Delete
# +logdev+::
[297] Fix | Delete
# The log device. This is a filename (String) or IO object (typically
[298] Fix | Delete
# +STDOUT+, +STDERR+, or an open file).
[299] Fix | Delete
# +shift_age+::
[300] Fix | Delete
# Number of old log files to keep, *or* frequency of rotation (+daily+,
[301] Fix | Delete
# +weekly+ or +monthly+).
[302] Fix | Delete
# +shift_size+::
[303] Fix | Delete
# Maximum logfile size (only applies when +shift_age+ is a number).
[304] Fix | Delete
#
[305] Fix | Delete
# === Description
[306] Fix | Delete
#
[307] Fix | Delete
# Create an instance.
[308] Fix | Delete
#
[309] Fix | Delete
def initialize(logdev, shift_age = 0, shift_size = 1048576)
[310] Fix | Delete
@progname = nil
[311] Fix | Delete
@level = DEBUG
[312] Fix | Delete
@default_formatter = Formatter.new
[313] Fix | Delete
@formatter = nil
[314] Fix | Delete
@logdev = nil
[315] Fix | Delete
if logdev
[316] Fix | Delete
@logdev = LogDevice.new(logdev, :shift_age => shift_age,
[317] Fix | Delete
:shift_size => shift_size)
[318] Fix | Delete
end
[319] Fix | Delete
end
[320] Fix | Delete
[321] Fix | Delete
#
[322] Fix | Delete
# :call-seq:
[323] Fix | Delete
# Logger#add(severity, message = nil, progname = nil) { ... }
[324] Fix | Delete
#
[325] Fix | Delete
# === Args
[326] Fix | Delete
#
[327] Fix | Delete
# +severity+::
[328] Fix | Delete
# Severity. Constants are defined in Logger namespace: +DEBUG+, +INFO+,
[329] Fix | Delete
# +WARN+, +ERROR+, +FATAL+, or +UNKNOWN+.
[330] Fix | Delete
# +message+::
[331] Fix | Delete
# The log message. A String or Exception.
[332] Fix | Delete
# +progname+::
[333] Fix | Delete
# Program name string. Can be omitted. Treated as a message if no
[334] Fix | Delete
# +message+ and +block+ are given.
[335] Fix | Delete
# +block+::
[336] Fix | Delete
# Can be omitted. Called to get a message string if +message+ is nil.
[337] Fix | Delete
#
[338] Fix | Delete
# === Return
[339] Fix | Delete
#
[340] Fix | Delete
# When the given severity is not high enough (for this particular logger),
[341] Fix | Delete
# log no message, and return +true+.
[342] Fix | Delete
#
[343] Fix | Delete
# === Description
[344] Fix | Delete
#
[345] Fix | Delete
# Log a message if the given severity is high enough. This is the generic
[346] Fix | Delete
# logging method. Users will be more inclined to use #debug, #info, #warn,
[347] Fix | Delete
# #error, and #fatal.
[348] Fix | Delete
#
[349] Fix | Delete
# <b>Message format</b>: +message+ can be any object, but it has to be
[350] Fix | Delete
# converted to a String in order to log it. Generally, +inspect+ is used
[351] Fix | Delete
# if the given object is not a String.
[352] Fix | Delete
# A special case is an +Exception+ object, which will be printed in detail,
[353] Fix | Delete
# including message, class, and backtrace. See #msg2str for the
[354] Fix | Delete
# implementation if required.
[355] Fix | Delete
#
[356] Fix | Delete
# === Bugs
[357] Fix | Delete
#
[358] Fix | Delete
# * Logfile is not locked.
[359] Fix | Delete
# * Append open does not need to lock file.
[360] Fix | Delete
# * If the OS supports multi I/O, records possibly may be mixed.
[361] Fix | Delete
#
[362] Fix | Delete
def add(severity, message = nil, progname = nil)
[363] Fix | Delete
severity ||= UNKNOWN
[364] Fix | Delete
if @logdev.nil? or severity < @level
[365] Fix | Delete
return true
[366] Fix | Delete
end
[367] Fix | Delete
progname ||= @progname
[368] Fix | Delete
if message.nil?
[369] Fix | Delete
if block_given?
[370] Fix | Delete
message = yield
[371] Fix | Delete
else
[372] Fix | Delete
message = progname
[373] Fix | Delete
progname = @progname
[374] Fix | Delete
end
[375] Fix | Delete
end
[376] Fix | Delete
@logdev.write(
[377] Fix | Delete
format_message(format_severity(severity), Time.now, progname, message))
[378] Fix | Delete
true
[379] Fix | Delete
end
[380] Fix | Delete
alias log add
[381] Fix | Delete
[382] Fix | Delete
#
[383] Fix | Delete
# Dump given message to the log device without any formatting. If no log
[384] Fix | Delete
# device exists, return +nil+.
[385] Fix | Delete
#
[386] Fix | Delete
def <<(msg)
[387] Fix | Delete
unless @logdev.nil?
[388] Fix | Delete
@logdev.write(msg)
[389] Fix | Delete
end
[390] Fix | Delete
end
[391] Fix | Delete
[392] Fix | Delete
#
[393] Fix | Delete
# Log a +DEBUG+ message.
[394] Fix | Delete
#
[395] Fix | Delete
# See #info for more information.
[396] Fix | Delete
#
[397] Fix | Delete
def debug(progname = nil, &block)
[398] Fix | Delete
add(DEBUG, nil, progname, &block)
[399] Fix | Delete
end
[400] Fix | Delete
[401] Fix | Delete
#
[402] Fix | Delete
# :call-seq:
[403] Fix | Delete
# info(message)
[404] Fix | Delete
# info(progname, &block)
[405] Fix | Delete
#
[406] Fix | Delete
# Log an +INFO+ message.
[407] Fix | Delete
#
[408] Fix | Delete
# +message+:: The message to log; does not need to be a String.
[409] Fix | Delete
# +progname+:: In the block form, this is the #progname to use in the
[410] Fix | Delete
# log message. The default can be set with #progname=.
[411] Fix | Delete
# +block+:: Evaluates to the message to log. This is not evaluated unless
[412] Fix | Delete
# the logger's level is sufficient to log the message. This
[413] Fix | Delete
# allows you to create potentially expensive logging messages that
[414] Fix | Delete
# are only called when the logger is configured to show them.
[415] Fix | Delete
#
[416] Fix | Delete
# === Examples
[417] Fix | Delete
#
[418] Fix | Delete
# logger.info("MainApp") { "Received connection from #{ip}" }
[419] Fix | Delete
# # ...
[420] Fix | Delete
# logger.info "Waiting for input from user"
[421] Fix | Delete
# # ...
[422] Fix | Delete
# logger.info { "User typed #{input}" }
[423] Fix | Delete
#
[424] Fix | Delete
# You'll probably stick to the second form above, unless you want to provide a
[425] Fix | Delete
# program name (which you can do with #progname= as well).
[426] Fix | Delete
#
[427] Fix | Delete
# === Return
[428] Fix | Delete
#
[429] Fix | Delete
# See #add.
[430] Fix | Delete
#
[431] Fix | Delete
def info(progname = nil, &block)
[432] Fix | Delete
add(INFO, nil, progname, &block)
[433] Fix | Delete
end
[434] Fix | Delete
[435] Fix | Delete
#
[436] Fix | Delete
# Log a +WARN+ message.
[437] Fix | Delete
#
[438] Fix | Delete
# See #info for more information.
[439] Fix | Delete
#
[440] Fix | Delete
def warn(progname = nil, &block)
[441] Fix | Delete
add(WARN, nil, progname, &block)
[442] Fix | Delete
end
[443] Fix | Delete
[444] Fix | Delete
#
[445] Fix | Delete
# Log an +ERROR+ message.
[446] Fix | Delete
#
[447] Fix | Delete
# See #info for more information.
[448] Fix | Delete
#
[449] Fix | Delete
def error(progname = nil, &block)
[450] Fix | Delete
add(ERROR, nil, progname, &block)
[451] Fix | Delete
end
[452] Fix | Delete
[453] Fix | Delete
#
[454] Fix | Delete
# Log a +FATAL+ message.
[455] Fix | Delete
#
[456] Fix | Delete
# See #info for more information.
[457] Fix | Delete
#
[458] Fix | Delete
def fatal(progname = nil, &block)
[459] Fix | Delete
add(FATAL, nil, progname, &block)
[460] Fix | Delete
end
[461] Fix | Delete
[462] Fix | Delete
#
[463] Fix | Delete
# Log an +UNKNOWN+ message. This will be printed no matter what the logger's
[464] Fix | Delete
# level is.
[465] Fix | Delete
#
[466] Fix | Delete
# See #info for more information.
[467] Fix | Delete
#
[468] Fix | Delete
def unknown(progname = nil, &block)
[469] Fix | Delete
add(UNKNOWN, nil, progname, &block)
[470] Fix | Delete
end
[471] Fix | Delete
[472] Fix | Delete
#
[473] Fix | Delete
# Close the logging device.
[474] Fix | Delete
#
[475] Fix | Delete
def close
[476] Fix | Delete
@logdev.close if @logdev
[477] Fix | Delete
end
[478] Fix | Delete
[479] Fix | Delete
private
[480] Fix | Delete
[481] Fix | Delete
# Severity label for logging (max 5 chars).
[482] Fix | Delete
SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
[483] Fix | Delete
[484] Fix | Delete
def format_severity(severity)
[485] Fix | Delete
SEV_LABEL[severity] || 'ANY'
[486] Fix | Delete
end
[487] Fix | Delete
[488] Fix | Delete
def format_message(severity, datetime, progname, msg)
[489] Fix | Delete
(@formatter || @default_formatter).call(severity, datetime, progname, msg)
[490] Fix | Delete
end
[491] Fix | Delete
[492] Fix | Delete
[493] Fix | Delete
# Default formatter for log messages.
[494] Fix | Delete
class Formatter
[495] Fix | Delete
Format = "%s, [%s#%d] %5s -- %s: %s\n"
[496] Fix | Delete
[497] Fix | Delete
attr_accessor :datetime_format
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function