google-logging-utils - Class Google::Logging::Message (v0.2.0)

Inherits

  • Object

Methods

.from

defself.from(input)->Message

Create a log message from an input object, which can be any of:

  • An existing Message object.
  • A Hash. Symbol keys are used as keyword arguments to the#initialize constructor. String keys are treated as fieldsin the JSON payload.
  • Any other object is converted to a string withto_s and used as asimple text payload.
Parameter
  • input (Object) — A log message input object.
Returns

#fields

deffields()->Hash{String=>Object},nil
Returns
  • (Hash{String=>Object}, nil) — The log message as a set ofkey-value pairs, or nil if not present.

#full_message

deffull_message()->String
Aliases
Returns
  • (String) — A full string representation of the message and fieldsas rendered in the standard logger formatter.

#initialize

definitialize(message:nil,fields:nil,timestamp:nil,source_location:nil,insert_id:nil,trace:nil,span_id:nil,trace_sampled:nil,labels:nil)->Message

Low-level constructor for a logging message.All arguments are optional, with the exception that at least one of:message and:fields must be provided.

Parameters
  • message (String)(defaults to: nil) — The main log message as a string.
  • fields (Hash{String=>Object})(defaults to: nil) — The log message as a set ofkey-value pairs representing a JSON object.
  • timestamp (Time, Numeric, :now)(defaults to: nil) — The timestamp for the log entry.Can be provided as a Time object, a Numeric indicating the secondssince epoch, or:now to use the current time. Optional.
  • source_location (SourceLocation, Hash, :caller, nil)(defaults to: nil) — The sourcelocation for the log entry. Can be provided as aSourceLocationobject, a Hash containing exactly the keys:file,:line, and:function, or:caller to use the location of the caller.Optional.
  • insert_id (String)(defaults to: nil) — A unique ID for this log entry that could beused on the backend to dedup messages. Optional.
  • trace (String)(defaults to: nil) — A Google Cloud Trace resource name. Optional.
  • span_id (String)(defaults to: nil) — The trace span containing this entry. Optional.
  • trace_sampled (boolean)(defaults to: nil) — Whether this trace is sampled. Optional.
  • labels (Hash{String=>String})(defaults to: nil) — Optional metadata.
Returns
  • (Message) — a new instance of Message

#insert_id

definsert_id()->String,nil
Returns
  • (String, nil) — The unique ID for this log entry that could beused on the backend to dedup messages, or nil if not present.

#inspect

definspect()->String
Alias Of:#full_message
Returns
  • (String) — A full string representation of the message and fieldsas rendered in the standard logger formatter.

#labels

deflabels()->Hash{String=>String},nil
Returns
  • (Hash{String=>String}, nil) — Metadata, or nil if not present.

#message

defmessage()->String
Aliases
Returns
  • (String) — The message as a string. This is always present as anonempty string, and can be reliably used as the "display" of thislog entry in a list of entries.

#source_location

defsource_location()->SourceLocation,nil
Returns
  • (SourceLocation, nil) — The source location for the log entry, ornil if not present.

#span_id

defspan_id()->String,nil
Returns
  • (String, nil) — The trace span containing this entry, or nil ifnot present.

#timestamp

deftimestamp()->Time,nil
Returns
  • (Time, nil) — The timestamp for the log entry, or nil if notpresent.

#to_h

defto_h()->Hash
Returns
  • (Hash) — A hash of kwargs that can be passed to the constructorto clone this message.

#to_s

defto_s()->String
Alias Of:#message
Returns
  • (String) — The message as a string. This is always present as anonempty string, and can be reliably used as the "display" of thislog entry in a list of entries.

#trace

deftrace()->String,nil
Returns
  • (String, nil) — The Google Cloud Trace resource name, or nil ifnot present.

#trace_sampled

deftrace_sampled()->true,false,nil
Returns
  • (true, false, nil) — Whether this trace is sampled, or nil if notpresent or known.

#trace_sampled?

deftrace_sampled?()->true,false,nil
Returns
  • (true, false, nil) — Whether this trace is sampled, or nil if notpresent or known.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.