Class: AuditLoggable::Logger::JSONFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- AuditLoggable::Logger::JSONFormatter
- Defined in:
- lib/audit_loggable/logger.rb
Instance Attribute Summary collapse
-
#timezone ⇒ Object
readonly
Returns the value of attribute timezone.
Instance Method Summary collapse
- #call(_severity, time, _progname, message) ⇒ Object
-
#initialize(timezone:) ⇒ JSONFormatter
constructor
A new instance of JSONFormatter.
Constructor Details
#initialize(timezone:) ⇒ JSONFormatter
Returns a new instance of JSONFormatter.
10 11 12 13 14 |
# File 'lib/audit_loggable/logger.rb', line 10 def initialize(timezone:) raise ArgumentError unless %i[utc local].include? timezone @timezone = timezone end |
Instance Attribute Details
#timezone ⇒ Object (readonly)
Returns the value of attribute timezone.
8 9 10 |
# File 'lib/audit_loggable/logger.rb', line 8 def timezone @timezone end |
Instance Method Details
#call(_severity, time, _progname, message) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/audit_loggable/logger.rb', line 16 def call(_severity, time, _progname, ) = case timezone when :utc then time.getutc when :local then time.getlocal end h = { timestamp: , record: } "#{h.to_json}\n" end |