Module: Utils::LocalLogger

Defined in:
lib/crtu/utils/logger.rb

Instance Method Summary collapse

Instance Method Details

#all_loggerObject

Class wide console and file logger. Message appears on console output and it’s stored on file



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/crtu/utils/logger.rb', line 126

def all_logger
  log_file = (LOCAL_LOGGER_LOG_FILE.nil?) ? File.join(Dir.tmpdir , "#{self.class}.log") : LOCAL_LOGGER_LOG_FILE
  @logger = Log4r::Logger.new('LocalLoggerConsoleAndFile')
  pf = PatternFormatter.new(:pattern => "[%l] : #{self.class} @ %d : %M")

  so = StdoutOutputter.new('console', :formatter => pf)
  fo = RollingFileOutputter.new('f1',
                                filename: log_file,
                                trunc: false,
                                formatter: pf,
                                maxtime: SECONDS_IN_DAY)

  @logger.outputters << so
  @logger.outputters << fo
  @logger.level = DEBUG
  @logger
end

#console_loggerObject

Class console logger. The messages only go to the stdout No message is saved to file



97
98
99
100
101
102
103
104
105
# File 'lib/crtu/utils/logger.rb', line 97

def console_logger
  @logger = Log4r::Logger.new('LocalLoggerConsole')
  pf = PatternFormatter.new(:pattern => "[%l] : #{self.class} @ %d : %M")

  so = StdoutOutputter.new('console', :formatter => pf)
  @logger.outputters << so
  @logger.level = DEBUG
  @logger
end

#file_loggerObject

Class simple file logger. Message is stored in file, but it does not appear on stdout



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/crtu/utils/logger.rb', line 109

def file_logger
  log_file = (LOCAL_LOGGER_LOG_FILE.nil?) ? File.join(Dir.tmpdir , "#{self.class}.log") : LOCAL_LOGGER_LOG_FILE
  @logger = Log4r::Logger.new('LocalLoggerFile')
  pf = PatternFormatter.new(:pattern => "[%l] : #{self.class} @ %d : %M")

  fo = RollingFileOutputter.new('f1',
                                filename: log_file,
                                trunc: false,
                                formatter: pf,
                                maxtime: SECONDS_IN_DAY)
  @logger.outputters << fo
  @logger.level = DEBUG
  @logger
end