Class: Gcloud::Logging::Project
- Inherits:
-
Object
- Object
- Gcloud::Logging::Project
- Defined in:
- lib/gcloud/logging/project.rb
Overview
# Project
Projects are top-level containers in Google Cloud Platform. They store information about billing and authorized users, and they control access to Google Cloud Logging resources. Each project has a friendly name and a unique ID. Projects can be created only in the [Google Developers Console](console.developers.google.com). See Gcloud#logging.
See Gcloud#logging
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#create_metric(name, filter, description: nil) ⇒ Gcloud::Logging::Metric
(also: #new_metric)
Creates a new logs-based metric for Google Cloud Monitoring.
-
#create_sink(name, destination, filter: nil, version: :unspecified) ⇒ Gcloud::Logging::Sink
(also: #new_sink)
Creates a new project sink.
-
#delete_log(name) ⇒ Boolean
Deletes a log and all its log entries.
-
#entries(projects: nil, filter: nil, order: nil, token: nil, max: nil) ⇒ Array<Gcloud::Logging::Entry>
(also: #find_entries)
Lists log entries.
-
#entry ⇒ Gcloud::Logging::Entry
(also: #new_entry)
Creates an new Entry instance that may be populated and written to the Cloud Logging service.
-
#initialize(project, credentials) ⇒ Project
constructor
A new instance of Project.
-
#logger(log_name, resource, labels = {}) ⇒ Gcloud::Logging::Logger
Creates a logger instance that is API-compatible with Ruby’s standard library [Logger](ruby-doc.org/stdlib/libdoc/logger/rdoc).
-
#metric(name) ⇒ Gcloud::Logging::Metric?
(also: #get_metric, #find_metric)
Retrieves metric by name.
-
#metrics(token: nil, max: nil) ⇒ Array<Gcloud::Logging::Metric>
(also: #find_metrics)
Retrieves the list of metrics belonging to the project.
-
#project ⇒ String
The ID of the current project.
-
#resource(type, labels = {}) ⇒ Gcloud::Logging::Resource
(also: #new_resource)
Creates a new monitored resource instance.
-
#resource_descriptors(token: nil, max: nil) ⇒ Array<Gcloud::Logging::ResourceDescriptor>
(also: #find_resource_descriptors)
Retrieves the list of monitored resource descriptors that are used by Google Cloud Logging.
-
#sink(sink_name) ⇒ Gcloud::Logging::Sink?
(also: #get_sink, #find_sink)
Retrieves a sink by name.
-
#sinks(token: nil, max: nil) ⇒ Array<Gcloud::Logging::Sink>
(also: #find_sinks)
Retrieves the list of sinks belonging to the project.
-
#write_entries(entries, log_name: nil, resource: nil, labels: nil) ⇒ Boolean
Writes log entries to the Cloud Logging service.
Constructor Details
#initialize(project, credentials) ⇒ Project
Returns a new instance of Project.
52 53 54 55 56 |
# File 'lib/gcloud/logging/project.rb', line 52 def initialize project, credentials project = project.to_s # Always cast to a string fail ArgumentError, "project is missing" if project.empty? @service = Service.new project, credentials end |
Instance Attribute Details
#service ⇒ Object
48 49 50 |
# File 'lib/gcloud/logging/project.rb', line 48 def service @service end |
Class Method Details
.default_project ⇒ Object
77 78 79 80 81 82 |
# File 'lib/gcloud/logging/project.rb', line 77 def self.default_project ENV["LOGGING_PROJECT"] || ENV["GCLOUD_PROJECT"] || ENV["GOOGLE_CLOUD_PROJECT"] || Gcloud::GCE.project_id end |
Instance Method Details
#create_metric(name, filter, description: nil) ⇒ Gcloud::Logging::Metric Also known as: new_metric
Creates a new logs-based metric for Google Cloud Monitoring.
598 599 600 601 602 603 604 |
# File 'lib/gcloud/logging/project.rb', line 598 def create_metric name, filter, description: nil ensure_service! grpc = service.create_metric name, filter, description Metric.from_grpc grpc, service rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#create_sink(name, destination, filter: nil, version: :unspecified) ⇒ Gcloud::Logging::Sink Also known as: new_sink
Creates a new project sink. When you create a sink, only new log entries that match the sink’s filter are exported. Cloud Logging does not send previously-ingested log entries to the sink’s destination.
Before creating the sink, ensure that you have granted ‘[email protected]` permission to write logs to the destination. See [Permissions for writing exported logs](cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
485 486 487 488 489 490 491 492 |
# File 'lib/gcloud/logging/project.rb', line 485 def create_sink name, destination, filter: nil, version: :unspecified version = Sink.resolve_version version ensure_service! grpc = service.create_sink name, destination, filter, version Sink.from_grpc grpc, service rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#delete_log(name) ⇒ Boolean
Deletes a log and all its log entries. The log will reappear if it receives new entries.
305 306 307 308 309 310 311 |
# File 'lib/gcloud/logging/project.rb', line 305 def delete_log name ensure_service! service.delete_log name return true rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#entries(projects: nil, filter: nil, order: nil, token: nil, max: nil) ⇒ Array<Gcloud::Logging::Entry> Also known as: find_entries
Lists log entries. Use this method to retrieve log entries from Cloud Logging.
149 150 151 152 153 154 155 156 157 |
# File 'lib/gcloud/logging/project.rb', line 149 def entries projects: nil, filter: nil, order: nil, token: nil, max: nil ensure_service! list_grpc = service.list_entries projects: projects, filter: filter, order: order, token: token, max: max Entry::List.from_grpc list_grpc, service, projects: projects, max: max, filter: filter, order: order rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#entry ⇒ Gcloud::Logging::Entry Also known as: new_entry
Creates an new Entry instance that may be populated and written to the Cloud Logging service. The Entry#resource attribute is pre-populated with a new Resource instance. Equivalent to calling ‘Gcloud::Logging::Entry.new`.
180 181 182 |
# File 'lib/gcloud/logging/project.rb', line 180 def entry Entry.new end |
#logger(log_name, resource, labels = {}) ⇒ Gcloud::Logging::Logger
Creates a logger instance that is API-compatible with Ruby’s standard library [Logger](ruby-doc.org/stdlib/libdoc/logger/rdoc).
281 282 283 |
# File 'lib/gcloud/logging/project.rb', line 281 def logger log_name, resource, labels = {} Logger.new self, log_name, resource, labels end |
#metric(name) ⇒ Gcloud::Logging::Metric? Also known as: get_metric, find_metric
Retrieves metric by name.
629 630 631 632 633 634 635 636 |
# File 'lib/gcloud/logging/project.rb', line 629 def metric name ensure_service! grpc = service.get_metric name Metric.from_grpc grpc, service rescue GRPC::BadStatus => e return nil if e.code == 5 raise Gcloud::Error.from_error(e) end |
#metrics(token: nil, max: nil) ⇒ Array<Gcloud::Logging::Metric> Also known as: find_metrics
Retrieves the list of metrics belonging to the project.
562 563 564 565 566 567 568 |
# File 'lib/gcloud/logging/project.rb', line 562 def metrics token: nil, max: nil ensure_service! grpc = service.list_metrics token: token, max: max Metric::List.from_grpc grpc, service rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#project ⇒ String
The ID of the current project.
71 72 73 |
# File 'lib/gcloud/logging/project.rb', line 71 def project service.project end |
#resource(type, labels = {}) ⇒ Gcloud::Logging::Resource Also known as: new_resource
Creates a new monitored resource instance.
376 377 378 379 380 381 |
# File 'lib/gcloud/logging/project.rb', line 376 def resource type, labels = {} Resource.new.tap do |r| r.type = type r.labels = labels end end |
#resource_descriptors(token: nil, max: nil) ⇒ Array<Gcloud::Logging::ResourceDescriptor> Also known as: find_resource_descriptors
Retrieves the list of monitored resource descriptors that are used by Google Cloud Logging.
352 353 354 355 356 357 358 |
# File 'lib/gcloud/logging/project.rb', line 352 def resource_descriptors token: nil, max: nil ensure_service! list_grpc = service.list_resource_descriptors token: token, max: max ResourceDescriptor::List.from_grpc list_grpc, service rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#sink(sink_name) ⇒ Gcloud::Logging::Sink? Also known as: get_sink, find_sink
Retrieves a sink by name.
517 518 519 520 521 522 523 524 |
# File 'lib/gcloud/logging/project.rb', line 517 def sink sink_name ensure_service! grpc = service.get_sink sink_name Sink.from_grpc grpc, service rescue GRPC::BadStatus => e return nil if e.code == 5 raise Gcloud::Error.from_error(e) end |
#sinks(token: nil, max: nil) ⇒ Array<Gcloud::Logging::Sink> Also known as: find_sinks
Retrieves the list of sinks belonging to the project.
418 419 420 421 422 423 424 |
# File 'lib/gcloud/logging/project.rb', line 418 def sinks token: nil, max: nil ensure_service! list_grpc = service.list_sinks token: token, max: max Sink::List.from_grpc list_grpc, service rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |
#write_entries(entries, log_name: nil, resource: nil, labels: nil) ⇒ Boolean
Writes log entries to the Cloud Logging service.
If you write a collection of log entries, you can provide the log name, resource, and/or labels hash to be used for all of the entries, and omit these values from the individual entries.
244 245 246 247 248 249 250 251 252 |
# File 'lib/gcloud/logging/project.rb', line 244 def write_entries entries, log_name: nil, resource: nil, labels: nil ensure_service! service.write_entries Array(entries).map(&:to_grpc), log_name: log_name, resource: resource, labels: labels return true rescue GRPC::BadStatus => e raise Gcloud::Error.from_error(e) end |