console 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbf1eadc0f7feb035420f924a20586af9519aa49df5aedb11a4dbdd6fb74f6c4
4
- data.tar.gz: 7d6d9d50f41664e74a0eb7ea7b1b176c7715915bf60e936d62ab5786855dd4c9
3
+ metadata.gz: 7e6e1262499d10a334cb59ca261e8999ba79d951ac1e7cfba12bccd7f89e6984
4
+ data.tar.gz: 640cd8f249f96f87384cd787f9949c1756bc0138e1f1da4eca5a27d5c4c4a846
5
5
  SHA512:
6
- metadata.gz: f971cf07e39afd931aa72e72045bb0ac53fe6d301ce86af896947f295f3f27c8d815c124c433d1688d25f46e7f48ca004fd16d80e3abb4e79daf451292e56d2a
7
- data.tar.gz: fabc30bc37fb1ea3d4ce2c54f2ca9aea101faf1484c037fea9b837ea0d7543bf9be5a56678ce3df293fa7d177747ed4caa429d968f2206d542376168b1b455d3
6
+ metadata.gz: 140efdbe4232fbe7ff475716b97059d119ee3a692b3e72ed5c1c3790f403e5fe2074f6265aa766d860fe329786c414cf54350083af64b42cb798fe9b534670d8
7
+ data.tar.gz: 517647d3daa6af74fae8f23b1738c6de23c36765e8997130a89b7e29b636e9cf33910529b08dc67d41a5462d0506ff4b9f7b78619c464efea8b41b8a83a022d1
data/README.md CHANGED
@@ -31,6 +31,16 @@ Capturing structured information allows it to be used in different ways. These e
31
31
 
32
32
  Generally speaking, use `Console.logger` which is suitable for logging to the user's terminal.
33
33
 
34
+ ### Environment Variables
35
+
36
+ #### `CONSOLE_LEVEL=debug`
37
+
38
+ Control the default logger level. You can set it to any of the supported log levels: `debug`, `info`, `warn`, `error`, `fatal`.
39
+
40
+ #### `CONSOLE_DEBUG=MyClass,MyModule::MyClass`
41
+
42
+ Enable debug logging for the specified class names. You can specify one or more class names which will be resolved at runtime.
43
+
34
44
  ### Module Integration
35
45
 
36
46
  ```ruby
@@ -128,8 +138,8 @@ require 'console'
128
138
 
129
139
  MyLogger = Console::Filter[noise: 0, stuff: 1, broken: 2]
130
140
 
131
- logger = MyLogger.new(Console.logger, name: "Java")
132
- logger.verbose! # log severity/name/pid etc.
141
+ # verbose: true - log severity/name/pid etc.
142
+ logger = MyLogger.new(Console.logger, name: "Java", verbose: true)
133
143
 
134
144
  logger.broken("It's so janky.")
135
145
  ```
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -26,17 +28,12 @@ module Console
26
28
  class << self
27
29
  attr_accessor :logger
28
30
 
29
- LEVELS = {
30
- 'debug' => Logger::DEBUG,
31
- 'info' => Logger::INFO,
32
- }
33
-
34
31
  # Set the default log level based on `$DEBUG` and `$VERBOSE`.
35
- # You can also specify CONSOLE_LOG_LEVEL=debug or CONSOLE_LOG_LEVEL=info in environment.
32
+ # You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
36
33
  # https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
37
34
  def default_log_level(env = ENV)
38
- if level = env['CONSOLE_LOG_LEVEL']
39
- LEVELS[level] || Logger.warn
35
+ if level = (env['CONSOLE_LEVEL'] || env['CONSOLE_LOG_LEVEL'])
36
+ Logger::LEVELS[level.to_sym] || Logger.warn
40
37
  elsif $DEBUG
41
38
  Logger::DEBUG
42
39
  elsif $VERBOSE.nil?
@@ -45,23 +42,37 @@ module Console
45
42
  Logger::INFO
46
43
  end
47
44
  end
48
- end
49
-
50
- # Create the logger instance:
51
- @logger = Logger.new(
52
- Terminal::Logger.new($stderr),
53
- level: self.default_log_level,
54
- verbose: !$VERBOSE.nil?,
55
- )
56
-
57
- if names = ENV['CONSOLE_DEBUG']&.split(',')
58
- @resolver ||= Resolver.new
59
45
 
60
- @resolver.bind(names) do |klass|
61
- @logger.enable(klass, Logger::DEBUG)
46
+ def default_resolver(logger, env = ENV)
47
+ if names = env['CONSOLE_DEBUG']&.split(',')
48
+ resolver = Resolver.new
49
+
50
+ resolver.bind(names) do |klass|
51
+ logger.enable(klass, Logger::DEBUG)
52
+ end
53
+
54
+ return resolver
55
+ end
56
+ end
57
+
58
+ # Controls verbose output using `$VERBOSE`.
59
+ def verbose?
60
+ !$VERBOSE.nil?
61
+ end
62
+
63
+ def build(output, verbose: self.verbose?, level: self.default_log_level)
64
+ terminal = Terminal::Logger.new(output, verbose: verbose)
65
+
66
+ logger = Logger.new(terminal, verbose: verbose, level: level)
67
+
68
+ return logger
62
69
  end
63
70
  end
64
71
 
72
+ # Create the logger instance:
73
+ @logger = self.build($stderr)
74
+ @resolver = self.default_resolver(@logger)
75
+
65
76
  def logger= logger
66
77
  @logger = logger
67
78
  end
@@ -66,8 +66,6 @@ module Console
66
66
  if enabled
67
67
  enabled.each{|name| enable(name)}
68
68
  end
69
-
70
- verbose!(verbose)
71
69
  end
72
70
 
73
71
  def with(level: @level, verbose: @verbose, **options)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Console
22
- VERSION = "1.5.0"
22
+ VERSION = "1.6.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2019-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: covered
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.0.4
120
+ rubygems_version: 3.0.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Beautiful logging for Ruby.