Cloud Logging API - Class Google::Cloud::Logging::Entry (v2.3.3)

Reference documentation and code samples for the Cloud Logging API class Google::Cloud::Logging::Entry.

Entry

An individual entry in a log.

Each log entry is composed of metadata and a payload. The metadata includes standard information used by Stackdriver Logging, such as when the entry was created and where it came from. The payload is the event record. Traditionally this is a message string, but in Stackdriver Logging it can also be a JSON or protocol buffer object. A single log can have entries with different payload types.

A log is a named collection of entries. Logs can be produced by Google Cloud Platform services, by third-party services, or by your applications. For example, the log compute.googleapis.com/activity_log is produced by Google Compute Engine. Logs are simply referenced by name in google-cloud. There is no Log type in google-cloud or Log resource in the Stackdriver Logging API.

Inherits

  • Object

Examples

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry payload: "Job started.", log_name: "my_app_log"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "1"
entry.resource.labels[:version_id] = "20150925t173233"

logging.write_entries entry

Provide a hash to write a JSON payload to the log:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

payload = { "stats" => { "a" => 8, "b" => 12.5} }
entry = logging.entry payload: payload, log_name: "my_app_log"
entry.resource.type = "gae_app"
entry.resource.labels[:module_id] = "1"
entry.resource.labels[:version_id] = "20150925t173233"

logging.write_entries entry

Methods

.insert_id

def self.insert_id() -> String

Generate a pseudo-random, 16-character ID suitable for use as the log entry's #insert_id.

Returns
  • (String)
Example
require "google/cloud/logging"

insert_id = Google::Cloud::Logging::Entry.insert_id

#alert!

def alert!()

Sets the severity level to :ALERT.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.alert!
entry.alert? #=> true
entry.severity #=> :ALERT

#alert?

def alert?() -> Boolean

Returns true if the severity level is :ALERT.

Returns
  • (Boolean)

#critical!

def critical!()

Sets the severity level to :CRITICAL.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.critical!
entry.critical? #=> true
entry.severity #=> :CRITICAL

#critical?

def critical?() -> Boolean

Returns true if the severity level is :CRITICAL.

Returns
  • (Boolean)

#debug!

def debug!()

Sets the severity level to :DEBUG.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.debug!
entry.debug? #=> true
entry.severity #=> :DEBUG

#debug?

def debug?() -> Boolean

Returns true if the severity level is :DEBUG.

Returns
  • (Boolean)

#default!

def default!()

Sets the severity level to :DEFAULT.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity = :DEBUG
entry.default!
entry.default? #=> true
entry.severity #=> :DEFAULT

#default?

def default?() -> Boolean

Returns true if the severity level is :DEFAULT.

Returns
  • (Boolean)

#emergency!

def emergency!()

Sets the severity level to :EMERGENCY.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.emergency!
entry.emergency? #=> true
entry.severity #=> :EMERGENCY

#emergency?

def emergency?() -> Boolean

Returns true if the severity level is :EMERGENCY.

Returns
  • (Boolean)

#error!

def error!()

Sets the severity level to :ERROR.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.error!
entry.error? #=> true
entry.severity #=> :ERROR

#error?

def error?() -> Boolean

Returns true if the severity level is :ERROR.

Returns
  • (Boolean)

#http_request

def http_request() -> Google::Cloud::Logging::Entry::HttpRequest

Information about the HTTP request associated with this log entry, if applicable.

#info!

def info!()

Sets the severity level to :INFO.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.info!
entry.info? #=> true
entry.severity #=> :INFO

#info?

def info?() -> Boolean

Returns true if the severity level is :INFO.

Returns
  • (Boolean)

#initialize

def initialize() -> Entry

Create a new Entry instance. The #resource attribute is pre-populated with a new Resource instance. See also Project#entry.

Returns
  • (Entry) — a new instance of Entry

#insert_id

def insert_id() -> String

A unique ID for the log entry. If you provide this field, the logging service considers other log entries in the same log with the same ID as duplicates which can be removed. If omitted, Stackdriver Logging will generate a unique ID for this log entry.

Returns
  • (String)

#insert_id=

def insert_id=(value) -> String

A unique ID for the log entry. If you provide this field, the logging service considers other log entries in the same log with the same ID as duplicates which can be removed. If omitted, Stackdriver Logging will generate a unique ID for this log entry.

Parameter
  • value (String)
Returns
  • (String)

#labels

def labels() -> Hash

A set of user-defined data that provides additional information about the log entry.

Returns
  • (Hash)

