Class: ArchUnit::Common::Logging::CheckLogger
- Inherits:
-
Object
- Object
- ArchUnit::Common::Logging::CheckLogger
- Defined in:
- lib/archunit/common/logging/check_logger.rb
Overview
A logger owned by one check invocation; no configuration or output state is global.
Constant Summary collapse
- LEVEL_PRIORITIES =
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
Instance Attribute Summary collapse
-
#log_path ⇒ Object
readonly
Returns the value of attribute log_path.
Instance Method Summary collapse
- #close ⇒ Object
- #end_check(check_name, violation_count: nil, error: nil) ⇒ Object
-
#initialize(options = nil, clock: -> { Time.now.utc }) ⇒ CheckLogger
constructor
A new instance of CheckLogger.
- #log_metric(name:, value:, subject: nil) ⇒ Object
- #log_progress(message) ⇒ Object
- #log_violation(violation) ⇒ Object
- #start_check(check_name) ⇒ Object
Constructor Details
#initialize(options = nil, clock: -> { Time.now.utc }) ⇒ CheckLogger
Returns a new instance of CheckLogger.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/archunit/common/logging/check_logger.rb', line 16 def initialize( = nil, clock: -> { Time.now.utc }) () raise ArgumentError, 'clock must respond to call' unless clock.respond_to?(:call) @options = @clock = clock @file = nil @log_path = nil @mutex = Mutex.new end |
Instance Attribute Details
#log_path ⇒ Object (readonly)
Returns the value of attribute log_path.
14 15 16 |
# File 'lib/archunit/common/logging/check_logger.rb', line 14 def log_path @log_path end |
Instance Method Details
#close ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/archunit/common/logging/check_logger.rb', line 56 def close @mutex.synchronize do @file&.close @file = nil end nil end |
#end_check(check_name, violation_count: nil, error: nil) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/archunit/common/logging/check_logger.rb', line 31 def end_check(check_name, violation_count: nil, error: nil) name = label(check_name, 'check_name') if error write(:error, "end check: #{name} failed with #{error.class}: #{error.}") else write(:info, "end check: #{name} (#{Integer(violation_count)} violations)") end end |
#log_metric(name:, value:, subject: nil) ⇒ Object
50 51 52 53 54 |
# File 'lib/archunit/common/logging/check_logger.rb', line 50 def log_metric(name:, value:, subject: nil) metric = label(name, 'name') context = subject.nil? ? '' : " [#{subject}]" write(:debug, "log metric: #{metric}=#{value}#{context}") end |
#log_progress(message) ⇒ Object
40 41 42 |
# File 'lib/archunit/common/logging/check_logger.rb', line 40 def log_progress() write(:info, "log progress: #{label(, 'message')}") end |
#log_violation(violation) ⇒ Object
44 45 46 47 48 |
# File 'lib/archunit/common/logging/check_logger.rb', line 44 def log_violation(violation) raise ArgumentError, 'violation is required' if violation.nil? write(:warn, "log violation: #{violation_description(violation)}") end |
#start_check(check_name) ⇒ Object
27 28 29 |
# File 'lib/archunit/common/logging/check_logger.rb', line 27 def start_check(check_name) write(:info, "start check: #{label(check_name, 'check_name')}") end |