Class: Klogger::Logger
- Inherits:
-
Logger
- Object
- Logger
- Klogger::Logger
- Defined in:
- lib/klogger/logger.rb
Constant Summary collapse
- LEVELS =
[:debug, :info, :warn, :error, :fatal].freeze
- FORMATTERS =
{ json: Formatters::JSON, simple: Formatters::Simple, go: Formatters::Go }.freeze
Instance Attribute Summary collapse
-
#destinations ⇒ Object
readonly
Returns the value of attribute destinations.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #add_destination(destination) ⇒ Object
- #add_group(**tags) ⇒ Object
- #exception(exception, message = nil, **tags) ⇒ Object
- #group(**tags, &block) ⇒ Object
-
#initialize(name = nil, destination: $stdout, formatter: :go, highlight: false, include_group_ids: false, tags: {}) ⇒ Logger
constructor
A new instance of Logger.
- #pop_group ⇒ Object
- #remove_destination(destination) ⇒ Object
- #silence! ⇒ Object
- #silenced? ⇒ Boolean
- #tagged(**tags, &block) ⇒ Object
- #unsilence! ⇒ Object
Constructor Details
#initialize(name = nil, destination: $stdout, formatter: :go, highlight: false, include_group_ids: false, tags: {}) ⇒ Logger
Returns a new instance of Logger.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/klogger/logger.rb', line 25 def initialize(name = nil, destination: $stdout, formatter: :go, highlight: false, include_group_ids: false, tags: {}) @name = name = @destinations = [] @group_set = GroupSet.new @silenced = Concurrent::ThreadLocalVar.new { false } @include_group_ids = include_group_ids super(destination) self.formatter = FORMATTERS[formatter].new(highlight: highlight) end |
Instance Attribute Details
#destinations ⇒ Object (readonly)
Returns the value of attribute destinations.
15 16 17 |
# File 'lib/klogger/logger.rb', line 15 def destinations @destinations end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/klogger/logger.rb', line 14 def name @name end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
16 17 18 |
# File 'lib/klogger/logger.rb', line 16 def end |
Instance Method Details
#add_destination(destination) ⇒ Object
84 85 86 |
# File 'lib/klogger/logger.rb', line 84 def add_destination(destination) @destinations << destination end |
#add_group(**tags) ⇒ Object
54 55 56 |
# File 'lib/klogger/logger.rb', line 54 def add_group(**) @group_set.add(**) end |
#exception(exception, message = nil, **tags) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/klogger/logger.rb', line 37 def exception(exception, = nil, **) error({ message: , exception: exception.class.name, exception_message: exception., backtrace: exception.backtrace[0, 4].join("\n") }.merge()) end |
#group(**tags, &block) ⇒ Object
50 51 52 |
# File 'lib/klogger/logger.rb', line 50 def group(**, &block) @group_set.call(**, &block) end |
#pop_group ⇒ Object
58 59 60 |
# File 'lib/klogger/logger.rb', line 58 def pop_group @group_set.pop end |
#remove_destination(destination) ⇒ Object
88 89 90 |
# File 'lib/klogger/logger.rb', line 88 def remove_destination(destination) @destinations.delete(destination) end |
#silence! ⇒ Object
66 67 68 69 70 71 |
# File 'lib/klogger/logger.rb', line 66 def silence! @silenced.value = true yield if block_given? ensure unsilence! if block_given? end |
#silenced? ⇒ Boolean
80 81 82 |
# File 'lib/klogger/logger.rb', line 80 def silenced? @silenced.value == true end |
#tagged(**tags, &block) ⇒ Object
62 63 64 |
# File 'lib/klogger/logger.rb', line 62 def tagged(**, &block) @group_set.call_without_id(**, &block) end |
#unsilence! ⇒ Object
73 74 75 76 77 78 |
# File 'lib/klogger/logger.rb', line 73 def unsilence! @silenced.value = false yield if block_given? ensure silence! if block_given? end |