Class: RSpecTracer::Logger Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_tracer/logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal Logger — see RSpecTracer for the user-facing surface. Internal logger; thin wrapper around IO#puts gated on numeric log level. Exposed via RSpecTracer.logger.

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_level, out: nil) ⇒ Logger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Logger.

Parameters:

  • log_level (Integer)

    numeric level (Configuration::LOG_LEVEL)

  • out (IO, nil) (defaults to: nil)

    destination stream. Falls back to default_out when nil, then to $stdout.



30
31
32
33
# File 'lib/rspec_tracer/logger.rb', line 30

def initialize(log_level, out: nil)
  @log_level = log_level
  @out = out || self.class.default_out || $stdout
end

Class Attribute Details

.default_outIO?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Process-wide default destination for loggers constructed without an explicit out:. nil (the norm) means $stdout, which normal rspec runs rely on. The rspec-tracer binary sets this to its stderr BEFORE booting the tracer library, so loggers constructed while the project's .rspec-tracer config loads (e.g. by the 1.x deprecation shims, or recreated after a config log_level call resets the memoized instance) already bind to stderr and machine-readable stdout (blast-radius --json) stays free of diagnostics. See CLI.

Returns:

  • (IO, nil)


23
24
25
# File 'lib/rspec_tracer/logger.rb', line 23

def default_out
  @default_out
end

Instance Method Details

#debug(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal method on the tracer pipeline.



37
38
39
# File 'lib/rspec_tracer/logger.rb', line 37

def debug(message)
  @out.puts message if @log_level == 1
end

#error(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal method on the tracer pipeline.



55
56
57
# File 'lib/rspec_tracer/logger.rb', line 55

def error(message)
  @out.puts message if @log_level.between?(1, 4)
end

#info(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal method on the tracer pipeline.



43
44
45
# File 'lib/rspec_tracer/logger.rb', line 43

def info(message)
  @out.puts message if @log_level.between?(1, 2)
end

#warn(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Internal method on the tracer pipeline.



49
50
51
# File 'lib/rspec_tracer/logger.rb', line 49

def warn(message)
  @out.puts message if @log_level.between?(1, 3)
end