Class: GoogleLogger::Loggers::CloudLogger
- Defined in:
- lib/google_logger/loggers/cloud_logger.rb
Instance Method Summary collapse
-
#build_entry(payload, log_name: 'default_log', severity: :DEFAULT) ⇒ Google::Cloud::Logging::Entry
Builds a new entry.
-
#initialize ⇒ CloudLogger
constructor
Creates a new logger with project_id and credentials specified in configuration.
-
#write_entry(entry) ⇒ Object
Writes an entry to google cloud.
Constructor Details
#initialize ⇒ CloudLogger
Creates a new logger with project_id and credentials specified in configuration
9 10 11 12 13 14 |
# File 'lib/google_logger/loggers/cloud_logger.rb', line 9 def initialize @project = Google::Cloud::Logging.new( project_id: configuration.project_id, credentials: configuration.credentials ) end |
Instance Method Details
#build_entry(payload, log_name: 'default_log', severity: :DEFAULT) ⇒ Google::Cloud::Logging::Entry
Builds a new entry
23 24 25 26 27 28 |
# File 'lib/google_logger/loggers/cloud_logger.rb', line 23 def build_entry(payload, log_name: 'default_log', severity: :DEFAULT) entry = @project.entry(payload: payload, log_name: log_name, severity: severity, timestamp: Time.now) entry.resource.type = configuration.resource_type entry.resource.labels = configuration.resource_labels entry end |
#write_entry(entry) ⇒ Object
Writes an entry to google cloud
defaults to configuration value
return [Boolean] ‘true` if the entry was successfully written
36 37 38 39 |
# File 'lib/google_logger/loggers/cloud_logger.rb', line 36 def write_entry(entry) log_writer = configuration.async ? @project.async_writer : @project log_writer.write_entries(entry) end |