2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-10 09:34:50 +08:00
|
|
|
class FakeLogger
|
2024-06-20 16:33:01 +08:00
|
|
|
attr_reader :debugs, :infos, :warnings, :errors, :fatals, :severities
|
2021-03-15 12:36:10 +08:00
|
|
|
attr_accessor :level
|
2018-10-10 09:34:50 +08:00
|
|
|
|
|
|
|
def initialize
|
2023-12-06 20:18:34 +08:00
|
|
|
@debugs = []
|
2018-10-23 01:22:23 +08:00
|
|
|
@infos = []
|
2022-05-05 09:50:43 +08:00
|
|
|
@warnings = []
|
|
|
|
@errors = []
|
2019-02-14 14:58:16 +08:00
|
|
|
@fatals = []
|
2022-10-13 02:25:49 +08:00
|
|
|
@level = Logger::DEBUG
|
2024-06-20 16:33:01 +08:00
|
|
|
@severities = { 0 => :debugs, 1 => :infos, 2 => :warnings, 3 => :errors, 4 => :fatals }
|
2018-10-23 01:22:23 +08:00
|
|
|
end
|
|
|
|
|
2024-06-20 16:33:01 +08:00
|
|
|
def debug(message = nil)
|
2023-12-06 20:18:34 +08:00
|
|
|
@debugs << message
|
2022-05-05 09:50:43 +08:00
|
|
|
end
|
|
|
|
|
2022-10-12 22:06:00 +08:00
|
|
|
def debug?
|
|
|
|
@level <= Logger::DEBUG
|
|
|
|
end
|
|
|
|
|
2018-10-23 01:22:23 +08:00
|
|
|
def info(message = nil)
|
|
|
|
@infos << message
|
2018-10-10 09:34:50 +08:00
|
|
|
end
|
|
|
|
|
2022-10-12 22:06:00 +08:00
|
|
|
def info?
|
|
|
|
@level <= Logger::INFO
|
|
|
|
end
|
|
|
|
|
2024-06-20 16:33:01 +08:00
|
|
|
def warn(message = nil)
|
2018-10-10 09:34:50 +08:00
|
|
|
@warnings << message
|
|
|
|
end
|
|
|
|
|
2022-10-12 22:06:00 +08:00
|
|
|
def warn?
|
|
|
|
@level <= Logger::WARN
|
|
|
|
end
|
|
|
|
|
2024-06-20 16:33:01 +08:00
|
|
|
def error(message = nil)
|
2018-10-10 09:34:50 +08:00
|
|
|
@errors << message
|
|
|
|
end
|
2019-02-14 14:58:16 +08:00
|
|
|
|
2022-10-12 22:06:00 +08:00
|
|
|
def error?
|
|
|
|
@level <= Logger::ERROR
|
|
|
|
end
|
|
|
|
|
2024-06-20 16:33:01 +08:00
|
|
|
def fatal(message = nil)
|
2019-02-14 14:58:16 +08:00
|
|
|
@fatals << message
|
|
|
|
end
|
|
|
|
|
2022-10-12 22:06:00 +08:00
|
|
|
def fatal?
|
|
|
|
@level <= Logger::FATAL
|
|
|
|
end
|
|
|
|
|
2019-02-14 14:58:16 +08:00
|
|
|
def formatter
|
|
|
|
end
|
2024-06-20 16:33:01 +08:00
|
|
|
|
|
|
|
def add(severity, message = nil, progname = nil)
|
|
|
|
public_send(severities[severity]) << message
|
|
|
|
end
|
|
|
|
|
|
|
|
def broadcasts
|
|
|
|
[self]
|
|
|
|
end
|
2018-10-10 09:34:50 +08:00
|
|
|
end
|