Class: Logman
- Inherits:
-
Object
- Object
- Logman
- Defined in:
- lib/logman.rb,
lib/logman/version.rb
Overview
:reek:PrimaDonnaMethod { exclude: [clear! ] } :reek:TooManyStatements{ exclude: [process ] }
Constant Summary collapse
- SEVERITY_LEVELS =
i(fatal error warn info debug).freeze
- VERSION =
"1.0.0".freeze
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #add(metadata = {}) ⇒ Object
- #clear! ⇒ Object
-
#initialize(options = {}) ⇒ Logman
constructor
A new instance of Logman.
- #process(name, metadata = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Logman
Returns a new instance of Logman.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logman.rb', line 29 def initialize( = {}) @logger = [:logger] || ::Logger.new(STDOUT) if @logger.instance_of?(Logman) # copy constructor @fields = @logger.fields.dup @logger = @logger.logger else @fields = {} end @logger.formatter = formatter end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
26 27 28 |
# File 'lib/logman.rb', line 26 def fields @fields end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
27 28 29 |
# File 'lib/logman.rb', line 27 def logger @logger end |
Class Method Details
.default_logger ⇒ Object
11 12 13 |
# File 'lib/logman.rb', line 11 def default_logger @default_logger ||= Logman.new end |
.process(name, metadata = {}, &block) ⇒ Object
15 16 17 |
# File 'lib/logman.rb', line 15 def process(name, = {}, &block) default_logger.process(name, , &block) end |
Instance Method Details
#add(metadata = {}) ⇒ Object
44 45 46 |
# File 'lib/logman.rb', line 44 def add( = {}) @fields.merge!() end |
#clear! ⇒ Object
48 49 50 |
# File 'lib/logman.rb', line 48 def clear! @fields = {} end |
#process(name, metadata = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/logman.rb', line 58 def process(name, = {}) logger = Logman.new(:logger => self) logger.add() logger.info("#{name}-started") result = yield(logger) logger.info("#{name}-finished") result rescue StandardError => exception logger.error("#{name}-failed", :type => exception.class.name, :msg => exception.) raise end |