class

Log::Metadata

Inherits Enumerable / Reference / Object

Immutable structured metadata information for logging.

See Log.context, Log.context=, Log::Context#clear, Log::Context#set, Log.with_context, and Log::Emitter.

NOTE: If you'd like to format the context as JSON, remember to require "log/json".

Constructors

build(value : NamedTuple | Hash) : self

Returns a Metadata with the information of the argument. Used to handle Log::Context#set and Log#Emitter.emit overloads.

Source
build(value : Metadata) : Metadata

Returns a Metadata with the information of the argument. Used to handle Log::Context#set and Log#Emitter.emit overloads.

Source
new(parent : Metadata | Nil = nil, entries : NamedTuple | Hash = NamedTuple.new) : self
Source

Class methods

empty

Returns an empty Log::Metadata.

NOTE: Since Log::Metadata is immutable, it's safe to share this instance.

Source

Instance methods

==(other : Metadata) : Bool
Source
==(other)

Returns false (other can only be a Value here).

Source
[](key : Symbol) : Value
Source
[]?(key : Symbol) : Value | Nil
Source
dup

Returns a shallow copy of this object.

This allocates a new object and copies the contents of self into it.

Source
each

Must yield this collection's elements to the block.

Source
empty?

Returns true if self does not contain any element.

([] of Int32).empty? # => true
([1]).empty?         # => false
[nil, false].empty?  # => false
  • #present? returns the inverse.
Source
extend(other : NamedTuple | Hash) : Metadata

Returns a Log::Metadata with all the entries of self and other. If a key is defined in both, the values in other are used.

Source
fetch(key, &)
Source
hash(hasher)

See Object#hash(hasher)

Source
to_json(builder : JSON::Builder) : Nil

Returns Log::Metadata as JSON value.

NOTE: require "log/json" is required to opt-in to this feature.

log_entry.context.to_json # => "{\"user_id\":1}"
Source
to_s(io : IO) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Source

Nested types