Class: CloseYourIt::LogDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/closeyourit/log_device.rb

Overview

Oggetto Logger-compatibile esposto come CloseYourIt.logger: ogni chiamata inoltra a CloseYourIt.emit_log (→ ingest /logs). Usabile come logger esplicito dell'app, anche con attributes:

CloseYourIt.logger.warn("disco quasi pieno", disk: "sda1")

warn mappa sul livello warning (enum backend); supporta block e ::Logger#add per drop-in.

La sorgente del log (campo logger del payload) si imposta SOLO via .named (child logger, parità dart/js) o via costruttore — MAI da una keyword dei metodi: così una chiave logger passata a un metodo resta un attributo dati e non viene hijackata come sorgente (CYRB-8). payments = CloseYourIt.logger.named("payments") # child con sorgente "payments" payments.warn("retry", attempt: 3) # logger=payments, attributes=attempt:3 CloseYourIt.logger.warn("disco pieno", logger: "/dev/sda1") # attributes=logger:"/dev/sda1"

Constant Summary collapse

SEVERITY_LEVELS =

Severità numeriche ::Logger → livelli CloseYourIt (UNKNOWN→fatal).

{ 0 => "debug", 1 => "info", 2 => "warning", 3 => "error", 4 => "fatal", 5 => "fatal" }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(source = nil) ⇒ LogDevice

source = nome della sorgente del log (campo logger del payload). Preferire .named in app.



20
21
22
# File 'lib/closeyourit/log_device.rb', line 20

def initialize(source = nil)
  @source = normalize_source(source)
end

Instance Method Details

#<<(message) ⇒ Object



37
38
39
40
# File 'lib/closeyourit/log_device.rb', line 37

def <<(message)
  write("info", message, {})
  message
end

#add(severity, message = nil, progname = nil, &block) ⇒ Object Also known as: log

Compat con ::Logger#add(severity, message = nil, progname = nil).



43
44
45
# File 'lib/closeyourit/log_device.rb', line 43

def add(severity, message = nil, progname = nil, &block)
  write(SEVERITY_LEVELS.fetch(severity.to_i, "info"), message || progname, {}, &block)
end

#debug(message = nil, **attributes, &block) ⇒ Object



31
# File 'lib/closeyourit/log_device.rb', line 31

def debug(message = nil, **attributes, &block) = write("debug", message, attributes, &block)

#error(message = nil, **attributes, &block) ⇒ Object



34
# File 'lib/closeyourit/log_device.rb', line 34

def error(message = nil, **attributes, &block) = write("error", message, attributes, &block)

#fatal(message = nil, **attributes, &block) ⇒ Object



35
# File 'lib/closeyourit/log_device.rb', line 35

def fatal(message = nil, **attributes, &block) = write("fatal", message, attributes, &block)

#info(message = nil, **attributes, &block) ⇒ Object



32
# File 'lib/closeyourit/log_device.rb', line 32

def info(message = nil, **attributes, &block)  = write("info", message, attributes, &block)

#named(source) ⇒ Object

Child logger con sorgente esplicita (parità dart/js). Ritorna un NUOVO LogDevice: il logger su cui è chiamato resta invariato (immutabile), come i child logger cross-SDK. CloseYourIt.logger.named("payments").info("retry", attempt: 3)



27
28
29
# File 'lib/closeyourit/log_device.rb', line 27

def named(source)
  self.class.new(source)
end

#warn(message = nil, **attributes, &block) ⇒ Object



33
# File 'lib/closeyourit/log_device.rb', line 33

def warn(message = nil, **attributes, &block)  = write("warning", message, attributes, &block)