Class: Console::Logger

Inherits:
Object
  • Object
show all
Extended by:
Fiber::Local
Defined in:
lib/console/logger.rb

Constant Summary collapse

DEFAULT_LEVEL =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, **options) ⇒ Logger

Returns a new instance of Logger.



81
82
83
# File 'lib/console/logger.rb', line 81

def initialize(output, **options)
  super(output, **options)
end

Class Method Details

.default_log_level(env = ENV) ⇒ Object

Set the default log level based on ‘$DEBUG` and `$VERBOSE`. You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment. mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/console/logger.rb', line 41

def self.default_log_level(env = ENV)
  if level = env['CONSOLE_LEVEL']
    LEVELS[level.to_sym] || level.to_i
  elsif $DEBUG
    DEBUG
  elsif $VERBOSE.nil?
    WARN
  else
    INFO
  end
end

.default_logger(output = $stderr, env = ENV, **options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/console/logger.rb', line 58

def self.default_logger(output = $stderr, env = ENV, **options)
  if options[:verbose].nil?
    options[:verbose] = self.verbose?(env)
  end
  
  if options[:level].nil?
    options[:level] = self.default_log_level(env)
  end
  
  output = Output.new(output, env, **options)
  logger = self.new(output, **options)
  
  Resolver.default_resolver(logger)
  
  return logger
end

.localObject



75
76
77
# File 'lib/console/logger.rb', line 75

def self.local
  self.default_logger
end

.verbose?(env = ENV) ⇒ Boolean

Controls verbose output using ‘$VERBOSE`.

Returns:

  • (Boolean)


54
55
56
# File 'lib/console/logger.rb', line 54

def self.verbose?(env = ENV)
  !$VERBOSE.nil? || env['CONSOLE_VERBOSE']
end

Instance Method Details

#failure(subject, exception, *arguments, &block) ⇒ Object



99
100
101
# File 'lib/console/logger.rb', line 99

def failure(subject, exception, *arguments, &block)
  fatal(subject, *arguments, Event::Failure.new(exception), &block)
end

#measure(subject, name = "block", **tags, &block) ⇒ Object



89
90
91
92
93
94
95
96
97
# File 'lib/console/logger.rb', line 89

def measure(subject, name = "block", **tags, &block)
  measure = Measure.new(self, subject, **tags)
  
  if block_given?
    return measure.duration(name, &block)
  else
    return measure
  end
end

#progress(subject, total, **options) ⇒ Object



85
86
87
# File 'lib/console/logger.rb', line 85

def progress(subject, total, **options)
  Progress.new(self, subject, total, **options)
end