Class: GoogleCloudRun::Logger

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/google_cloud_run/logger.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 Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



5
6
7
8
9
10
# File 'lib/google_cloud_run/logger.rb', line 5

def initialize
  @level = G_INFO
  @formatter = DummyFormatter.new
  @out = Rails.application.config.google_cloudrun.out
  @project_id = GoogleCloudRun.project_id
end

Instance Method Details

#<<(msg) ⇒ Object



133
134
135
# File 'lib/google_cloud_run/logger.rb', line 133

def <<(msg)
  log(G_DEBUG, msg)
end

#alert(msg = nil, **labels, &block) ⇒ Object



109
110
111
# File 'lib/google_cloud_run/logger.rb', line 109

def alert(msg = nil, **labels, &block)
  write(G_ALERT, msg, labels, &block)
end

#alert!Object



117
118
119
# File 'lib/google_cloud_run/logger.rb', line 117

def alert!
  self.level = G_ALERT
end

#alert?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/google_cloud_run/logger.rb', line 113

def alert?
  self.level?(G_ALERT)
end

#closeObject

implement ::Logger interface, but do nothing



157
# File 'lib/google_cloud_run/logger.rb', line 157

def close; end

#critical(msg = nil, **labels, &block) ⇒ Object Also known as: fatal



97
98
99
# File 'lib/google_cloud_run/logger.rb', line 97

def critical(msg = nil, **labels, &block)
  write(G_CRITICAL, msg, labels, &block)
end

#critical!Object Also known as: fatal!



105
106
107
# File 'lib/google_cloud_run/logger.rb', line 105

def critical!
  self.level = G_CRITICAL
end

#critical?Boolean Also known as: fatal?

Returns:

  • (Boolean)


101
102
103
# File 'lib/google_cloud_run/logger.rb', line 101

def critical?
  self.level?(G_CRITICAL)
end

#datetime_formatObject



148
149
150
# File 'lib/google_cloud_run/logger.rb', line 148

def datetime_format
  "%FT%T.%9NZ" # RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits
end

#datetime_format=(format) ⇒ Object



161
# File 'lib/google_cloud_run/logger.rb', line 161

def datetime_format=(format); end

#debug(msg = nil, **labels, &block) ⇒ Object



37
38
39
# File 'lib/google_cloud_run/logger.rb', line 37

def debug(msg = nil, **labels, &block)
  write(G_DEBUG, msg, labels, &block)
end

#debug!Object



45
46
47
# File 'lib/google_cloud_run/logger.rb', line 45

def debug!
  self.level = G_DEBUG
end

#debug?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/google_cloud_run/logger.rb', line 41

def debug?
  self.level?(G_DEBUG)
end

#default(msg = nil, **labels, &block) ⇒ Object Also known as: unknown



25
26
27
# File 'lib/google_cloud_run/logger.rb', line 25

def default(msg = nil, **labels, &block)
  write(G_DEFAULT, msg, labels, &block)
end

#default!Object



33
34
35
# File 'lib/google_cloud_run/logger.rb', line 33

def default!
  self.level = G_DEFAULT
end

#default?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/google_cloud_run/logger.rb', line 29

def default?
  self.level?(G_DEFAULT)
end

#emergency(msg = nil, **labels, &block) ⇒ Object



121
122
123
# File 'lib/google_cloud_run/logger.rb', line 121

def emergency(msg = nil, **labels, &block)
  write(G_EMERGENCY, msg, labels, &block)
end

#emergency!Object



129
130
131
# File 'lib/google_cloud_run/logger.rb', line 129

def emergency!
  self.level = G_EMERGENCY
end

#emergency?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/google_cloud_run/logger.rb', line 125

def emergency?
  self.level?(G_EMERGENCY)
end

#error(msg = nil, **labels, &block) ⇒ Object



85
86
87
# File 'lib/google_cloud_run/logger.rb', line 85

def error(msg = nil, **labels, &block)
  write(G_ERROR, msg, labels, &block)
end

#error!Object



93
94
95
# File 'lib/google_cloud_run/logger.rb', line 93

def error!
  self.level = G_ERROR
end

#error?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/google_cloud_run/logger.rb', line 89

def error?
  self.level?(G_ERROR)
end

#flushObject

called by ActiveSupport::LogSubscriber.flush_all!



143
144
145
146
# File 'lib/google_cloud_run/logger.rb', line 143

def flush
  Thread.current[thread_key] = nil
  @out.flush
end

#formatterObject



152
153
154
# File 'lib/google_cloud_run/logger.rb', line 152

def formatter
  @formatter
end

#formatter=(formatter) ⇒ Object



163
# File 'lib/google_cloud_run/logger.rb', line 163

def formatter=(formatter); end

#info(msg = nil, **labels, &block) ⇒ Object



49
50
51
# File 'lib/google_cloud_run/logger.rb', line 49

def info(msg = nil, **labels, &block)
  write(G_INFO, msg, labels, &block)
end

#info!Object



57
58
59
# File 'lib/google_cloud_run/logger.rb', line 57

def info!
  self.level = G_INFO
end

#info?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/google_cloud_run/logger.rb', line 53

def info?
  self.level?(G_INFO)
end

#inject_request(request) ⇒ Object

called by LoggerMiddleware



138
139
140
# File 'lib/google_cloud_run/logger.rb', line 138

def inject_request(request)
  Thread.current[thread_key] = request
end

#level=(level) ⇒ Object Also known as: sev_threshold



12
13
14
# File 'lib/google_cloud_run/logger.rb', line 12

def level=(level)
  @level = Severity.mapping(level)
end

#level?(level) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/google_cloud_run/logger.rb', line 16

def level?(level)
  Severity.mapping(level) >= @level
end

#log(severity, msg = nil, progname = nil, **labels, &block) ⇒ Object Also known as: add



20
21
22
23
# File 'lib/google_cloud_run/logger.rb', line 20

def log(severity, msg = nil, progname = nil, **labels, &block)
  labels["progname"] = progname unless progname.blank?
  write(severity, msg, labels, &block)
end

#notice(msg = nil, **labels, &block) ⇒ Object



61
62
63
# File 'lib/google_cloud_run/logger.rb', line 61

def notice(msg = nil, **labels, &block)
  write(G_NOTICE, msg, labels, &block)
end

#notice!Object



69
70
71
# File 'lib/google_cloud_run/logger.rb', line 69

def notice!
  self.level = G_NOTICE
end

#notice?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/google_cloud_run/logger.rb', line 65

def notice?
  self.level?(G_NOTICE)
end

#reopen(logdev = nil) ⇒ Object



159
# File 'lib/google_cloud_run/logger.rb', line 159

def reopen(logdev = nil); end

#warning(msg = nil, **labels, &block) ⇒ Object Also known as: warn



73
74
75
# File 'lib/google_cloud_run/logger.rb', line 73

def warning(msg = nil, **labels, &block)
  write(G_WARNING, msg, labels, &block)
end

#warning!Object Also known as: warn!



81
82
83
# File 'lib/google_cloud_run/logger.rb', line 81

def warning!
  self.level = G_WARNING
end

#warning?Boolean Also known as: warn?

Returns:

  • (Boolean)


77
78
79
# File 'lib/google_cloud_run/logger.rb', line 77

def warning?
  self.level?(G_WARNING)
end