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