Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby32/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
require 'rbconfig'
[13] Fix | Delete
[14] Fix | Delete
require_relative 'logger/version'
[15] Fix | Delete
require_relative 'logger/formatter'
[16] Fix | Delete
require_relative 'logger/log_device'
[17] Fix | Delete
require_relative 'logger/severity'
[18] Fix | Delete
require_relative 'logger/errors'
[19] Fix | Delete
[20] Fix | Delete
# \Class \Logger provides a simple but sophisticated logging utility that
[21] Fix | Delete
# you can use to create one or more
[22] Fix | Delete
# {event logs}[https://en.wikipedia.org/wiki/Logging_(software)#Event_logs]
[23] Fix | Delete
# for your program.
[24] Fix | Delete
# Each such log contains a chronological sequence of entries
[25] Fix | Delete
# that provides a record of the program's activities.
[26] Fix | Delete
#
[27] Fix | Delete
# == About the Examples
[28] Fix | Delete
#
[29] Fix | Delete
# All examples on this page assume that \Logger has been required:
[30] Fix | Delete
#
[31] Fix | Delete
# require 'logger'
[32] Fix | Delete
#
[33] Fix | Delete
# == Synopsis
[34] Fix | Delete
#
[35] Fix | Delete
# Create a log with Logger.new:
[36] Fix | Delete
#
[37] Fix | Delete
# # Single log file.
[38] Fix | Delete
# logger = Logger.new('t.log')
[39] Fix | Delete
# # Size-based rotated logging: 3 10-megabyte files.
[40] Fix | Delete
# logger = Logger.new('t.log', 3, 10485760)
[41] Fix | Delete
# # Period-based rotated logging: daily (also allowed: 'weekly', 'monthly').
[42] Fix | Delete
# logger = Logger.new('t.log', 'daily')
[43] Fix | Delete
# # Log to an IO stream.
[44] Fix | Delete
# logger = Logger.new($stdout)
[45] Fix | Delete
#
[46] Fix | Delete
# Add entries (level, message) with Logger#add:
[47] Fix | Delete
#
[48] Fix | Delete
# logger.add(Logger::DEBUG, 'Maximal debugging info')
[49] Fix | Delete
# logger.add(Logger::INFO, 'Non-error information')
[50] Fix | Delete
# logger.add(Logger::WARN, 'Non-error warning')
[51] Fix | Delete
# logger.add(Logger::ERROR, 'Non-fatal error')
[52] Fix | Delete
# logger.add(Logger::FATAL, 'Fatal error')
[53] Fix | Delete
# logger.add(Logger::UNKNOWN, 'Most severe')
[54] Fix | Delete
#
[55] Fix | Delete
# Close the log with Logger#close:
[56] Fix | Delete
#
[57] Fix | Delete
# logger.close
[58] Fix | Delete
#
[59] Fix | Delete
# == Entries
[60] Fix | Delete
#
[61] Fix | Delete
# You can add entries with method Logger#add:
[62] Fix | Delete
#
[63] Fix | Delete
# logger.add(Logger::DEBUG, 'Maximal debugging info')
[64] Fix | Delete
# logger.add(Logger::INFO, 'Non-error information')
[65] Fix | Delete
# logger.add(Logger::WARN, 'Non-error warning')
[66] Fix | Delete
# logger.add(Logger::ERROR, 'Non-fatal error')
[67] Fix | Delete
# logger.add(Logger::FATAL, 'Fatal error')
[68] Fix | Delete
# logger.add(Logger::UNKNOWN, 'Most severe')
[69] Fix | Delete
#
[70] Fix | Delete
# These shorthand methods also add entries:
[71] Fix | Delete
#
[72] Fix | Delete
# logger.debug('Maximal debugging info')
[73] Fix | Delete
# logger.info('Non-error information')
[74] Fix | Delete
# logger.warn('Non-error warning')
[75] Fix | Delete
# logger.error('Non-fatal error')
[76] Fix | Delete
# logger.fatal('Fatal error')
[77] Fix | Delete
# logger.unknown('Most severe')
[78] Fix | Delete
#
[79] Fix | Delete
# When you call any of these methods,
[80] Fix | Delete
# the entry may or may not be written to the log,
[81] Fix | Delete
# depending on the entry's severity and on the log level;
[82] Fix | Delete
# see {Log Level}[rdoc-ref:Logger@Log+Level]
[83] Fix | Delete
#
[84] Fix | Delete
# An entry always has:
[85] Fix | Delete
#
[86] Fix | Delete
# - A severity (the required argument to #add).
[87] Fix | Delete
# - An automatically created timestamp.
[88] Fix | Delete
#
[89] Fix | Delete
# And may also have:
[90] Fix | Delete
#
[91] Fix | Delete
# - A message.
[92] Fix | Delete
# - A program name.
[93] Fix | Delete
#
[94] Fix | Delete
# Example:
[95] Fix | Delete
#
[96] Fix | Delete
# logger = Logger.new($stdout)
[97] Fix | Delete
# logger.add(Logger::INFO, 'My message.', 'mung')
[98] Fix | Delete
# # => I, [2022-05-07T17:21:46.536234 #20536] INFO -- mung: My message.
[99] Fix | Delete
#
[100] Fix | Delete
# The default format for an entry is:
[101] Fix | Delete
#
[102] Fix | Delete
# "%s, [%s #%d] %5s -- %s: %s\n"
[103] Fix | Delete
#
[104] Fix | Delete
# where the values to be formatted are:
[105] Fix | Delete
#
[106] Fix | Delete
# - \Severity (one letter).
[107] Fix | Delete
# - Timestamp.
[108] Fix | Delete
# - Process id.
[109] Fix | Delete
# - \Severity (word).
[110] Fix | Delete
# - Program name.
[111] Fix | Delete
# - Message.
[112] Fix | Delete
#
[113] Fix | Delete
# You can use a different entry format by:
[114] Fix | Delete
#
[115] Fix | Delete
# - Setting a custom format proc (affects following entries);
[116] Fix | Delete
# see {formatter=}[Logger.html#attribute-i-formatter].
[117] Fix | Delete
# - Calling any of the methods above with a block
[118] Fix | Delete
# (affects only the one entry).
[119] Fix | Delete
# Doing so can have two benefits:
[120] Fix | Delete
#
[121] Fix | Delete
# - Context: the block can evaluate the entire program context
[122] Fix | Delete
# and create a context-dependent message.
[123] Fix | Delete
# - Performance: the block is not evaluated unless the log level
[124] Fix | Delete
# permits the entry actually to be written:
[125] Fix | Delete
#
[126] Fix | Delete
# logger.error { my_slow_message_generator }
[127] Fix | Delete
#
[128] Fix | Delete
# Contrast this with the string form, where the string is
[129] Fix | Delete
# always evaluated, regardless of the log level:
[130] Fix | Delete
#
[131] Fix | Delete
# logger.error("#{my_slow_message_generator}")
[132] Fix | Delete
#
[133] Fix | Delete
# === \Severity
[134] Fix | Delete
#
[135] Fix | Delete
# The severity of a log entry has two effects:
[136] Fix | Delete
#
[137] Fix | Delete
# - Determines whether the entry is selected for inclusion in the log;
[138] Fix | Delete
# see {Log Level}[rdoc-ref:Logger@Log+Level].
[139] Fix | Delete
# - Indicates to any log reader (whether a person or a program)
[140] Fix | Delete
# the relative importance of the entry.
[141] Fix | Delete
#
[142] Fix | Delete
# === Timestamp
[143] Fix | Delete
#
[144] Fix | Delete
# The timestamp for a log entry is generated automatically
[145] Fix | Delete
# when the entry is created.
[146] Fix | Delete
#
[147] Fix | Delete
# The logged timestamp is formatted by method
[148] Fix | Delete
# {Time#strftime}[rdoc-ref:Time#strftime]
[149] Fix | Delete
# using this format string:
[150] Fix | Delete
#
[151] Fix | Delete
# '%Y-%m-%dT%H:%M:%S.%6N'
[152] Fix | Delete
#
[153] Fix | Delete
# Example:
[154] Fix | Delete
#
[155] Fix | Delete
# logger = Logger.new($stdout)
[156] Fix | Delete
# logger.add(Logger::INFO)
[157] Fix | Delete
# # => I, [2022-05-07T17:04:32.318331 #20536] INFO -- : nil
[158] Fix | Delete
#
[159] Fix | Delete
# You can set a different format using method #datetime_format=.
[160] Fix | Delete
#
[161] Fix | Delete
# === Message
[162] Fix | Delete
#
[163] Fix | Delete
# The message is an optional argument to an entry method:
[164] Fix | Delete
#
[165] Fix | Delete
# logger = Logger.new($stdout)
[166] Fix | Delete
# logger.add(Logger::INFO, 'My message')
[167] Fix | Delete
# # => I, [2022-05-07T18:15:37.647581 #20536] INFO -- : My message
[168] Fix | Delete
#
[169] Fix | Delete
# For the default entry formatter, <tt>Logger::Formatter</tt>,
[170] Fix | Delete
# the message object may be:
[171] Fix | Delete
#
[172] Fix | Delete
# - A string: used as-is.
[173] Fix | Delete
# - An Exception: <tt>message.message</tt> is used.
[174] Fix | Delete
# - Anything else: <tt>message.inspect</tt> is used.
[175] Fix | Delete
#
[176] Fix | Delete
# *Note*: Logger::Formatter does not escape or sanitize
[177] Fix | Delete
# the message passed to it.
[178] Fix | Delete
# Developers should be aware that malicious data (user input)
[179] Fix | Delete
# may be in the message, and should explicitly escape untrusted data.
[180] Fix | Delete
#
[181] Fix | Delete
# You can use a custom formatter to escape message data;
[182] Fix | Delete
# see the example at {formatter=}[Logger.html#attribute-i-formatter].
[183] Fix | Delete
#
[184] Fix | Delete
# === Program Name
[185] Fix | Delete
#
[186] Fix | Delete
# The program name is an optional argument to an entry method:
[187] Fix | Delete
#
[188] Fix | Delete
# logger = Logger.new($stdout)
[189] Fix | Delete
# logger.add(Logger::INFO, 'My message', 'mung')
[190] Fix | Delete
# # => I, [2022-05-07T18:17:38.084716 #20536] INFO -- mung: My message
[191] Fix | Delete
#
[192] Fix | Delete
# The default program name for a new logger may be set in the call to
[193] Fix | Delete
# Logger.new via optional keyword argument +progname+:
[194] Fix | Delete
#
[195] Fix | Delete
# logger = Logger.new('t.log', progname: 'mung')
[196] Fix | Delete
#
[197] Fix | Delete
# The default program name for an existing logger may be set
[198] Fix | Delete
# by a call to method #progname=:
[199] Fix | Delete
#
[200] Fix | Delete
# logger.progname = 'mung'
[201] Fix | Delete
#
[202] Fix | Delete
# The current program name may be retrieved with method
[203] Fix | Delete
# {progname}[Logger.html#attribute-i-progname]:
[204] Fix | Delete
#
[205] Fix | Delete
# logger.progname # => "mung"
[206] Fix | Delete
#
[207] Fix | Delete
# == Log Level
[208] Fix | Delete
#
[209] Fix | Delete
# The log level setting determines whether an entry is actually
[210] Fix | Delete
# written to the log, based on the entry's severity.
[211] Fix | Delete
#
[212] Fix | Delete
# These are the defined severities (least severe to most severe):
[213] Fix | Delete
#
[214] Fix | Delete
# logger = Logger.new($stdout)
[215] Fix | Delete
# logger.add(Logger::DEBUG, 'Maximal debugging info')
[216] Fix | Delete
# # => D, [2022-05-07T17:57:41.776220 #20536] DEBUG -- : Maximal debugging info
[217] Fix | Delete
# logger.add(Logger::INFO, 'Non-error information')
[218] Fix | Delete
# # => I, [2022-05-07T17:59:14.349167 #20536] INFO -- : Non-error information
[219] Fix | Delete
# logger.add(Logger::WARN, 'Non-error warning')
[220] Fix | Delete
# # => W, [2022-05-07T18:00:45.337538 #20536] WARN -- : Non-error warning
[221] Fix | Delete
# logger.add(Logger::ERROR, 'Non-fatal error')
[222] Fix | Delete
# # => E, [2022-05-07T18:02:41.592912 #20536] ERROR -- : Non-fatal error
[223] Fix | Delete
# logger.add(Logger::FATAL, 'Fatal error')
[224] Fix | Delete
# # => F, [2022-05-07T18:05:24.703931 #20536] FATAL -- : Fatal error
[225] Fix | Delete
# logger.add(Logger::UNKNOWN, 'Most severe')
[226] Fix | Delete
# # => A, [2022-05-07T18:07:54.657491 #20536] ANY -- : Most severe
[227] Fix | Delete
#
[228] Fix | Delete
# The default initial level setting is Logger::DEBUG, the lowest level,
[229] Fix | Delete
# which means that all entries are to be written, regardless of severity:
[230] Fix | Delete
#
[231] Fix | Delete
# logger = Logger.new($stdout)
[232] Fix | Delete
# logger.level # => 0
[233] Fix | Delete
# logger.add(0, "My message")
[234] Fix | Delete
# # => D, [2022-05-11T15:10:59.773668 #20536] DEBUG -- : My message
[235] Fix | Delete
#
[236] Fix | Delete
# You can specify a different setting in a new logger
[237] Fix | Delete
# using keyword argument +level+ with an appropriate value:
[238] Fix | Delete
#
[239] Fix | Delete
# logger = Logger.new($stdout, level: Logger::ERROR)
[240] Fix | Delete
# logger = Logger.new($stdout, level: 'error')
[241] Fix | Delete
# logger = Logger.new($stdout, level: :error)
[242] Fix | Delete
# logger.level # => 3
[243] Fix | Delete
#
[244] Fix | Delete
# With this level, entries with severity Logger::ERROR and higher
[245] Fix | Delete
# are written, while those with lower severities are not written:
[246] Fix | Delete
#
[247] Fix | Delete
# logger = Logger.new($stdout, level: Logger::ERROR)
[248] Fix | Delete
# logger.add(3)
[249] Fix | Delete
# # => E, [2022-05-11T15:17:20.933362 #20536] ERROR -- : nil
[250] Fix | Delete
# logger.add(2) # Silent.
[251] Fix | Delete
#
[252] Fix | Delete
# You can set the log level for an existing logger
[253] Fix | Delete
# with method #level=:
[254] Fix | Delete
#
[255] Fix | Delete
# logger.level = Logger::ERROR
[256] Fix | Delete
#
[257] Fix | Delete
# These shorthand methods also set the level:
[258] Fix | Delete
#
[259] Fix | Delete
# logger.debug! # => 0
[260] Fix | Delete
# logger.info! # => 1
[261] Fix | Delete
# logger.warn! # => 2
[262] Fix | Delete
# logger.error! # => 3
[263] Fix | Delete
# logger.fatal! # => 4
[264] Fix | Delete
#
[265] Fix | Delete
# You can retrieve the log level with method
[266] Fix | Delete
# {level}[Logger.html#attribute-i-level]:
[267] Fix | Delete
#
[268] Fix | Delete
# logger.level = Logger::ERROR
[269] Fix | Delete
# logger.level # => 3
[270] Fix | Delete
#
[271] Fix | Delete
# These methods return whether a given
[272] Fix | Delete
# level is to be written:
[273] Fix | Delete
#
[274] Fix | Delete
# logger.level = Logger::ERROR
[275] Fix | Delete
# logger.debug? # => false
[276] Fix | Delete
# logger.info? # => false
[277] Fix | Delete
# logger.warn? # => false
[278] Fix | Delete
# logger.error? # => true
[279] Fix | Delete
# logger.fatal? # => true
[280] Fix | Delete
#
[281] Fix | Delete
# == Log File Rotation
[282] Fix | Delete
#
[283] Fix | Delete
# By default, a log file is a single file that grows indefinitely
[284] Fix | Delete
# (until explicitly closed); there is no file rotation.
[285] Fix | Delete
#
[286] Fix | Delete
# To keep log files to a manageable size,
[287] Fix | Delete
# you can use _log_ _file_ _rotation_, which uses multiple log files:
[288] Fix | Delete
#
[289] Fix | Delete
# - Each log file has entries for a non-overlapping
[290] Fix | Delete
# time interval.
[291] Fix | Delete
# - Only the most recent log file is open and active;
[292] Fix | Delete
# the others are closed and inactive.
[293] Fix | Delete
#
[294] Fix | Delete
# === Size-Based Rotation
[295] Fix | Delete
#
[296] Fix | Delete
# For size-based log file rotation, call Logger.new with:
[297] Fix | Delete
#
[298] Fix | Delete
# - Argument +logdev+ as a file path.
[299] Fix | Delete
# - Argument +shift_age+ with a positive integer:
[300] Fix | Delete
# the number of log files to be in the rotation.
[301] Fix | Delete
# - Argument +shift_size+ as a positive integer:
[302] Fix | Delete
# the maximum size (in bytes) of each log file;
[303] Fix | Delete
# defaults to 1048576 (1 megabyte).
[304] Fix | Delete
#
[305] Fix | Delete
# Examples:
[306] Fix | Delete
#
[307] Fix | Delete
# logger = Logger.new('t.log', 3) # Three 1-megabyte files.
[308] Fix | Delete
# logger = Logger.new('t.log', 5, 10485760) # Five 10-megabyte files.
[309] Fix | Delete
#
[310] Fix | Delete
# For these examples, suppose:
[311] Fix | Delete
#
[312] Fix | Delete
# logger = Logger.new('t.log', 3)
[313] Fix | Delete
#
[314] Fix | Delete
# Logging begins in the new log file, +t.log+;
[315] Fix | Delete
# the log file is "full" and ready for rotation
[316] Fix | Delete
# when a new entry would cause its size to exceed +shift_size+.
[317] Fix | Delete
#
[318] Fix | Delete
# The first time +t.log+ is full:
[319] Fix | Delete
#
[320] Fix | Delete
# - +t.log+ is closed and renamed to +t.log.0+.
[321] Fix | Delete
# - A new file +t.log+ is opened.
[322] Fix | Delete
#
[323] Fix | Delete
# The second time +t.log+ is full:
[324] Fix | Delete
#
[325] Fix | Delete
# - +t.log.0 is renamed as +t.log.1+.
[326] Fix | Delete
# - +t.log+ is closed and renamed to +t.log.0+.
[327] Fix | Delete
# - A new file +t.log+ is opened.
[328] Fix | Delete
#
[329] Fix | Delete
# Each subsequent time that +t.log+ is full,
[330] Fix | Delete
# the log files are rotated:
[331] Fix | Delete
#
[332] Fix | Delete
# - +t.log.1+ is removed.
[333] Fix | Delete
# - +t.log.0 is renamed as +t.log.1+.
[334] Fix | Delete
# - +t.log+ is closed and renamed to +t.log.0+.
[335] Fix | Delete
# - A new file +t.log+ is opened.
[336] Fix | Delete
#
[337] Fix | Delete
# === Periodic Rotation
[338] Fix | Delete
#
[339] Fix | Delete
# For periodic rotation, call Logger.new with:
[340] Fix | Delete
#
[341] Fix | Delete
# - Argument +logdev+ as a file path.
[342] Fix | Delete
# - Argument +shift_age+ as a string period indicator.
[343] Fix | Delete
#
[344] Fix | Delete
# Examples:
[345] Fix | Delete
#
[346] Fix | Delete
# logger = Logger.new('t.log', 'daily') # Rotate log files daily.
[347] Fix | Delete
# logger = Logger.new('t.log', 'weekly') # Rotate log files weekly.
[348] Fix | Delete
# logger = Logger.new('t.log', 'monthly') # Rotate log files monthly.
[349] Fix | Delete
#
[350] Fix | Delete
# Example:
[351] Fix | Delete
#
[352] Fix | Delete
# logger = Logger.new('t.log', 'daily')
[353] Fix | Delete
#
[354] Fix | Delete
# When the given period expires:
[355] Fix | Delete
#
[356] Fix | Delete
# - The base log file, +t.log+ is closed and renamed
[357] Fix | Delete
# with a date-based suffix such as +t.log.20220509+.
[358] Fix | Delete
# - A new log file +t.log+ is opened.
[359] Fix | Delete
# - Nothing is removed.
[360] Fix | Delete
#
[361] Fix | Delete
# The default format for the suffix is <tt>'%Y%m%d'</tt>,
[362] Fix | Delete
# which produces a suffix similar to the one above.
[363] Fix | Delete
# You can set a different format using create-time option
[364] Fix | Delete
# +shift_period_suffix+;
[365] Fix | Delete
# see details and suggestions at
[366] Fix | Delete
# {Time#strftime}[rdoc-ref:Time#strftime].
[367] Fix | Delete
#
[368] Fix | Delete
class Logger
[369] Fix | Delete
_, name, rev = %w$Id$
[370] Fix | Delete
if name
[371] Fix | Delete
name = name.chomp(",v")
[372] Fix | Delete
else
[373] Fix | Delete
name = File.basename(__FILE__)
[374] Fix | Delete
end
[375] Fix | Delete
rev ||= "v#{VERSION}"
[376] Fix | Delete
ProgName = "#{name}/#{rev}"
[377] Fix | Delete
[378] Fix | Delete
include Severity
[379] Fix | Delete
[380] Fix | Delete
# Logging severity threshold (e.g. <tt>Logger::INFO</tt>).
[381] Fix | Delete
attr_reader :level
[382] Fix | Delete
[383] Fix | Delete
# Sets the log level; returns +severity+.
[384] Fix | Delete
# See {Log Level}[rdoc-ref:Logger@Log+Level].
[385] Fix | Delete
#
[386] Fix | Delete
# Argument +severity+ may be an integer, a string, or a symbol:
[387] Fix | Delete
#
[388] Fix | Delete
# logger.level = Logger::ERROR # => 3
[389] Fix | Delete
# logger.level = 3 # => 3
[390] Fix | Delete
# logger.level = 'error' # => "error"
[391] Fix | Delete
# logger.level = :error # => :error
[392] Fix | Delete
#
[393] Fix | Delete
# Logger#sev_threshold= is an alias for Logger#level=.
[394] Fix | Delete
#
[395] Fix | Delete
def level=(severity)
[396] Fix | Delete
if severity.is_a?(Integer)
[397] Fix | Delete
@level = severity
[398] Fix | Delete
else
[399] Fix | Delete
case severity.to_s.downcase
[400] Fix | Delete
when 'debug'
[401] Fix | Delete
@level = DEBUG
[402] Fix | Delete
when 'info'
[403] Fix | Delete
@level = INFO
[404] Fix | Delete
when 'warn'
[405] Fix | Delete
@level = WARN
[406] Fix | Delete
when 'error'
[407] Fix | Delete
@level = ERROR
[408] Fix | Delete
when 'fatal'
[409] Fix | Delete
@level = FATAL
[410] Fix | Delete
when 'unknown'
[411] Fix | Delete
@level = UNKNOWN
[412] Fix | Delete
else
[413] Fix | Delete
raise ArgumentError, "invalid log level: #{severity}"
[414] Fix | Delete
end
[415] Fix | Delete
end
[416] Fix | Delete
end
[417] Fix | Delete
[418] Fix | Delete
# Program name to include in log messages.
[419] Fix | Delete
attr_accessor :progname
[420] Fix | Delete
[421] Fix | Delete
# Sets the date-time format.
[422] Fix | Delete
#
[423] Fix | Delete
# Argument +datetime_format+ should be either of these:
[424] Fix | Delete
#
[425] Fix | Delete
# - A string suitable for use as a format for method
[426] Fix | Delete
# {Time#strftime}[rdoc-ref:Time#strftime].
[427] Fix | Delete
# - +nil+: the logger uses <tt>'%Y-%m-%dT%H:%M:%S.%6N'</tt>.
[428] Fix | Delete
#
[429] Fix | Delete
def datetime_format=(datetime_format)
[430] Fix | Delete
@default_formatter.datetime_format = datetime_format
[431] Fix | Delete
end
[432] Fix | Delete
[433] Fix | Delete
# Returns the date-time format; see #datetime_format=.
[434] Fix | Delete
#
[435] Fix | Delete
def datetime_format
[436] Fix | Delete
@default_formatter.datetime_format
[437] Fix | Delete
end
[438] Fix | Delete
[439] Fix | Delete
# Sets or retrieves the logger entry formatter proc.
[440] Fix | Delete
#
[441] Fix | Delete
# When +formatter+ is +nil+, the logger uses Logger::Formatter.
[442] Fix | Delete
#
[443] Fix | Delete
# When +formatter+ is a proc, a new entry is formatted by the proc,
[444] Fix | Delete
# which is called with four arguments:
[445] Fix | Delete
#
[446] Fix | Delete
# - +severity+: The severity of the entry.
[447] Fix | Delete
# - +time+: A Time object representing the entry's timestamp.
[448] Fix | Delete
# - +progname+: The program name for the entry.
[449] Fix | Delete
# - +msg+: The message for the entry (string or string-convertible object).
[450] Fix | Delete
#
[451] Fix | Delete
# The proc should return a string containing the formatted entry.
[452] Fix | Delete
#
[453] Fix | Delete
# This custom formatter uses
[454] Fix | Delete
# {String#dump}[rdoc-ref:String#dump]
[455] Fix | Delete
# to escape the message string:
[456] Fix | Delete
#
[457] Fix | Delete
# logger = Logger.new($stdout, progname: 'mung')
[458] Fix | Delete
# original_formatter = logger.formatter || Logger::Formatter.new
[459] Fix | Delete
# logger.formatter = proc { |severity, time, progname, msg|
[460] Fix | Delete
# original_formatter.call(severity, time, progname, msg.dump)
[461] Fix | Delete
# }
[462] Fix | Delete
# logger.add(Logger::INFO, "hello \n ''")
[463] Fix | Delete
# logger.add(Logger::INFO, "\f\x00\xff\\\"")
[464] Fix | Delete
#
[465] Fix | Delete
# Output:
[466] Fix | Delete
#
[467] Fix | Delete
# I, [2022-05-13T13:16:29.637488 #8492] INFO -- mung: "hello \n ''"
[468] Fix | Delete
# I, [2022-05-13T13:16:29.637610 #8492] INFO -- mung: "\f\x00\xFF\\\""
[469] Fix | Delete
#
[470] Fix | Delete
attr_accessor :formatter
[471] Fix | Delete
[472] Fix | Delete
alias sev_threshold level
[473] Fix | Delete
alias sev_threshold= level=
[474] Fix | Delete
[475] Fix | Delete
# Returns +true+ if the log level allows entries with severity
[476] Fix | Delete
# Logger::DEBUG to be written, +false+ otherwise.
[477] Fix | Delete
# See {Log Level}[rdoc-ref:Logger@Log+Level].
[478] Fix | Delete
#
[479] Fix | Delete
def debug?; level <= DEBUG; end
[480] Fix | Delete
[481] Fix | Delete
# Sets the log level to Logger::DEBUG.
[482] Fix | Delete
# See {Log Level}[rdoc-ref:Logger@Log+Level].
[483] Fix | Delete
#
[484] Fix | Delete
def debug!; self.level = DEBUG; end
[485] Fix | Delete
[486] Fix | Delete
# Returns +true+ if the log level allows entries with severity
[487] Fix | Delete
# Logger::INFO to be written, +false+ otherwise.
[488] Fix | Delete
# See {Log Level}[rdoc-ref:Logger@Log+Level].
[489] Fix | Delete
#
[490] Fix | Delete
def info?; level <= INFO; end
[491] Fix | Delete
[492] Fix | Delete
# Sets the log level to Logger::INFO.
[493] Fix | Delete
# See {Log Level}[rdoc-ref:Logger@Log+Level].
[494] Fix | Delete
#
[495] Fix | Delete
def info!; self.level = INFO; end
[496] Fix | Delete
[497] Fix | Delete
# Returns +true+ if the log level allows entries with severity
[498] Fix | Delete
# Logger::WARN to be written, +false+ otherwise.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function