Module: Logcraft

Extended by:
LogContextHelper
Defined in:
lib/logcraft.rb,
lib/logcraft/rails.rb,
lib/logcraft/railtie.rb,
lib/logcraft/version.rb,
lib/logcraft/log_layout.rb,
lib/logcraft/rspec/helpers.rb,
lib/logcraft/log_context_helper.rb,
lib/logcraft/rails/active_record.rb,
lib/logcraft/rails/request_logger.rb,
lib/logcraft/rails/request_id_logger.rb,
lib/logcraft/rails/log_subscription_handler.rb,
lib/logcraft/rails/active_record/log_subscriber.rb

Defined Under Namespace

Modules: LogContextHelper, RSpec, Rails Classes: LogLayout, Railtie

Constant Summary collapse

VERSION =
"2.2.1"

Class Method Summary collapse

Methods included from LogContextHelper

add_to_log_context, within_log_context

Class Method Details

.initialize(log_level: :info, global_context: {}, layout_options: {}) ⇒ Object



15
16
17
18
# File 'lib/logcraft.rb', line 15

def self.initialize(log_level: :info, global_context: {}, layout_options: {})
  Logging.logger.root.appenders = Logging.appenders.stdout layout: LogLayout.new(global_context, layout_options)
  Logging.logger.root.level = log_level
end

.logger(name, level = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/logcraft.rb', line 20

def self.logger(name, level = nil)
  Logging::Logger[name].tap do |logger|
    logger.level = level if level
    logger.instance_variable_set :@logdev, OpenStruct.new(dev: STDOUT)
    logger.define_singleton_method :dup do
      super().tap do |logger_copy|
        Logging::Logger.define_log_methods logger_copy
      end
    end
  end
end