Class: Fluent::Plugin::BunyanToGoogleCloudLoggingOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_bunyan_to_google_cloud_logging.rb

Instance Method Summary collapse

Instance Method Details

#process(tag, es) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fluent/plugin/out_bunyan_to_google_cloud_logging.rb', line 37

def process(tag, es)
  entries = []

  es.each do |time, record|
    msg = record.delete("msg")
    record["message"] = msg if msg

    entry = @logging.entry
    entry.log_name = tag

    labels = {}.tap do |h|
      app_name =  record.delete("name")
      h["app_name"] = app_name unless app_name.nil?

      hostname = record.delete("hostname")
      h["hostname"] = hostname unless hostname.nil?

      pid = record.delete("pid")
      h["pid"] = pid.to_s unless pid.nil?

      v = record.delete("v")
      h["log_version"] = v.to_s unless v.nil?
    end
    entry.labels = labels unless labels.empty?

    entry.resource.type = "global"
    entry.timestamp = Time.at(time.to_r)
    entry.severity = severity(record["level"])
    entry.payload = record
    entries << entry
  end

  @logging.write_entries entries
end

#startObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/fluent/plugin/out_bunyan_to_google_cloud_logging.rb', line 26

def start
  super

  Google::Cloud.configure do |config|
    config.project_id = @project_id
    config.keyfile = @keyfile
  end

  @logging = Google::Cloud::Logging.new
end