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