-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlog_event.rb
More file actions
31 lines (27 loc) · 757 Bytes
/
log_event.rb
File metadata and controls
31 lines (27 loc) · 757 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
# frozen_string_literal: true
module Html2rss
module Web
##
# Shared structured log emitter for request-scoped application events.
module LogEvent
class << self
# @param payload [Hash{Symbol=>Object}]
# @param level [Symbol]
# @return [void]
def emit(payload:, level: :info)
logger.public_send(level, build_payload(payload).to_json)
end
private
# @return [Logger]
def logger
AppLogger.logger
end
# @param payload [Hash{Symbol=>Object}]
# @return [Hash{Symbol=>Object}]
def build_payload(payload)
RequestContext.current_h.merge(LogSanitizer.sanitize_details(payload))
end
end
end
end
end