Module: Magellan::Gcs::Proxy::Log
- Included in:
- Cli, Context, GCP, GCP, ProgressNotification, PubsubProgressNotifier, PubsubSustainer
- Defined in:
- lib/magellan/gcs/proxy/log.rb
Constant Summary collapse
- CLOUD_LOGGING_RESOURCE_KEYS =
[ :project_id, :cluster_name, :namespace_id, :instance_id, :pod_id, :container_name, :zone, ].freeze
Class Method Summary collapse
- .build_cloud_logging_logger(config) ⇒ Object
- .build_logger(loggers) ⇒ Object
- .build_loggers ⇒ Object
- .logger ⇒ Object
- .loggers ⇒ Object
- .verbose(msg) ⇒ Object
Class Method Details
.build_cloud_logging_logger(config) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/magellan/gcs/proxy/log.rb', line 53 def build_cloud_logging_logger(config) log_name = config['log_name'] return nil unless log_name # container # GKE Container A Google Container Engine (GKE) container instance. # project_id: The identifier of the GCP project associated with this resource (e.g., my-project). # cluster_name: An immutable name for the cluster the container is running in. # namespace_id: Immutable ID of the cluster namespace the container is running in. # instance_id: Immutable ID of the GCE instance the container is running in. # pod_id: Immutable ID of the pod the container is running in. # container_name: Immutable name of the container. # zone: The GCE zone in which the instance is running. # See https://cloud.google.com/logging/docs/api/v2/resource-list = CLOUD_LOGGING_RESOURCE_KEYS.each_with_object({}) do |key, d| if v = ENV["BLOCKS_BATCH_CLOUD_LOGGING_#{key.to_s.upcase}"] d[key] = v end end resource = GCP.logging.resource 'container', Google::Cloud::Logging::Logger.new GCP.logging, log_name, resource, magellan_gcs_proxy: Magellan::Gcs::Proxy::VERSION end |
.build_logger(loggers) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/magellan/gcs/proxy/log.rb', line 18 def build_logger(loggers) case loggers.length when 0 then Logger.new('/dev/null') when 1 then loggers.first else CompositeLogger.new(loggers) end end |
.build_loggers ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/magellan/gcs/proxy/log.rb', line 30 def build_loggers (Proxy.config[:loggers] || []).map do |logger_def| config = logger_def.dup type = config.delete('type') case type when 'stdout' then Logger.new($stdout) when 'stderr' then Logger.new($stderr) when 'cloud_logging' then build_cloud_logging_logger(config) else raise "Unsupported logger type: #{type} with #{config.inspect}" end end end |
.logger ⇒ Object
14 15 16 |
# File 'lib/magellan/gcs/proxy/log.rb', line 14 def logger @logger ||= build_logger(loggers) end |
.loggers ⇒ Object
26 27 28 |
# File 'lib/magellan/gcs/proxy/log.rb', line 26 def loggers @loggers ||= build_loggers end |