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 +4 -4
- data/README.md +12 -2
- data/lib/console.rb +32 -21
- data/lib/console/filter.rb +0 -2
- data/lib/console/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e6e1262499d10a334cb59ca261e8999ba79d951ac1e7cfba12bccd7f89e6984
|
4
|
+
data.tar.gz: 640cd8f249f96f87384cd787f9949c1756bc0138e1f1da4eca5a27d5c4c4a846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
132
|
-
logger
|
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
|
```
|
data/lib/console.rb
CHANGED
@@ -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
|
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
|
-
|
61
|
-
|
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
|
data/lib/console/filter.rb
CHANGED
data/lib/console/version.rb
CHANGED
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.
|
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-
|
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.
|
120
|
+
rubygems_version: 3.0.6
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Beautiful logging for Ruby.
|