Class: Log4j2LoggerBridge::Destination::Configuration

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/log4j2_logger_bridge/destination.rb

Overview

The Configuration class for the Destination module

Constant Summary

Constants included from Constants

Constants::DEFAULT_APP_NAME, Constants::DEFAULT_LOGS_DIR_NAME, Constants::DEFAULT_LOG_PATTERN, Constants::DEFAULT_ROLLOVER_SCHEDULE, Constants::DEFAULT_ROLLOVER_SIZE, Constants::DEFAULT_RUBY_LOG_FORMAT, Constants::DEFAULT_TIMESTAMP_FORMAT, Constants::EMPTY_STRING, Constants::NUMERIC_TO_SYMBOL, Constants::SYMBOL_TO_RUBY

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
29
30
31
# File 'lib/log4j2_logger_bridge/destination.rb', line 22

def initialize
  @project_dir_path = Dir.pwd
  @app_name = File.basename(@project_dir_path.to_s)
  @logs_dir_name = DEFAULT_LOGS_DIR_NAME
  @log_file_name = "#{@app_name}.log"
  @timestamp_format = DEFAULT_TIMESTAMP_FORMAT
  @rollover_schedule = DEFAULT_ROLLOVER_SCHEDULE
  @rollover_size = DEFAULT_ROLLOVER_SIZE
  @rolling_file_name_template = nil
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def app_name
  @app_name
end

#log_file_nameObject

Returns the value of attribute log_file_name.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def log_file_name
  @log_file_name
end

#logs_dir_nameObject

Returns the value of attribute logs_dir_name.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def logs_dir_name
  @logs_dir_name
end

#project_dir_pathObject

Returns the value of attribute project_dir_path.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def project_dir_path
  @project_dir_path
end

#rolling_file_name_templateObject

Returns the value of attribute rolling_file_name_template.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def rolling_file_name_template
  @rolling_file_name_template
end

#rollover_scheduleObject

Returns the value of attribute rollover_schedule.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def rollover_schedule
  @rollover_schedule
end

#rollover_sizeObject

Returns the value of attribute rollover_size.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def rollover_size
  @rollover_size
end

#timestamp_formatObject

Returns the value of attribute timestamp_format.



18
19
20
# File 'lib/log4j2_logger_bridge/destination.rb', line 18

def timestamp_format
  @timestamp_format
end

Instance Method Details

#ensure_paths!Object



50
51
52
53
# File 'lib/log4j2_logger_bridge/destination.rb', line 50

def ensure_paths!
  FileUtils.mkdir_p(logs_dir_path)
  FileUtils.touch(log_file_path)
end

#log_file_pathObject



37
38
39
# File 'lib/log4j2_logger_bridge/destination.rb', line 37

def log_file_path
  File.expand_path(File.join(logs_dir_path, log_file_name))
end

#logs_dir_pathObject



33
34
35
# File 'lib/log4j2_logger_bridge/destination.rb', line 33

def logs_dir_path
  File.expand_path(File.join(project_dir_path, logs_dir_name))
end

#resolved_rolling_file_name_templateObject



41
42
43
44
45
46
47
48
# File 'lib/log4j2_logger_bridge/destination.rb', line 41

def resolved_rolling_file_name_template
  template = rolling_file_name_template
  return File.expand_path(template) if template && !template.strip.empty?

  File.expand_path(
    File.join(logs_dir_path, "#{app_name}-%d{yyyy-MM-dd}.log.gz")
  )
end

#rolloverObject



55
56
57
58
59
60
61
# File 'lib/log4j2_logger_bridge/destination.rb', line 55

def rollover
  {
    schedule: rollover_schedule,
    size: rollover_size,
    file_pattern: resolved_rolling_file_name_template
  }
end