Class: Gcloud::Logging::Entry
- Inherits:
-
Object
- Object
- Gcloud::Logging::Entry
- Defined in:
- lib/gcloud/logging/entry.rb,
lib/gcloud/logging/entry/list.rb,
lib/gcloud/logging/entry/operation.rb,
lib/gcloud/logging/entry/http_request.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 gcloud-ruby. There is no Log type in gcloud-ruby or Log resource in the Cloud Logging API.
Defined Under Namespace
Classes: HttpRequest, List, Operation
Instance Attribute Summary collapse
-
#http_request ⇒ Gcloud::Logging::Entry::HttpRequest
readonly
Information about the HTTP request associated with this log entry, if applicable.
-
#insert_id ⇒ String
A unique ID for the log entry.
-
#labels ⇒ Hash
A set of user-defined data that provides additional information about the log entry.
-
#log_name ⇒ Object
The resource name of the log to which this log entry belongs.
-
#operation ⇒ Gcloud::Logging::Entry::Operation
readonly
Information about an operation associated with the log entry, if applicable.
-
#payload ⇒ String, Hash
The log entry payload, represented as either a string, a hash (JSON), or a hash (protocol buffer).
-
#resource ⇒ Gcloud::Logging::Resource
The monitored resource associated with this log entry.
-
#severity ⇒ Symbol
The severity level of the log entry.
-
#timestamp ⇒ Time
The time the event described by the log entry occurred.
Class Method Summary collapse
Instance Method Summary collapse
-
#alert! ⇒ Object
Sets the severity level to
:ALERT. -
#alert? ⇒ Boolean
Returns
trueif the severity level is:ALERT. -
#append_payload(grpc) ⇒ Object
object.
-
#critical! ⇒ Object
Sets the severity level to
:CRITICAL. -
#critical? ⇒ Boolean
Returns
trueif the severity level is:CRITICAL. -
#debug! ⇒ Object
Sets the severity level to
:DEBUG. -
#debug? ⇒ Boolean
Returns
trueif the severity level is:DEBUG. -
#default! ⇒ Object
Sets the severity level to
:DEFAULT. -
#default? ⇒ Boolean
Returns
trueif the severity level is:DEFAULT. -
#emergency! ⇒ Object
Sets the severity level to
:EMERGENCY. -
#emergency? ⇒ Boolean
Returns
trueif the severity level is:EMERGENCY. - #empty? ⇒ Boolean
-
#error! ⇒ Object
Sets the severity level to
:ERROR. -
#error? ⇒ Boolean
Returns
trueif the severity level is:ERROR. -
#info! ⇒ Object
Sets the severity level to
:INFO. -
#info? ⇒ Boolean
Returns
trueif the severity level is:INFO. -
#initialize ⇒ Entry
constructor
Create a new Entry instance.
-
#labels_grpc ⇒ Object
Google::Logging::V2::LogEntry object.
-
#notice! ⇒ Object
Sets the severity level to
:NOTICE. -
#notice? ⇒ Boolean
Returns
trueif the severity level is:NOTICE. - #timestamp_grpc ⇒ Object
- #to_grpc ⇒ Object
-
#warning! ⇒ Object
Sets the severity level to
:WARNING. -
#warning? ⇒ Boolean
Returns
trueif the severity level is:WARNING.
Constructor Details
#initialize ⇒ Entry
Create a new Entry instance. The #resource attribute is pre-populated with a new Resource instance. See also Project#entry.
64 65 66 67 68 69 70 |
# File 'lib/gcloud/logging/entry.rb', line 64 def initialize @labels = {} @resource = Resource.new @http_request = HttpRequest.new @operation = Operation.new @severity = :DEFAULT end |
Instance Attribute Details
#http_request ⇒ Gcloud::Logging::Entry::HttpRequest (readonly)
Information about the HTTP request associated with this log entry, if applicable.
353 354 355 |
# File 'lib/gcloud/logging/entry.rb', line 353 def http_request @http_request end |
#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.
335 336 337 |
# File 'lib/gcloud/logging/entry.rb', line 335 def insert_id @insert_id end |
#labels ⇒ Hash
A set of user-defined data that provides additional information about the log entry.
341 342 343 |
# File 'lib/gcloud/logging/entry.rb', line 341 def labels @labels end |
#log_name ⇒ Object
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.
83 84 85 |
# File 'lib/gcloud/logging/entry.rb', line 83 def log_name @log_name end |
#operation ⇒ Gcloud::Logging::Entry::Operation (readonly)
Information about an operation associated with the log entry, if applicable.
359 360 361 |
# File 'lib/gcloud/logging/entry.rb', line 359 def operation @operation end |
#payload ⇒ String, Hash
The log entry payload, represented as either a string, a hash (JSON), or a hash (protocol buffer).
347 348 349 |
# File 'lib/gcloud/logging/entry.rb', line 347 def payload @payload end |
#resource ⇒ Gcloud::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.
91 92 93 |
# File 'lib/gcloud/logging/entry.rb', line 91 def resource @resource end |
#severity ⇒ Symbol
The severity level of the log entry. The default value is :DEFAULT.
102 103 104 |
# File 'lib/gcloud/logging/entry.rb', line 102 def severity @severity end |
#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.
97 98 99 |
# File 'lib/gcloud/logging/entry.rb', line 97 def end |
Class Method Details
.extract_payload(grpc) ⇒ Object
453 454 455 |
# File 'lib/gcloud/logging/entry.rb', line 453 def self.extract_payload grpc grpc.proto_payload || grpc.json_payload || grpc.text_payload end |
.extract_timestamp(grpc) ⇒ Object
459 460 461 462 |
# File 'lib/gcloud/logging/entry.rb', line 459 def self. grpc return nil if grpc..nil? Time.at grpc..seconds, grpc..nanos/1000.0 end |
.from_grpc(grpc) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/gcloud/logging/entry.rb', line 395 def self.from_grpc grpc return new if grpc.nil? new.tap do |e| e.log_name = grpc.log_name e. = (grpc) e.severity = grpc.severity e.insert_id = grpc.insert_id e.labels = GRPCUtils.map_to_hash(grpc.labels) e.payload = extract_payload(grpc) e.instance_variable_set "@resource", Resource.from_grpc(grpc.resource) e.instance_variable_set "@http_request", HttpRequest.from_grpc(grpc.http_request) e.instance_variable_set "@operation", Operation.from_grpc(grpc.operation) end end |
Instance Method Details
#alert! ⇒ Object
Sets the severity level to :ALERT.
300 301 302 |
# File 'lib/gcloud/logging/entry.rb', line 300 def alert! self.severity = :ALERT end |
#alert? ⇒ Boolean
Returns true if the severity level is :ALERT.
281 282 283 |
# File 'lib/gcloud/logging/entry.rb', line 281 def alert? severity == :ALERT end |
#append_payload(grpc) ⇒ Object
object.
437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/gcloud/logging/entry.rb', line 437 def append_payload grpc grpc.proto_payload = nil grpc.json_payload = nil grpc.text_payload = nil if payload.is_a? Google::Protobuf::Any grpc.proto_payload = payload elsif payload.respond_to? :to_hash grpc.json_payload = GRPCUtils.hash_to_struct payload.to_hash else grpc.text_payload = payload.to_s end end |
#critical! ⇒ Object
Sets the severity level to :CRITICAL.
275 276 277 |
# File 'lib/gcloud/logging/entry.rb', line 275 def critical! self.severity = :CRITICAL end |
#critical? ⇒ Boolean
Returns true if the severity level is :CRITICAL.
256 257 258 |
# File 'lib/gcloud/logging/entry.rb', line 256 def critical? severity == :CRITICAL end |
#debug! ⇒ Object
Sets the severity level to :DEBUG.
150 151 152 |
# File 'lib/gcloud/logging/entry.rb', line 150 def debug! self.severity = :DEBUG end |
#debug? ⇒ Boolean
Returns true if the severity level is :DEBUG.
131 132 133 |
# File 'lib/gcloud/logging/entry.rb', line 131 def debug? severity == :DEBUG end |
#default! ⇒ Object
Sets the severity level to :DEFAULT.
125 126 127 |
# File 'lib/gcloud/logging/entry.rb', line 125 def default! self.severity = :DEFAULT end |
#default? ⇒ Boolean
Returns true if the severity level is :DEFAULT.
106 107 108 |
# File 'lib/gcloud/logging/entry.rb', line 106 def default? severity == :DEFAULT end |
#emergency! ⇒ Object
Sets the severity level to :EMERGENCY.
325 326 327 |
# File 'lib/gcloud/logging/entry.rb', line 325 def emergency! self.severity = :EMERGENCY end |
#emergency? ⇒ Boolean
Returns true if the severity level is :EMERGENCY.
306 307 308 |
# File 'lib/gcloud/logging/entry.rb', line 306 def emergency? severity == :EMERGENCY end |
#empty? ⇒ Boolean
363 364 365 366 367 368 369 370 371 372 |
# File 'lib/gcloud/logging/entry.rb', line 363 def empty? log_name.nil? && .nil? && insert_id.nil? && (labels.nil? || labels.empty?) && payload.nil? && resource.empty? && http_request.empty? && operation.empty? end |
#error! ⇒ Object
Sets the severity level to :ERROR.
250 251 252 |
# File 'lib/gcloud/logging/entry.rb', line 250 def error! self.severity = :ERROR end |
#error? ⇒ Boolean
Returns true if the severity level is :ERROR.
231 232 233 |
# File 'lib/gcloud/logging/entry.rb', line 231 def error? severity == :ERROR end |
#info! ⇒ Object
Sets the severity level to :INFO.
175 176 177 |
# File 'lib/gcloud/logging/entry.rb', line 175 def info! self.severity = :INFO end |
#info? ⇒ Boolean
Returns true if the severity level is :INFO.
156 157 158 |
# File 'lib/gcloud/logging/entry.rb', line 156 def info? severity == :INFO end |
#labels_grpc ⇒ Object
Google::Logging::V2::LogEntry object.
426 427 428 429 430 431 432 |
# File 'lib/gcloud/logging/entry.rb', line 426 def labels_grpc # Coerce symbols to strings Hash[labels.map do |k, v| v = String(v) if v.is_a? Symbol [String(k), v] end] end |
#notice! ⇒ Object
Sets the severity level to :NOTICE.
200 201 202 |
# File 'lib/gcloud/logging/entry.rb', line 200 def notice! self.severity = :NOTICE end |
#notice? ⇒ Boolean
Returns true if the severity level is :NOTICE.
181 182 183 |
# File 'lib/gcloud/logging/entry.rb', line 181 def notice? severity == :NOTICE end |
#timestamp_grpc ⇒ Object
414 415 416 417 418 419 420 421 |
# File 'lib/gcloud/logging/entry.rb', line 414 def return nil if .nil? # TODO: ArgumentError if timestamp is not a Time object? Google::Protobuf::Timestamp.new( seconds: .to_i, nanos: .nsec ) end |
#to_grpc ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/gcloud/logging/entry.rb', line 376 def to_grpc grpc = Google::Logging::V2::LogEntry.new( log_name: log_name.to_s, timestamp: , # TODO: verify severity is the correct type? severity: severity, insert_id: insert_id.to_s, labels: labels_grpc, resource: resource.to_grpc, http_request: http_request.to_grpc, operation: operation.to_grpc ) # Add payload append_payload grpc grpc end |
#warning! ⇒ Object
Sets the severity level to :WARNING.
225 226 227 |
# File 'lib/gcloud/logging/entry.rb', line 225 def warning! self.severity = :WARNING end |
#warning? ⇒ Boolean
Returns true if the severity level is :WARNING.
206 207 208 |
# File 'lib/gcloud/logging/entry.rb', line 206 def warning? severity == :WARNING end |