class GoogleLogger::Loggers::CloudLogger

Public Class Methods

new() click to toggle source

Creates a new logger with project_id and credentials specified in configuration

# 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

Public Instance Methods

build_entry(payload, log_name: 'default_log', severity: :DEFAULT) click to toggle source

Builds a new entry

@param [String, Hash] payload content of the log @param [String] log_name log_name which can be used to filter logs @param [Symbol] severity severity of the log

@return [Google::Cloud::Logging::Entry] entry with payload and default resource configuration

# 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) click to toggle source

Writes an entry to google cloud

@param [Google::Cloud::Logging::Entry] entry entry to be written to google cloud defaults to configuration value

return [Boolean] `true` if the entry was successfully written

# 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