Module: Bunyan

Defined in:
lib/bunyan_capybara/bunyan_constants.rb,
lib/bunyan_capybara.rb

Overview

Extracted to separate location to assist in ./bin/run_tests to work.

Defined Under Namespace

Modules: CapybaraInjection

Constant Summary collapse

DEFAULT_ENVIRONMENT =
'prod'.freeze
DEFAULT_LOG_LEVEL =
'info'.freeze
AVAILABLE_LOG_LEVELS =
%w(debug info warn error fatal).freeze
DISALLOWED_NETWORK_TRAFFIC_REGEXP =
/\.example\.com\//.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.current_loggerObject

Expose the current logger as a class method; Note this will mean we cannot run our specs in parallel (at least without some other consideration)



51
52
53
# File 'lib/bunyan_capybara.rb', line 51

def self.current_logger
  @current_logger
end

.current_logger=(value) ⇒ Object

Allow the ExampleLogging.current_logger to be set



56
57
58
# File 'lib/bunyan_capybara.rb', line 56

def self.current_logger=(value)
  @current_logger = value
end

.instantiate_all_loggers!(config: ENV, path:) ⇒ Object

Note:

Call this method no more than once per spec

Given that we want to send logs to different locations based on application, we need to initialize different loggers. We also don’t want to keep adding appenders, so this is a means of instantiating all of those loggers before we run any of the examples.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bunyan_capybara.rb', line 27

def self.instantiate_all_loggers!(config: ENV, path:)
  raise "You already called instantiate_all_loggers!" if @called
  @called = true
  layout = Logging.layouts.pattern(format_as: :json, date_pattern: "%Y-%m-%d %H:%M:%S.%L")
  Logging.appenders.stdout(layout: layout)
  if !File.exist?(File.expand_path('~/bunyan_logs'))
    Dir.mkdir(File.expand_path('~/bunyan_logs'))
  end
  entries = Dir.glob(File.expand_path(path + '/*', __FILE__))
  entries.each do |entry|
    application_name_under_test = entry.split('/').last
    logger = Logging.logger[application_name_under_test]
    log_filename = File.expand_path("~/bunyan_logs/#{application_name_under_test}.log", __FILE__)
    logger.add_appenders('stdout', Logging.appenders.file(log_filename, layout: layout))
    logger.level = config.fetch('LOG_LEVEL', DEFAULT_LOG_LEVEL).to_sym
  end
end

.reset_current_logger!Object



60
61
62
# File 'lib/bunyan_capybara.rb', line 60

def self.reset_current_logger!
  @current_logger = nil
end

.start(**kwargs) ⇒ Object



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

def self.start(**kwargs)
  BunyanWrapperWithLogging.new(**kwargs).start
end

Instance Method Details

#current_loggerObject



64
65
66
# File 'lib/bunyan_capybara.rb', line 64

def current_logger
  @current_logger
end