Skip to content

class Log::Metadata
inherits Reference

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".

Included modules

Enumerable

Class methods

.build(value : NamedTuple | Hash)

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

View source

.build(value : Metadata)

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

View source

.empty : Log::Metadata

Returns an empty Log::Metadata.

Note

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

View source

.new(parent : Metadata? = nil, entries : NamedTuple | Hash = NamedTuple.new)

View source

Methods

#==(other : Metadata)

View source

#[](key : Symbol) : Value

View source

#[]?(key : Symbol) : Value?

View source

#each(& : Tuple(Symbol, Value) -> )

Must yield this collection's elements to the block.

View source

#empty?

Returns true if self is empty, false otherwise.

([] of Int32).empty? # => true
([1]).empty?         # => false
View 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.

View source

#fetch

View source

#hash(hasher)

View 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>
View source