google-logging-utils - Class Google::Logging::Message (v0.2.0) Stay organized with collections Save and categorize content based on your preferences.
Reference documentation and code samples for the google-logging-utils class Google::Logging::Message.
A log message that can be formatted either as a normal text log entry oras a structured log entry suitable for Google Cloud Logging.
A log message has a "body" which consists of either a string message, aJSON object (i.e. a Hash whose values are typically strings or numbersbut could be nested arrays and hashes), or both. It also includes severaladditional optional fields used by the Google Cloud Logging backend.
Most log formatters will render the message body as a string and ignorethe other attributes. TheStructuredFormatter, however, will format thefull message data in the JSON format understood by the Google loggingagent.
Inherits
- Object
Methods
.from
defself.from(input)->MessageCreate 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 with
to_sand used as asimple text payload.
- input (Object) — A log message input object.
- (Message)
#fields
deffields()->Hash{String=>Object},nil- (Hash{String=>Object}, nil) — The log message as a set ofkey-value pairs, or nil if not present.
#full_message
deffull_message()->String- (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)->MessageLow-level constructor for a logging message.All arguments are optional, with the exception that at least one of:message and:fields must be provided.
- 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
:nowto 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:callerto 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.
- (Message) — a new instance of Message
#insert_id
definsert_id()->String,nil- (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- (String) — A full string representation of the message and fieldsas rendered in the standard logger formatter.
#labels
deflabels()->Hash{String=>String},nil- (Hash{String=>String}, nil) — Metadata, or nil if not present.
#message
defmessage()->String- (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- (SourceLocation, nil) — The source location for the log entry, ornil if not present.
#span_id
defspan_id()->String,nil- (String, nil) — The trace span containing this entry, or nil ifnot present.
#timestamp
deftimestamp()->Time,nil- (Time, nil) — The timestamp for the log entry, or nil if notpresent.
#to_h
defto_h()->Hash- (Hash) — A hash of kwargs that can be passed to the constructorto clone this message.
#to_s
defto_s()->String- (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- (String, nil) — The Google Cloud Trace resource name, or nil ifnot present.
#trace_sampled
deftrace_sampled()->true,false,nil- (true, false, nil) — Whether this trace is sampled, or nil if notpresent or known.
#trace_sampled?
deftrace_sampled?()->true,false,nil- (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.