Class: GoogleCloudRun::LogEntry
- Inherits:
-
Object
- Object
- GoogleCloudRun::LogEntry
- Includes:
- Logger::Severity
- Defined in:
- lib/google_cloud_run/entry.rb
Constant Summary
Constants included from Logger::Severity
Logger::Severity::G_ALERT, Logger::Severity::G_CRITICAL, Logger::Severity::G_DEBUG, Logger::Severity::G_DEFAULT, Logger::Severity::G_EMERGENCY, Logger::Severity::G_ERROR, Logger::Severity::G_INFO, Logger::Severity::G_NOTICE, Logger::Severity::G_WARNING
Instance Attribute Summary collapse
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#location_line ⇒ Object
Returns the value of attribute location_line.
-
#location_method ⇒ Object
Returns the value of attribute location_method.
-
#location_path ⇒ Object
Returns the value of attribute location_path.
-
#message ⇒ Object
Returns the value of attribute message.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#request ⇒ Object
Returns the value of attribute request.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize ⇒ LogEntry
constructor
A new instance of LogEntry.
- #to_json ⇒ Object
Constructor Details
Instance Attribute Details
#labels ⇒ Object
Returns the value of attribute labels.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def labels @labels end |
#location_line ⇒ Object
Returns the value of attribute location_line.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def location_line @location_line end |
#location_method ⇒ Object
Returns the value of attribute location_method.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def location_method @location_method end |
#location_path ⇒ Object
Returns the value of attribute location_path.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def location_path @location_path end |
#message ⇒ Object
Returns the value of attribute message.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def @message end |
#project_id ⇒ Object
Returns the value of attribute project_id.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def project_id @project_id end |
#request ⇒ Object
Returns the value of attribute request.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def request @request end |
#severity ⇒ Object
Returns the value of attribute severity.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def severity @severity end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def @timestamp end |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/google_cloud_run/entry.rb', line 5 def user @user end |
Instance Method Details
#to_json ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/google_cloud_run/entry.rb', line 20 def to_json raise "labels must be hash" if !@labels.blank? && !@labels.is_a?(Hash) labels["user"] = @user unless @user.blank? j = {} j["logging.googleapis.com/insertId"] = @insert_id j["severity"] = Severity.to_s(Severity.mapping(@severity)) j["message"] = @message.is_a?(String) ? @message.strip : @message.inspect j["timestampSeconds"] = @timestamp.to_i j["timestampNanos"] = @timestamp.nsec j["logging.googleapis.com/labels"] = @labels unless @labels.blank? if @request # https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest j["httpRequest"] = {} j["httpRequest"]["requestMethod"] = @request&.method.to_s j["httpRequest"]["requestUrl"] = @request&.url.to_s j["httpRequest"]["userAgent"] = @request&.headers["user-agent"].to_s unless @request&.headers["user-agent"].blank? j["httpRequest"]["remoteIp"] = @request&.remote_ip.to_s j["httpRequest"]["referer"] = @request&.headers["referer"].to_s unless @request&.headers["referer"].blank? trace, span, sample = GoogleCloudRun.parse_trace_context(@request&.headers["X-Cloud-Trace-Context"]) j["logging.googleapis.com/trace"] = "projects/#{@project_id}/traces/#{trace}" unless trace.blank? j["logging.googleapis.com/spanId"] = span unless span.blank? j["logging.googleapis.com/trace_sampled"] = sample unless sample.nil? end if @location_path || @location_line || @location_method j["logging.googleapis.com/sourceLocation"] = {} j["logging.googleapis.com/sourceLocation"]["function"] = @location_method.to_s j["logging.googleapis.com/sourceLocation"]["file"] = @location_path.to_s j["logging.googleapis.com/sourceLocation"]["line"] = @location_line.to_i end j.to_json end |