Class: Vx::Lib::Logger::Instance
- Inherits:
-
Object
- Object
- Vx::Lib::Logger::Instance
- Defined in:
- lib/vx/lib/logger/instance.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #get_formatter(name) ⇒ Object
- #handle(message, options = {}) ⇒ Object
-
#initialize(io, params = {}) ⇒ Instance
constructor
A new instance of Instance.
- #level ⇒ Object
- #level=(new_val) ⇒ Object
- #progname=(new_val) ⇒ Object
Constructor Details
#initialize(io, params = {}) ⇒ Instance
Returns a new instance of Instance.
10 11 12 13 14 |
# File 'lib/vx/lib/logger/instance.rb', line 10 def initialize(io, params = {}) @params = params @logger = ::Logger.new(io, 7, 50_000_000) @logger.formatter = get_formatter(params[:format]) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
8 9 10 |
# File 'lib/vx/lib/logger/instance.rb', line 8 def logger @logger end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/vx/lib/logger/instance.rb', line 8 def params @params end |
Instance Method Details
#get_formatter(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/vx/lib/logger/instance.rb', line 34 def get_formatter(name) case name when :json JsonFormatter.new else JsonFormatter.new end end |
#handle(message, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vx/lib/logger/instance.rb', line 43 def handle(, = {}) be = Time.now.to_f re = nil ex = nil begin re = yield rescue Exception => e ex = e end en = Time.now.to_f .merge!(duration: (en - be)) if ex error , .merge!(exception: ex) if ex raise ex else info , end re end |
#level ⇒ Object
22 23 24 |
# File 'lib/vx/lib/logger/instance.rb', line 22 def level @logger.level end |
#level=(new_val) ⇒ Object
26 27 28 |
# File 'lib/vx/lib/logger/instance.rb', line 26 def level=(new_val) @logger.level = new_val end |
#progname=(new_val) ⇒ Object
30 31 32 |
# File 'lib/vx/lib/logger/instance.rb', line 30 def progname=(new_val) params[:progname] = new_val end |