Class: BatchKit::Logging::Log4rFacade
- Inherits:
-
Object
- Object
- BatchKit::Logging::Log4rFacade
show all
- Defined in:
- lib/batch-kit/logging/log4r_logger.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Log4rFacade.
14
15
16
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 14
def initialize(logger)
@log4r_logger = logger
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(mthd, *args) ⇒ Object
63
64
65
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 63
def method_missing(mthd, *args)
@log4r_logger.send(mthd, *args)
end
|
Instance Method Details
#level ⇒ Object
19
20
21
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 19
def level
Log4r::LNAMES[@log4r_logger.level].downcase.intern
end
|
#level=(lvl) ⇒ Object
24
25
26
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 24
def level=(lvl)
@log4r_logger.level = Log4r::LNAMES.index(lvl.to_s.upcase)
end
|
#log_file ⇒ Object
29
30
31
32
33
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 29
def log_file
out_name = "#{self.name}_file"
fo = @log4r_logger.outputters.find{ |o| o.name == out_name }
fo && fo.filename
end
|
#log_file=(log_path) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/batch-kit/logging/log4r_logger.rb', line 36
def log_file=(log_path)
out_name = "#{self.name}_file"
if outputter = Log4r::Outputter[out_name]
outputter.close
@log4r_logger.remove out_name
end
if log_path
FileUtils.mkdir_p(File.dirname(log_path))
formatter = Log4r::PatternFormatter.new(pattern: '[%d] %-6l %x %M\r')
outputter = Log4r::FileOutputter.new(out_name, filename: log_path,
trunc: false, formatter: formatter)
@log4r_logger.add out_name
end
end
|