Class: Google::Cloud::Logging::Project
- Inherits:
-
Object
- Object
- Google::Cloud::Logging::Project
- Defined in:
- lib/google/cloud/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 Stackdriver Logging resources. Each project has a friendly name and a unique ID. Projects can be created only in the Google Developers Console. See Google::Cloud#logging.
See Google::Cloud#logging
Instance Method Summary collapse
-
#async_writer(max_queue_size: AsyncWriter::DEFAULT_MAX_QUEUE_SIZE) ⇒ Object
Creates an object that batches and transmits log entries asynchronously.
-
#create_metric(name, filter, description: nil) ⇒ Google::Cloud::Logging::Metric
(also: #new_metric)
Creates a new logs-based metric for Google Cloud Monitoring.
-
#create_sink(name, destination, filter: nil, unique_writer_identity: nil) ⇒ Google::Cloud::Logging::Sink
(also: #new_sink)
Creates a new project sink.
-
#delete_log(name) ⇒ Boolean
Deletes a log and all its log entries.
-
#entries(resources: nil, filter: nil, order: nil, token: nil, max: nil, projects: nil) ⇒ Array<Google::Cloud::Logging::Entry>
(also: #find_entries)
Lists log entries.
-
#entry(log_name: nil, resource: nil, timestamp: nil, severity: nil, insert_id: nil, labels: nil, payload: nil) ⇒ Google::Cloud::Logging::Entry
(also: #new_entry)
Creates an new Entry instance that may be populated and written to the Stackdriver Logging service.
-
#logger(log_name, resource, labels = {}) ⇒ Google::Cloud::Logging::Logger
Creates a logger instance that is API-compatible with Ruby's standard library Logger.
-
#logs(resource: nil, token: nil, max: nil) ⇒ Array<String>
(also: #find_logs, #log_names, #find_log_names)
Lists log names.
-
#metric(name) ⇒ Google::Cloud::Logging::Metric?
(also: #get_metric, #find_metric)
Retrieves metric by name.
-
#metrics(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::Metric>
(also: #find_metrics)
Retrieves the list of metrics belonging to the project.
-
#project_id ⇒ String
(also: #project)
The ID of the current project.
-
#resource(type, labels = {}) ⇒ Google::Cloud::Logging::Resource
(also: #new_resource)
Creates a new monitored resource instance.
-
#resource_descriptors(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::ResourceDescriptor>
(also: #find_resource_descriptors)
Retrieves the list of monitored resource descriptors that are used by Stackdriver Logging.
-
#shared_async_writer ⇒ Object
Returns a shared AsyncWriter for this Project.
-
#sink(sink_name) ⇒ Google::Cloud::Logging::Sink?
(also: #get_sink, #find_sink)
Retrieves a sink by name.
-
#sinks(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::Sink>
(also: #find_sinks)
Retrieves the list of sinks belonging to the project.
-
#write_entries(entries, log_name: nil, resource: nil, labels: nil, partial_success: nil) ⇒ Boolean
Writes log entries to the Stackdriver Logging service.
Instance Method Details
#async_writer(max_queue_size: AsyncWriter::DEFAULT_MAX_QUEUE_SIZE) ⇒ Object
Creates an object that batches and transmits log entries asynchronously.
Use this object to transmit log entries efficiently. It keeps a queue of log entries, and runs a background thread that transmits them to the logging service in batches. Generally, adding to the queue will not block.
This object is thread-safe; it may accept write requests from multiple threads simultaneously, and will serialize them when executing in the background thread.
344 345 346 |
# File 'lib/google/cloud/logging/project.rb', line 344 def async_writer max_queue_size: AsyncWriter::DEFAULT_MAX_QUEUE_SIZE AsyncWriter.new self, max_queue_size end |
#create_metric(name, filter, description: nil) ⇒ Google::Cloud::Logging::Metric Also known as: new_metric
Creates a new logs-based metric for Google Cloud Monitoring.
775 776 777 778 779 |
# File 'lib/google/cloud/logging/project.rb', line 775 def create_metric name, filter, description: nil ensure_service! grpc = service.create_metric name, filter, description Metric.from_grpc grpc, service end |
#create_sink(name, destination, filter: nil, unique_writer_identity: nil) ⇒ Google::Cloud::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. 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.
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
# File 'lib/google/cloud/logging/project.rb', line 659 def create_sink name, destination, filter: nil, unique_writer_identity: nil, start_at: nil, end_at: nil, version: nil ensure_service! if start_at warn "[DEPRECATION] start_at is deprecated and will be ignored." end if end_at warn "[DEPRECATION] end_at is deprecated and will be ignored." end if version warn "[DEPRECATION] version is deprecated and will be ignored." end grpc = service.create_sink \ name, destination, filter, unique_writer_identity: unique_writer_identity Sink.from_grpc grpc, service end |
#delete_log(name) ⇒ Boolean
Deletes a log and all its log entries. The log will reappear if it receives new entries.
485 486 487 488 489 |
# File 'lib/google/cloud/logging/project.rb', line 485 def delete_log name ensure_service! service.delete_log name true end |
#entries(resources: nil, filter: nil, order: nil, token: nil, max: nil, projects: nil) ⇒ Array<Google::Cloud::Logging::Entry> Also known as: find_entries
Lists log entries. Use this method to retrieve log entries from Cloud Logging.
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/google/cloud/logging/project.rb', line 146 def entries resources: nil, filter: nil, order: nil, token: nil, max: nil, projects: nil ensure_service! list_grpc = service.list_entries resources: resources, filter: filter, order: order, token: token, max: max, projects: projects Entry::List.from_grpc list_grpc, service, resources: resources, max: max, filter: filter, order: order, projects: projects end |
#entry(log_name: nil, resource: nil, timestamp: nil, severity: nil, insert_id: nil, labels: nil, payload: nil) ⇒ Google::Cloud::Logging::Entry Also known as: new_entry
Creates an new Entry instance that may be populated and written to the
Stackdriver Logging service. The Entry#resource attribute is
pre-populated with a new Resource instance.
Equivalent to calling Google::Cloud::Logging::Entry.new
.
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/google/cloud/logging/project.rb', line 207 def entry log_name: nil, resource: nil, timestamp: nil, severity: nil, insert_id: nil, labels: nil, payload: nil e = Entry.new e.log_name = log_name if log_name e.resource = resource if resource e. = if e.severity = severity if severity e.insert_id = insert_id if insert_id e.labels = labels if labels e.payload = payload if payload e end |
#logger(log_name, resource, labels = {}) ⇒ Google::Cloud::Logging::Logger
Creates a logger instance that is API-compatible with Ruby's standard library Logger.
The logger will create a new AsyncWriter object to transmit log entries on a background thread.
420 421 422 |
# File 'lib/google/cloud/logging/project.rb', line 420 def logger log_name, resource, labels = {} Logger.new shared_async_writer, log_name, resource, labels end |
#logs(resource: nil, token: nil, max: nil) ⇒ Array<String> Also known as: find_logs, log_names, find_log_names
Lists log names. Use this method to retrieve log names from Cloud Logging.
456 457 458 459 460 461 |
# File 'lib/google/cloud/logging/project.rb', line 456 def logs resource: nil, token: nil, max: nil ensure_service! list_grpc = service.list_logs resource: resource, token: token, max: max Log::List.from_grpc list_grpc, service, resource: resource, max: max end |
#metric(name) ⇒ Google::Cloud::Logging::Metric? Also known as: get_metric, find_metric
Retrieves metric by name.
802 803 804 805 806 807 808 |
# File 'lib/google/cloud/logging/project.rb', line 802 def metric name ensure_service! grpc = service.get_metric name Metric.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#metrics(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::Metric> Also known as: find_metrics
Retrieves the list of metrics belonging to the project.
742 743 744 745 746 |
# File 'lib/google/cloud/logging/project.rb', line 742 def metrics token: nil, max: nil ensure_service! grpc = service.list_metrics token: token, max: max Metric::List.from_grpc grpc, service, max end |
#project_id ⇒ String Also known as: project
The ID of the current project.
74 75 76 |
# File 'lib/google/cloud/logging/project.rb', line 74 def project_id service.project end |
#resource(type, labels = {}) ⇒ Google::Cloud::Logging::Resource Also known as: new_resource
Creates a new monitored resource instance.
551 552 553 554 555 556 |
# File 'lib/google/cloud/logging/project.rb', line 551 def resource type, labels = {} Resource.new.tap do |r| r.type = type r.labels = labels end end |
#resource_descriptors(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::ResourceDescriptor> Also known as: find_resource_descriptors
Retrieves the list of monitored resource descriptors that are used by Stackdriver Logging.
525 526 527 528 529 |
# File 'lib/google/cloud/logging/project.rb', line 525 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, max end |
#shared_async_writer ⇒ Object
Returns a shared AsyncWriter for this Project. If this method is called multiple times, it will return the same object.
372 373 374 |
# File 'lib/google/cloud/logging/project.rb', line 372 def shared_async_writer @shared_async_writer ||= async_writer end |
#sink(sink_name) ⇒ Google::Cloud::Logging::Sink? Also known as: get_sink, find_sink
Retrieves a sink by name.
703 704 705 706 707 708 709 |
# File 'lib/google/cloud/logging/project.rb', line 703 def sink sink_name ensure_service! grpc = service.get_sink sink_name Sink.from_grpc grpc, service rescue Google::Cloud::NotFoundError nil end |
#sinks(token: nil, max: nil) ⇒ Array<Google::Cloud::Logging::Sink> Also known as: find_sinks
Retrieves the list of sinks belonging to the project.
588 589 590 591 592 |
# File 'lib/google/cloud/logging/project.rb', line 588 def sinks token: nil, max: nil ensure_service! list_grpc = service.list_sinks token: token, max: max Sink::List.from_grpc list_grpc, service, max end |
#write_entries(entries, log_name: nil, resource: nil, labels: nil, partial_success: nil) ⇒ Boolean
Writes log entries to the Stackdriver 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.
297 298 299 300 301 302 303 304 |
# File 'lib/google/cloud/logging/project.rb', line 297 def write_entries entries, log_name: nil, resource: nil, labels: nil, partial_success: nil ensure_service! service.write_entries Array(entries).map(&:to_grpc), log_name: log_name, resource: resource, labels: labels, partial_success: partial_success true end |