Module: QB::Util::Logging

Includes:
SemanticLogger::Loggable
Defined in:
lib/qb/util/logging.rb

Overview

Utility methods to setup logging with semantic_logger.

Defined Under Namespace

Modules: Formatters

Class Method Summary collapse

Class Method Details

.appenderObject



203
204
205
# File 'lib/qb/util/logging.rb', line 203

def self.appender
  @appender
end

.setup(level: nil) ⇒ return_type

Setup logging.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/qb/util/logging.rb', line 172

def self.setup level: nil
  if level.nil?
    if ENV['QB_LOG_LEVEL']
      level = ENV['QB_LOG_LEVEL'].to_sym
    else
      level = :info
    end
  end
  
  SemanticLogger.default_level = level
  
  @appender ||= SemanticLogger.add_appender(
    io: $stderr,
    formatter: Formatters::Color.new,
  )
  
  # Set ENV vars (that Ansible modules will have access to!)
  
  ENV['QB_LOG_LEVEL'] = level.to_s
  
  if level == :debug
    ENV['QB_DEBUG'] = 'true'
    logger.debug "debug logging is ON"
  else
    ENV.delete 'QB_DEBUG'
  end
  
  nil
end