Class: Google::Cloud::Logging::Sink

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/logging/sink.rb,
lib/google/cloud/logging/sink/list.rb

Overview

Sink

Used to export log entries outside Stackdriver Logging. When you create a sink, new log entries are exported. Stackdriver Logging does not send previously-ingested log entries to the sink's destination.

Before creating the sink, ensure that you have granted cloud-logs@google.com permission to write logs to the destination. See Permissions for writing exported logs.

You can retrieve an existing sink with Project#sink.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.create_bucket "my-logs-bucket"

# Grant owner permission to Stackdriver Logging service
email = "cloud-logs@google.com"
bucket.acl.add_owner "group-#{email}"

require "google/cloud/logging"

logging = Google::Cloud::Logging.new
sink = logging.create_sink "my-sink",
                           "storage.googleapis.com/#{bucket.id}"

See Also:

Defined Under Namespace

Classes: List

Instance Method Summary collapse

Instance Method Details

#deleteBoolean

Permanently deletes the logs-based sink.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new
sink = logging.sink "severe_errors"
sink.delete

Returns:

  • (Boolean)

    Returns true if the sink was deleted.



192
193
194
195
196
# File 'lib/google/cloud/logging/sink.rb', line 192

def delete
  ensure_service!
  service.delete_sink name
  true
end

#destinationObject

The export destination. See Exporting Logs With Sinks.



86
87
88
# File 'lib/google/cloud/logging/sink.rb', line 86

def destination
  @grpc.destination
end

#destination=(destination) ⇒ Object

Updates the export destination. See Exporting Logs With Sinks.



93
94
95
# File 'lib/google/cloud/logging/sink.rb', line 93

def destination= destination
  @grpc.destination = destination
end

#filterObject

An advanced logs filter that defines the log entries to be exported. The filter must be consistent with the log entry format designed by the version parameter, regardless of the format of the log entry that was originally written to Stackdriver Logging.



104
105
106
# File 'lib/google/cloud/logging/sink.rb', line 104

def filter
  @grpc.filter
end

#filter=(filter) ⇒ Object

Updates the advanced logs filter that defines the log entries to be exported. The filter must be consistent with the log entry format designed by the version parameter, regardless of the format of the log entry that was originally written to Stackdriver Logging.



115
116
117
# File 'lib/google/cloud/logging/sink.rb', line 115

def filter= filter
  @grpc.filter = filter
end

#nameObject

The client-assigned sink identifier. Sink identifiers are limited to 1000 characters and can include only the following characters: A-Z, a-z, 0-9, and the special characters _-..



79
80
81
# File 'lib/google/cloud/logging/sink.rb', line 79

def name
  @grpc.name
end

#reload!Object Also known as: refresh!

Reloads the logs-based sink with current data from the Logging service.



174
175
176
177
# File 'lib/google/cloud/logging/sink.rb', line 174

def reload!
  ensure_service!
  @grpc = service.get_sink name
end

#saveObject

Updates the logs-based sink.

Examples:

require "google/cloud/logging"

logging = Google::Cloud::Logging.new
sink = logging.sink "severe_errors"
sink.filter = "logName:syslog AND severity>=ERROR"
sink.save


166
167
168
169
# File 'lib/google/cloud/logging/sink.rb', line 166

def save
  ensure_service!
  @grpc = service.update_sink name, destination, filter, version
end

#unspecified?Boolean

Helper to determine if the sink's version is VERSION_FORMAT_UNSPECIFIED.

Returns:

  • (Boolean)


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

def unspecified?
  !(v1? || v2?)
end

#v1?Boolean

Helper to determine if the sink's version is V1.

Returns:

  • (Boolean)


151
152
153
# File 'lib/google/cloud/logging/sink.rb', line 151

def v1?
  version == :V1
end

#v2?Boolean

Helper to determine if the sink's version is V2.

Returns:

  • (Boolean)


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

def v2?
  version == :V2
end

#versionObject

The log entry version used when exporting log entries from this sink. This version does not have to correspond to the version of the log entry when it was written to Stackdriver Logging.



123
124
125
# File 'lib/google/cloud/logging/sink.rb', line 123

def version
  @grpc.output_version_format
end

#version=(version) ⇒ Object

Updates the log entry version used when exporting log entries from this sink. This version does not have to correspond to the version of the log entry when it was written to Stackdriver Logging. Accepted values are :VERSION_FORMAT_UNSPECIFIED, :V2, and :V1.



132
133
134
# File 'lib/google/cloud/logging/sink.rb', line 132

def version= version
  @grpc.output_version_format = self.class.resolve_version(version)
end