Class: ZgcpToolkit::Logger::GoogleCloudLogging

Inherits:
Object
  • Object
show all
Defined in:
lib/zgcp_toolkit/logger/google_cloud_logging.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_name) ⇒ GoogleCloudLogging

Returns a new instance of GoogleCloudLogging.



27
28
29
30
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 27

def initialize(log_name)
  @log_name = log_name.to_s
  @logger = self.class.client.logger(@log_name, self.class.resource)
end

Instance Attribute Details

#log_nameObject (readonly)

Returns the value of attribute log_name.



23
24
25
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 23

def log_name
  @log_name
end

#loggerObject (readonly)

Returns the value of attribute logger.



23
24
25
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 23

def logger
  @logger
end

Class Method Details

.clientObject



10
11
12
13
14
15
16
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 10

def client
  @mutex.synchronize do
    @client = nil if @client_pid != Process.pid
    @client_pid = Process.pid
    @client ||= Google::Cloud::Logging.new
  end
end

.resourceObject



18
19
20
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 18

def resource
  @mutex.synchronize { @resource ||= Google::Cloud::Logging::Middleware.build_monitored_resource }
end

Instance Method Details

#flush!Object



32
33
34
# File 'lib/zgcp_toolkit/logger/google_cloud_logging.rb', line 32

def flush!
  logger.writer.flush
end