-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.rb
More file actions
38 lines (30 loc) · 833 Bytes
/
logging.rb
File metadata and controls
38 lines (30 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
if defined?(Rails)
require 'berkeley_library/logging/railtie'
else
require 'berkeley_library/logging/configurator'
end
module BerkeleyLibrary
# Include this module to get access to a shared global logger.
module Logging
def logger
Logging.logger
end
def logger=(v)
Logging.logger = v
end
class << self
def logger
@logger ||= BerkeleyLibrary::Logging::Loggers.default_logger
end
def logger=(v)
@logger = (ensure_logger(v) unless v.nil?)
end
LOG_METHODS = %i[debug info warn error].freeze
private
def ensure_logger(v)
return v if (missing = LOG_METHODS.reject { |m| v.respond_to?(m) }).empty?
raise ArgumentError, "Not a logger: #{v.inspect} does not respond to #{missing.join(', ')}"
end
end
end
end