Class: NseData::Config::Logger

Inherits:
Base
  • Object
show all
Defined in:
lib/nse_data/config/logger.rb

Overview

Logger handles configuration specifically for logging.

It inherits from Base to utilize the hash-like configuration interface and provides default settings for logging.

Instance Attribute Summary collapse

Attributes inherited from Base

#settings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=

Constructor Details

#initialize(logger = ::Logger.new(self.class.default_log_file)) ⇒ Logger

Initializes the Logger with a default or custom Logger instance.

Parameters:

  • logger (Logger) (defaults to: ::Logger.new(self.class.default_log_file))

    Optional custom Logger instance.



28
29
30
31
32
33
# File 'lib/nse_data/config/logger.rb', line 28

def initialize(logger = ::Logger.new(self.class.default_log_file))
  super()
  @logger = logger
  @settings[:logger] = logger
  # puts "Log file created at: #{self.class.default_log_file}"
end

Instance Attribute Details

#loggerObject

Retrieves/Sets the Logger instance.



15
16
17
# File 'lib/nse_data/config/logger.rb', line 15

def logger
  @logger
end

Class Method Details

.default_log_fileObject

Creates a default temporary log file.



17
18
19
20
21
22
23
# File 'lib/nse_data/config/logger.rb', line 17

def self.default_log_file
  return $stdout if ENV['NSE_DEV']

  temp_file = Tempfile.new(['nse_data', '.log'])
  temp_file.close # Close the file immediately after creation
  temp_file.path # Return the file path for the Logger
end