#labels=

def labels=(value) -> Hash

A set of user-defined data that provides additional information about the log entry.

Parameter
  • value (Hash)
Returns
  • (Hash)

#log_name

def log_name()

The resource name of the log to which this log entry belongs. The format of the name is projects/<project-id>/logs/<log-id>. e.g. projects/my-projectid/logs/my_app_log and projects/1234567890/logs/library.googleapis.com%2Fbook_log

The log ID part of resource name must be less than 512 characters long and can only include the following characters: upper and lower case alphanumeric characters: [A-Za-z0-9]; and punctuation characters: forward-slash (/), underscore (_), hyphen (-), and period (.). Forward-slash (/) characters in the log ID must be URL-encoded.

#log_name=

def log_name=(value)

The resource name of the log to which this log entry belongs. The format of the name is projects/<project-id>/logs/<log-id>. e.g. projects/my-projectid/logs/my_app_log and projects/1234567890/logs/library.googleapis.com%2Fbook_log

The log ID part of resource name must be less than 512 characters long and can only include the following characters: upper and lower case alphanumeric characters: [A-Za-z0-9]; and punctuation characters: forward-slash (/), underscore (_), hyphen (-), and period (.). Forward-slash (/) characters in the log ID must be URL-encoded.

#notice!

def notice!()

Sets the severity level to :NOTICE.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.notice!
entry.notice? #=> true
entry.severity #=> :NOTICE

#notice?

def notice?() -> Boolean

Returns true if the severity level is :NOTICE.

Returns
  • (Boolean)

#operation

def operation() -> Google::Cloud::Logging::Entry::Operation

Information about an operation associated with the log entry, if applicable.

#payload

def payload() -> String, Hash

The log entry payload, represented as either a string, a hash (JSON), or a hash (protocol buffer).

Returns
  • (String, Hash)

#payload=

def payload=(value) -> String, Hash

The log entry payload, represented as either a string, a hash (JSON), or a hash (protocol buffer).

Parameter
  • value (String, Hash)
Returns
  • (String, Hash)

#resource

def resource() -> Google::Cloud::Logging::Resource

The monitored resource associated with this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error.

#resource=

def resource=(value) -> Google::Cloud::Logging::Resource

The monitored resource associated with this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error.

#severity

def severity() -> Symbol

The severity level of the log entry. The default value is :DEFAULT.

Returns
  • (Symbol)

#severity=

def severity=(value) -> Symbol

The severity level of the log entry. The default value is :DEFAULT.

Parameter
  • value (Symbol)
Returns
  • (Symbol)

#source_location

def source_location() -> Google::Cloud::Logging::Entry::SourceLocation

Source code location information associated with the log entry, if any.

#timestamp

def timestamp() -> Time

The time the event described by the log entry occurred. If omitted, Stackdriver Logging will use the time the log entry is written.

Returns
  • (Time)

#timestamp=

def timestamp=(value) -> Time

The time the event described by the log entry occurred. If omitted, Stackdriver Logging will use the time the log entry is written.

Parameter
  • value (Time)
Returns
  • (Time)

#trace

def trace() -> String

Resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com. Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824 Optional.

Returns
  • (String)

#trace=

def trace=(value) -> String

Resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com. Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824 Optional.

Parameter
  • value (String)
Returns
  • (String)

#trace_sampled

def trace_sampled() -> Boolean

The sampling decision of the trace associated with the log entry. Optional. A true value means that the trace resource name in the trace field was sampled for storage in a trace backend. A false means that the trace was not sampled for storage when this log entry was written, or the sampling decision was unknown at the time. A non-sampled trace value is still useful as a request correlation identifier. The default is false.

Returns
  • (Boolean)

#trace_sampled=

def trace_sampled=(value) -> Boolean

The sampling decision of the trace associated with the log entry. Optional. A true value means that the trace resource name in the trace field was sampled for storage in a trace backend. A false means that the trace was not sampled for storage when this log entry was written, or the sampling decision was unknown at the time. A non-sampled trace value is still useful as a request correlation identifier. The default is false.

Parameter
  • value (Boolean)
Returns
  • (Boolean)

#warning!

def warning!()

Sets the severity level to :WARNING.

Example
require "google/cloud/logging"

logging = Google::Cloud::Logging.new

entry = logging.entry
entry.severity #=> :DEFAULT
entry.warning!
entry.warning? #=> true
entry.severity #=> :WARNING

#warning?

def warning?() -> Boolean

Returns true if the severity level is :WARNING.

Returns
  • (Boolean)