Module: Dry::System::Plugins::Logging

Defined in:
lib/dry/system/plugins/logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(system) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dry/system/plugins/logging.rb', line 8

def self.extended(system)
  system.setting :logger, reader: true

  system.setting :log_dir, 'log'.freeze

  system.setting :log_levels, {
                   development: Logger::DEBUG,
                   test: Logger::DEBUG,
                   production: Logger::ERROR
                 }

  system.setting :logger_class, ::Logger, reader: true

  system.after(:configure, &:register_logger)

  super
end

Instance Method Details

#log_dir_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


53
54
55
# File 'lib/dry/system/plugins/logging.rb', line 53

def log_dir_path
  root.join(config.log_dir).realpath
end

#log_file_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


63
64
65
# File 'lib/dry/system/plugins/logging.rb', line 63

def log_file_name
  "#{config.env}.log"
end

#log_file_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


58
59
60
# File 'lib/dry/system/plugins/logging.rb', line 58

def log_file_path
  log_dir_path.join(log_file_name)
end

#log_levelObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


48
49
50
# File 'lib/dry/system/plugins/logging.rb', line 48

def log_level
  config.log_levels.fetch(config.env, Logger::ERROR)
end

#register_loggerself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set a logger

This is invoked automatically when a container is being configured

Returns:

  • (self)

33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dry/system/plugins/logging.rb', line 33

def register_logger
  if key?(:logger)
    self
  elsif config.logger
    register(:logger, config.logger)
  else
    config.logger = logger = config.logger_class.new(log_file_path)
    config.logger.level = log_level

    register(:logger, config.logger)
    self
  end
end