Class: Norikra::DummyLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/norikra/logger.rb

Overview

for tests

Constant Summary collapse

FORMAT_SIMULATED =

LOG_LOG4J_FORMAT = ā€˜%dHH:mm:ss Z [%p] %m%nā€™ LOG_FORMAT = ā€˜%s: %s%sā€™

"%s [%s] %s\n"

Constants inherited from Logger

Logger::DEFAULT_MEMORY_BUFFER_LINES, Logger::TIME_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Logger

#buffer

Instance Method Summary collapse

Methods inherited from Logger

#format, #format_data, #format_location, #push

Constructor Details

#initializeDummyLogger

Returns a new instance of DummyLogger.



247
248
249
250
# File 'lib/norikra/logger.rb', line 247

def initialize
  @logs = { :TRACE => [], :DEBUG => [], :INFO => [], :WARN => [], :ERROR => [], :FATAL => [] }
  @output = []
end

Instance Attribute Details

#logsObject

Returns the value of attribute logs.



246
247
248
# File 'lib/norikra/logger.rb', line 246

def logs
  @logs
end

#outputObject

Returns the value of attribute output.



246
247
248
# File 'lib/norikra/logger.rb', line 246

def output
  @output
end

Instance Method Details

#debug(m, d, f) ⇒ Object



257
# File 'lib/norikra/logger.rb', line 257

def debug(m,d,f); self.log(:DEBUG,m,d,f); end

#error(m, d, f) ⇒ Object



260
# File 'lib/norikra/logger.rb', line 260

def error(m,d,f); self.log(:ERROR,m,d,f); end

#fatal(m, d, f) ⇒ Object



261
# File 'lib/norikra/logger.rb', line 261

def fatal(m,d,f); self.log(:FATAL,m,d,f); end

#info(m, d, f) ⇒ Object



258
# File 'lib/norikra/logger.rb', line 258

def info(m,d,f) ; self.log(:INFO, m,d,f); end

#log(level, message, data, from) ⇒ Object



251
252
253
254
255
# File 'lib/norikra/logger.rb', line 251

def log(level, message, data, from)
  @logs[level].push({:message => message, :data => data, :from => from})
  formatted = sprintf(FORMAT_SIMULATED, Time.now.strftime(TIME_FORMAT), level.to_s, format(from, message, data))
  @output.push(formatted)
end

#trace(m, d, f) ⇒ Object



256
# File 'lib/norikra/logger.rb', line 256

def trace(m,d,f); self.log(:TRACE,m,d,f); end

#warn(m, d, f) ⇒ Object



259
# File 'lib/norikra/logger.rb', line 259

def warn(m,d,f) ; self.log(:WARN, m,d,f); end