Module: LambdaLoadout::Global

Defined in:
lib/lambda_loadout/global.rb

Overview

Module-level convenience methods for quick access

Provides a simple API similar to common logging modules:

LambdaLoadout.logger.info("message")
LambdaLoadout.metrics.add_metric(...)

Examples:

Module-level usage

LambdaLoadout.configure do |config|
  config.service = "my-service"
  config.namespace = "MyApp"
end

LambdaLoadout.logger.info("Processing request")
LambdaLoadout.metrics.add_metric(name: "Request", unit: "Count", value: 1)

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.log_levelObject

Configuration



23
24
25
# File 'lib/lambda_loadout/global.rb', line 23

def log_level
  @log_level
end

.loggerLambdaLoadout::Logger

Get or create the global logger instance



28
29
30
31
32
33
# File 'lib/lambda_loadout/global.rb', line 28

def logger
  @logger ||= LambdaLoadout::Logger.new(
    service: service || ENV.fetch('POWERTOOLS_SERVICE_NAME', nil),
    level: log_level || :info
  )
end

.metricsLambdaLoadout::Metrics

Get or create the global metrics instance



38
39
40
41
42
43
# File 'lib/lambda_loadout/global.rb', line 38

def metrics
  @metrics ||= LambdaLoadout::Metrics.new(
    namespace: namespace || ENV['POWERTOOLS_METRICS_NAMESPACE'] || 'LambdaLoadout',
    service: service || ENV.fetch('POWERTOOLS_SERVICE_NAME', nil)
  )
end

.namespaceObject

Configuration



23
24
25
# File 'lib/lambda_loadout/global.rb', line 23

def namespace
  @namespace
end

.serviceObject

Configuration



23
24
25
# File 'lib/lambda_loadout/global.rb', line 23

def service
  @service
end

Class Method Details

.reset!void

This method returns an undefined value.

Reset global instances (useful for testing)



48
49
50
51
# File 'lib/lambda_loadout/global.rb', line 48

def reset!
  @logger = nil
  @metrics = nil
end