Class: Snails::Logger::Formatter

Inherits:
Object
  • Object
show all
Defined in:
runtime/snails/logger/formatter.rbs,
runtime/snails/logger/formatter.rb

Constant Summary collapse

FRACTION_ZEROS =

Zero padding for the fractional second, indexed by digit count.

[ "000000", "00000", "0000", "000", "00", "0", "" ].freeze

Class Method Summary collapse

  • .format_time(time) ⇒ String

    the timestamp rule both local log lines share: the app's zone wall clock with microseconds, plus the zone offset (Z for UTC), so a line read in another zone still names the same instant.

  • .fraction_text(usec) ⇒ Object

    the six-digit fractional second %6N renders, from the microsecond the Time already holds: usec.to_s is far cheaper than the strftime pass that would produce the same digits.

Instance Method Summary collapse

Class Method Details

.format_time(time) ⇒ String

the timestamp rule both local log lines share: the app's zone wall clock with microseconds, plus the zone offset (Z for UTC), so a line read in another zone still names the same instant. The record line calls this too, so an app string call and a framework event spell an instant alike.

The calendar fields hold for a whole second, and strftime on a local time serializes across request threads in this runtime (measured: its call rate stays flat from one thread to 32), so the date, clock, and zone text are rendered once per second and reused. Only the fractional second is per call.

Examples:

Snails::Logger::Formatter.format_time(Time.at(0).utc) # => "1970-01-01T00:00:00.000000Z" (UTC process)

Parameters:

  • time (Time) —

    the instant to render

Returns:

  • (String) —

    the local timestamp with its offset, …Z for UTC



38
# File 'runtime/snails/logger/formatter.rb', line 38

def self.format_time: (Time time) -> String

.fraction_text(usec) ⇒ Object

the six-digit fractional second %6N renders, from the microsecond the Time already holds: usec.to_s is far cheaper than the strftime pass that would produce the same digits.



57
# File 'runtime/snails/logger/formatter.rb', line 57

def self.fraction_text: (Integer usec) -> String

Instance Method Details

#call(severity, time, progname, message) ⇒ String

Parameters:

Returns:



7
# File 'runtime/snails/logger/formatter.rbs', line 7

def call: (untyped severity, ::Time time, untyped progname, untyped message) -> String