Class: Google::Cloud::Logging::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/logging/entry.rb,
lib/google/cloud/logging/entry/list.rb,
lib/google/cloud/logging/entry/operation.rb,
lib/google/cloud/logging/entry/http_request.rb,
lib/google/cloud/logging/entry/source_location.rb

Overview

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.

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

See Also:

Defined Under Namespace

Classes: HttpRequest, List, Operation, SourceLocation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEntry

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



78
79
80
81
82
83
84
85
# File 'lib/google/cloud/logging/entry.rb', line 78

def initialize
  @labels = {}
  @resource = Resource.new
  @http_request = HttpRequest.new
  @operation = Operation.new
  @severity = :DEFAULT
  @source_location = SourceLocation.new
end

Instance Attribute Details

#http_requestGoogle::Cloud::Logging::Entry::HttpRequest (readonly)

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



359
360
361
# File 'lib/google/cloud/logging/entry.rb', line 359

def http_request
  @http_request
end

#insert_idString

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)


341
342
343
# File 'lib/google/cloud/logging/entry.rb', line 341

def insert_id
  @insert_id
end

#labelsHash

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

Returns:

  • (Hash)


347
348
349
# File 'lib/google/cloud/logging/entry.rb', line 347

def labels
  @labels
end

#log_nameObject

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.



98
99
100
# File 'lib/google/cloud/logging/entry.rb', line 98

def log_name
  @log_name
end

#operationGoogle::Cloud::Logging::Entry::Operation (readonly)

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



365
366
367
# File 'lib/google/cloud/logging/entry.rb', line 365

def operation
  @operation
end

#payloadString, Hash

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

Returns:

  • (String, Hash)


353
354
355
# File 'lib/google/cloud/logging/entry.rb', line 353

def payload
  @payload
end

#resourceGoogle::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.



106
107
108
# File 'lib/google/cloud/logging/entry.rb', line 106

def resource
  @resource
end

#severitySymbol

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

Returns:

  • (Symbol)


117
118
119
# File 'lib/google/cloud/logging/entry.rb', line 117

def severity
  @severity
end

#source_locationGoogle::Cloud::Logging::Entry::SourceLocation (readonly)

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



380
381
382
# File 'lib/google/cloud/logging/entry.rb', line 380

def source_location
  @source_location
end

#timestampTime

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)


112
113
114
# File 'lib/google/cloud/logging/entry.rb', line 112

def timestamp
  @timestamp
end

#traceString

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)


374
375
376
# File 'lib/google/cloud/logging/entry.rb', line 374

def trace
  @trace
end

Instance Method Details

#alert!Object

Sets the severity level to :ALERT.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


307
308
309
# File 'lib/google/cloud/logging/entry.rb', line 307

def alert!
  self.severity = :ALERT
end

#alert?Boolean

Returns true if the severity level is :ALERT.

Returns:

  • (Boolean)


289
290
291
# File 'lib/google/cloud/logging/entry.rb', line 289

def alert?
  severity == :ALERT
end

#critical!Object

Sets the severity level to :CRITICAL.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


283
284
285
# File 'lib/google/cloud/logging/entry.rb', line 283

def critical!
  self.severity = :CRITICAL
end

#critical?Boolean

Returns true if the severity level is :CRITICAL.

Returns:

  • (Boolean)


265
266
267
# File 'lib/google/cloud/logging/entry.rb', line 265

def critical?
  severity == :CRITICAL
end

#debug!Object

Sets the severity level to :DEBUG.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


163
164
165
# File 'lib/google/cloud/logging/entry.rb', line 163

def debug!
  self.severity = :DEBUG
end

#debug?Boolean

Returns true if the severity level is :DEBUG.

Returns:

  • (Boolean)


145
146
147
# File 'lib/google/cloud/logging/entry.rb', line 145

def debug?
  severity == :DEBUG
end

#default!Object

Sets the severity level to :DEFAULT.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


139
140
141
# File 'lib/google/cloud/logging/entry.rb', line 139

def default!
  self.severity = :DEFAULT
end

#default?Boolean

Returns true if the severity level is :DEFAULT.

Returns:

  • (Boolean)


121
122
123
# File 'lib/google/cloud/logging/entry.rb', line 121

def default?
  severity == :DEFAULT
end

#emergency!Object

Sets the severity level to :EMERGENCY.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


331
332
333
# File 'lib/google/cloud/logging/entry.rb', line 331

def emergency!
  self.severity = :EMERGENCY
end

#emergency?Boolean

Returns true if the severity level is :EMERGENCY.

Returns:

  • (Boolean)


313
314
315
# File 'lib/google/cloud/logging/entry.rb', line 313

def emergency?
  severity == :EMERGENCY
end

#error!Object

Sets the severity level to :ERROR.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


259
260
261
# File 'lib/google/cloud/logging/entry.rb', line 259

def error!
  self.severity = :ERROR
end

#error?Boolean

Returns true if the severity level is :ERROR.

Returns:

  • (Boolean)


241
242
243
# File 'lib/google/cloud/logging/entry.rb', line 241

def error?
  severity == :ERROR
end

#info!Object

Sets the severity level to :INFO.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


187
188
189
# File 'lib/google/cloud/logging/entry.rb', line 187

def info!
  self.severity = :INFO
end

#info?Boolean

Returns true if the severity level is :INFO.

Returns:

  • (Boolean)


169
170
171
# File 'lib/google/cloud/logging/entry.rb', line 169

def info?
  severity == :INFO
end

#notice!Object

Sets the severity level to :NOTICE.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


211
212
213
# File 'lib/google/cloud/logging/entry.rb', line 211

def notice!
  self.severity = :NOTICE
end

#notice?Boolean

Returns true if the severity level is :NOTICE.

Returns:

  • (Boolean)


193
194
195
# File 'lib/google/cloud/logging/entry.rb', line 193

def notice?
  severity == :NOTICE
end

#warning!Object

Sets the severity level to :WARNING.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new

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


235
236
237
# File 'lib/google/cloud/logging/entry.rb', line 235

def warning!
  self.severity = :WARNING
end

#warning?Boolean

Returns true if the severity level is :WARNING.

Returns:

  • (Boolean)


217
218
219
# File 'lib/google/cloud/logging/entry.rb', line 217

def warning?
  severity == :WARNING
end