Class: Logging::Appenders::GoogleCloudLogging

Inherits:
Logging::Appender
  • Object
show all
Includes:
Buffering
Defined in:
lib/logging/appenders/gcl.rb

Constant Summary collapse

SEVERITY_NAMES =
%w(DEBUG INFO NOTICE WARNING ERROR CRITICAL ALERT EMERGENCY)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ GoogleCloudLogging

Returns a new instance of GoogleCloudLogging.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logging/appenders/gcl.rb', line 21

def initialize(name, options={})
  super(name, options)
  auto_flushing = options.fetch(:buffsize, options.fetch(:buffer_size, 100))
  configure_buffering({:auto_flushing => auto_flushing}.merge(options))

  @project_id = options.fetch(:project_id, nil)
  raise ArgumentError, 'Must specify project id' if @project_id.nil?

  @log_name = options.fetch(:log_name, nil)
  raise ArgumentError, 'Must specify log name' if @log_name.nil?
  
  @resource_type = options.fetch(:resource_type, nil)
  raise ArgumentError, 'Must specify resource type' if @resource_type.empty?
  
  @resource_labels = options.fetch(:resource_labels, nil)
  @keyfile = options.fetch(:keyfile, nil)
end

Instance Attribute Details

#keyfileObject (readonly)

Returns the value of attribute keyfile.



19
20
21
# File 'lib/logging/appenders/gcl.rb', line 19

def keyfile
  @keyfile
end

#log_nameObject (readonly)

Returns the value of attribute log_name.



19
20
21
# File 'lib/logging/appenders/gcl.rb', line 19

def log_name
  @log_name
end

#project_idObject (readonly)

Returns the value of attribute project_id.



19
20
21
# File 'lib/logging/appenders/gcl.rb', line 19

def project_id
  @project_id
end

#resource_labelsObject (readonly)

Returns the value of attribute resource_labels.



19
20
21
# File 'lib/logging/appenders/gcl.rb', line 19

def resource_labels
  @resource_labels
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



19
20
21
# File 'lib/logging/appenders/gcl.rb', line 19

def resource_type
  @resource_type
end

Instance Method Details

#close(*args) ⇒ Object



47
48
49
# File 'lib/logging/appenders/gcl.rb', line 47

def close( *args )
  super(false)
end

#flushObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/logging/appenders/gcl.rb', line 51

def flush
  return self if @buffer.empty?
  entries = nil
  sync do
    entries = @buffer.dup
    @buffer.clear
  end

  send_entries(entries)

  self
end

#gcloud_loggingObject



39
40
41
# File 'lib/logging/appenders/gcl.rb', line 39

def gcloud_logging
  @gcloud_logging ||= Gcloud.new(@project_id, @keyfile).logging
end

#resourceObject



43
44
45
# File 'lib/logging/appenders/gcl.rb', line 43

def resource
  gcloud_logging.resource(@resource_type, @resource_labels)
end