Module: Waylon::Logger
- Defined in:
- lib/waylon/logger.rb
Overview
A simple way to abstract logging
Class Method Summary collapse
- .json_logger ⇒ Object
-
.level ⇒ String
The log level as defined in the global Config singleton.
-
.log(message, level = :info) ⇒ Object
Abstraction for sending logs to the logger at some level.
-
.logger ⇒ Logger
Provides an easy way to access the underlying logger.
- .logger=(logger) ⇒ Object
Class Method Details
.json_logger ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/waylon/logger.rb', line 30 def self.json_logger a_logger = ::Logger.new($stderr) a_logger.level = level a_logger.progname = "Waylon" a_logger.formatter = proc do |severity, datetime, progname, msg| json_data = JSON.dump( ts: datetime, severity: severity.ljust(5).to_s, progname:, pid: Process.pid, message: msg, v: Waylon::Core::VERSION ) "#{json_data}\n" end a_logger end |
.level ⇒ String
The log level as defined in the global Config singleton
8 9 10 |
# File 'lib/waylon/logger.rb', line 8 def self.level Config.instance["global.log.level"] || "info" end |
.log(message, level = :info) ⇒ Object
Abstraction for sending logs to the logger at some level
15 16 17 |
# File 'lib/waylon/logger.rb', line 15 def self.log(, level = :info) logger.send(level, ) end |
.logger ⇒ Logger
Provides an easy way to access the underlying logger
21 22 23 |
# File 'lib/waylon/logger.rb', line 21 def self.logger @logger ||= json_logger end |
.logger=(logger) ⇒ Object
26 27 28 |
# File 'lib/waylon/logger.rb', line 26 def self.logger=(logger) @logger = logger end |