Class: AllStak::Modules::Logs
- Inherits:
-
Object
- Object
- AllStak::Modules::Logs
- Defined in:
- lib/allstak/modules/logs.rb
Overview
Buffered structured-log ingestion. Each log is sent as its own POST.
Constant Summary collapse
- PATH =
"/ingest/v1/logs".freeze
- VALID_LEVELS =
%w[debug info warn error fatal].freeze
Instance Method Summary collapse
- #debug(msg, **kw) ⇒ Object
- #error(msg, **kw) ⇒ Object
- #fatal(msg, **kw) ⇒ Object
- #flush ⇒ Object
- #info(msg, **kw) ⇒ Object
-
#initialize(transport, config, logger) ⇒ Logs
constructor
A new instance of Logs.
- #log(level, message, service: nil, trace_id: nil, span_id: nil, request_id: nil, user_id: nil, error_id: nil, metadata: nil) ⇒ Object
- #shutdown ⇒ Object
- #warn(msg, **kw) ⇒ Object
Constructor Details
#initialize(transport, config, logger) ⇒ Logs
Returns a new instance of Logs.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/allstak/modules/logs.rb', line 8 def initialize(transport, config, logger) @transport = transport @config = config @logger = logger @buffer = Transport::FlushBuffer.new( name: "logs", max_size: config.buffer_size, interval_ms: config.flush_interval_ms, flush_proc: method(:flush_batch), logger: logger ) end |
Instance Method Details
#debug(msg, **kw) ⇒ Object
42 |
# File 'lib/allstak/modules/logs.rb', line 42 def debug(msg, **kw); log("debug", msg, **kw); end |
#error(msg, **kw) ⇒ Object
45 |
# File 'lib/allstak/modules/logs.rb', line 45 def error(msg, **kw); log("error", msg, **kw); end |
#fatal(msg, **kw) ⇒ Object
46 |
# File 'lib/allstak/modules/logs.rb', line 46 def fatal(msg, **kw); log("fatal", msg, **kw); end |
#flush ⇒ Object
48 49 50 |
# File 'lib/allstak/modules/logs.rb', line 48 def flush @buffer.flush end |
#info(msg, **kw) ⇒ Object
43 |
# File 'lib/allstak/modules/logs.rb', line 43 def info(msg, **kw); log("info", msg, **kw); end |
#log(level, message, service: nil, trace_id: nil, span_id: nil, request_id: nil, user_id: nil, error_id: nil, metadata: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/allstak/modules/logs.rb', line 21 def log(level, , service: nil, trace_id: nil, span_id: nil, request_id: nil, user_id: nil, error_id: nil, metadata: nil) return if @transport.disabled? level = normalize_level(level) payload = { level: level, message: .to_s, service: service || @config.service_name, environment: @config.environment, release: @config.respond_to?(:release) ? @config.release : nil, traceId: trace_id, spanId: span_id, requestId: request_id, userId: user_id, errorId: error_id, metadata: }.compact @buffer.push(payload) end |
#shutdown ⇒ Object
52 53 54 |
# File 'lib/allstak/modules/logs.rb', line 52 def shutdown @buffer.shutdown end |
#warn(msg, **kw) ⇒ Object
44 |
# File 'lib/allstak/modules/logs.rb', line 44 def warn(msg, **kw); log("warn", msg, **kw); end |