uu 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/.gitignore +2 -0
- data/.rubocop.local.yml +2 -0
- data/Gemfile.lock +29 -19
- data/lib/drb/http0helper.rb +1 -0
- data/lib/uu/log.rb +29 -0
- data/lib/uu/log_context.rb +21 -0
- data/lib/uu/loggable.rb +17 -0
- data/lib/uu/logger_fluent.rb +92 -0
- data/lib/uu/logger_stderr.rb +66 -0
- data/lib/uu/version.rb +1 -1
- data/lib/uu.rb +5 -0
- data/uu.gemspec +4 -0
- metadata +65 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73d99f426e2be9be3bdf189a6462aca5c00d0465eb44c721679024d3e7e722f7
|
4
|
+
data.tar.gz: f9213a72553bcc9e27e97e0e5e7816d0c3fc0581626b4db5be4ffa5989a7d6b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4528a5cf71ccd0d87b4e6aa2e50b58f41cf297ab94dd801c10ac101b91d5f843fa095d40dcecc0bc8f927c759f40ca932f174da6cdd6d6bf366825624836405c
|
7
|
+
data.tar.gz: 014d2f831489df7e18fe726f58bc680976f78cac8dfc4c55bab1d652bc24ec0c577ad5b324c7a7794810b395d64b9a8403f5ef8c9cb299c3c4a7b3a29131ff03
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
FLUENTD_HOST=
|
data/.gitignore
CHANGED
data/.rubocop.local.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
uu (0.
|
4
|
+
uu (0.2.0)
|
5
|
+
colorize
|
6
|
+
fluent-logger
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
8
10
|
specs:
|
9
11
|
ast (2.4.0)
|
12
|
+
byebug (10.0.2)
|
10
13
|
coderay (1.1.2)
|
14
|
+
colorize (0.8.1)
|
11
15
|
diff-lcs (1.3)
|
12
|
-
|
16
|
+
dotenv (2.6.0)
|
17
|
+
ffi (1.10.0)
|
18
|
+
fluent-logger (0.7.2)
|
19
|
+
msgpack (>= 1.0.0, < 2)
|
13
20
|
formatador (0.2.5)
|
14
|
-
guard (2.
|
21
|
+
guard (2.15.0)
|
15
22
|
formatador (>= 0.2.4)
|
16
23
|
listen (>= 2.7, < 4.0)
|
17
24
|
lumberjack (>= 1.0.12, < 2.0)
|
@@ -20,8 +27,8 @@ GEM
|
|
20
27
|
pry (>= 0.9.12)
|
21
28
|
shellany (~> 0.0)
|
22
29
|
thor (>= 0.18.1)
|
23
|
-
guard-bundler (2.
|
24
|
-
bundler (
|
30
|
+
guard-bundler (2.2.0)
|
31
|
+
bundler (>= 1.3.0)
|
25
32
|
guard (~> 2.2)
|
26
33
|
guard-compat (~> 1.1)
|
27
34
|
guard-compat (1.2.1)
|
@@ -35,7 +42,7 @@ GEM
|
|
35
42
|
guard-yard (2.2.1)
|
36
43
|
guard (>= 1.1.0)
|
37
44
|
yard (>= 0.7.0)
|
38
|
-
jaro_winkler (1.5.
|
45
|
+
jaro_winkler (1.5.2)
|
39
46
|
listen (3.1.5)
|
40
47
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
41
48
|
rb-inotify (~> 0.9, >= 0.9.7)
|
@@ -43,30 +50,31 @@ GEM
|
|
43
50
|
lumberjack (1.0.13)
|
44
51
|
mbs (0.0.3)
|
45
52
|
thor
|
46
|
-
method_source (0.9.
|
53
|
+
method_source (0.9.2)
|
54
|
+
msgpack (1.2.6)
|
47
55
|
nenv (0.3.0)
|
48
56
|
notiffany (0.1.1)
|
49
57
|
nenv (~> 0.1)
|
50
58
|
shellany (~> 0.0)
|
51
59
|
parallel (1.12.1)
|
52
|
-
parser (2.5.
|
60
|
+
parser (2.5.3.0)
|
53
61
|
ast (~> 2.4.0)
|
54
62
|
powerpack (0.1.2)
|
55
|
-
pry (0.
|
63
|
+
pry (0.12.2)
|
56
64
|
coderay (~> 1.1.0)
|
57
65
|
method_source (~> 0.9.0)
|
58
66
|
rainbow (3.0.0)
|
59
|
-
rake (
|
67
|
+
rake (12.3.2)
|
60
68
|
rb-fsevent (0.10.3)
|
61
|
-
rb-inotify (0.
|
62
|
-
ffi (
|
69
|
+
rb-inotify (0.10.0)
|
70
|
+
ffi (~> 1.0)
|
63
71
|
rspec (3.8.0)
|
64
72
|
rspec-core (~> 3.8.0)
|
65
73
|
rspec-expectations (~> 3.8.0)
|
66
74
|
rspec-mocks (~> 3.8.0)
|
67
75
|
rspec-core (3.8.0)
|
68
76
|
rspec-support (~> 3.8.0)
|
69
|
-
rspec-expectations (3.8.
|
77
|
+
rspec-expectations (3.8.2)
|
70
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
79
|
rspec-support (~> 3.8.0)
|
72
80
|
rspec-its (1.2.0)
|
@@ -76,26 +84,28 @@ GEM
|
|
76
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
77
85
|
rspec-support (~> 3.8.0)
|
78
86
|
rspec-support (3.8.0)
|
79
|
-
rubocop (0.
|
87
|
+
rubocop (0.62.0)
|
80
88
|
jaro_winkler (~> 1.5.1)
|
81
89
|
parallel (~> 1.10)
|
82
90
|
parser (>= 2.5, != 2.5.1.1)
|
83
91
|
powerpack (~> 0.1)
|
84
92
|
rainbow (>= 2.2.2, < 4.0)
|
85
93
|
ruby-progressbar (~> 1.7)
|
86
|
-
unicode-display_width (~> 1.
|
94
|
+
unicode-display_width (~> 1.4.0)
|
87
95
|
ruby-progressbar (1.10.0)
|
88
96
|
ruby_dep (1.5.0)
|
89
97
|
shellany (0.0.1)
|
90
|
-
thor (0.20.
|
91
|
-
unicode-display_width (1.4.
|
92
|
-
yard (0.9.
|
98
|
+
thor (0.20.3)
|
99
|
+
unicode-display_width (1.4.1)
|
100
|
+
yard (0.9.16)
|
93
101
|
|
94
102
|
PLATFORMS
|
95
103
|
ruby
|
96
104
|
|
97
105
|
DEPENDENCIES
|
98
106
|
bundler
|
107
|
+
byebug
|
108
|
+
dotenv
|
99
109
|
guard
|
100
110
|
guard-bundler
|
101
111
|
guard-rspec
|
@@ -110,4 +120,4 @@ DEPENDENCIES
|
|
110
120
|
yard
|
111
121
|
|
112
122
|
BUNDLED WITH
|
113
|
-
1.
|
123
|
+
1.17.2
|
data/lib/drb/http0helper.rb
CHANGED
data/lib/uu/log.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UU
|
4
|
+
class Log
|
5
|
+
include LogContext
|
6
|
+
include Loggable
|
7
|
+
|
8
|
+
def self.instance
|
9
|
+
Thread.current[:logger] ||= new
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@loggers = {
|
14
|
+
stderr: LoggerStderr.new(self),
|
15
|
+
fluent: LoggerFluent.new(self),
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor :loggers
|
20
|
+
|
21
|
+
%i[debug info warn error fatal].each do |severity|
|
22
|
+
define_method(severity) do |*args, &block|
|
23
|
+
@loggers.each_value.map do |logger|
|
24
|
+
logger.send(severity, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module UU
|
6
|
+
module LogContext
|
7
|
+
attr_writer :context
|
8
|
+
|
9
|
+
def context
|
10
|
+
@context ||= {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def with(context_)
|
14
|
+
original_context = context
|
15
|
+
self.context = context.merge(context_)
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
self.context = original_context
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/uu/loggable.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module UU
|
6
|
+
module Loggable
|
7
|
+
def self.included(mod)
|
8
|
+
mod.extend self
|
9
|
+
end
|
10
|
+
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators \
|
14
|
+
:'::UU::Log.instance', \
|
15
|
+
:debug, :info, :warn, :error, :fatal, :with
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fluent-logger'
|
4
|
+
|
5
|
+
module UU
|
6
|
+
class LoggerFluent
|
7
|
+
class Formatter
|
8
|
+
def initialize(context, tag)
|
9
|
+
@context = context
|
10
|
+
@tag = tag
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :context
|
14
|
+
|
15
|
+
def call(severity, msg)
|
16
|
+
[@tag, {
|
17
|
+
log_level: severity,
|
18
|
+
**metadata,
|
19
|
+
message: msg,
|
20
|
+
**@context.context,
|
21
|
+
}]
|
22
|
+
end
|
23
|
+
|
24
|
+
def metadata
|
25
|
+
location = find_location
|
26
|
+
{
|
27
|
+
filename: File.basename(location.path),
|
28
|
+
method: location.label,
|
29
|
+
lineno: location.lineno,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
PATHS = %w[
|
34
|
+
/log.rb
|
35
|
+
/logger.rb
|
36
|
+
/loggable.rb
|
37
|
+
/forwardable.rb
|
38
|
+
].freeze
|
39
|
+
|
40
|
+
def find_location
|
41
|
+
caller_locations.find do |location_|
|
42
|
+
location_.path != __FILE__ &&
|
43
|
+
PATHS.none? { |path| location_.path.end_with?(path) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Nil
|
49
|
+
def post(*); end
|
50
|
+
end
|
51
|
+
|
52
|
+
NIL = Nil.new
|
53
|
+
|
54
|
+
@cached_logger = Hash.new do |hash, key|
|
55
|
+
hash[key] =
|
56
|
+
Fluent::Logger::FluentLogger.new(
|
57
|
+
nil,
|
58
|
+
nanosecond_precision: true,
|
59
|
+
**key,
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
class << self
|
64
|
+
attr_reader :cached_logger
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(cxt, host: ENV['FLUENTD_HOST'], port: ENV['FLUENTD_PORT'])
|
68
|
+
@logger =
|
69
|
+
if host
|
70
|
+
self.class.cached_logger[
|
71
|
+
{ host: host, **(port ? { port: port.to_i } : {}) }
|
72
|
+
]
|
73
|
+
else
|
74
|
+
NIL
|
75
|
+
end
|
76
|
+
@formatter = Formatter.new(cxt, 'tag')
|
77
|
+
end
|
78
|
+
|
79
|
+
attr_reader :logger
|
80
|
+
attr_accessor :formatter
|
81
|
+
|
82
|
+
def format_message(severity, message)
|
83
|
+
@formatter.call(severity, message)
|
84
|
+
end
|
85
|
+
|
86
|
+
%i[debug info warn error fatal].each do |severity|
|
87
|
+
define_method(severity) do |&block|
|
88
|
+
@logger.post(*format_message(severity, block.call))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'colorize'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module UU
|
8
|
+
class LoggerStderr < Logger
|
9
|
+
class Formatter
|
10
|
+
DECORATION = {
|
11
|
+
'UNKNOWN' => { color: :red, mode: :underline },
|
12
|
+
'FATAL' => { color: :red, mode: :underline },
|
13
|
+
'ERROR' => :red,
|
14
|
+
'WARN' => :yellow,
|
15
|
+
'INFO' => :default,
|
16
|
+
'DEBUG' => :light_black,
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
def initialize(context)
|
20
|
+
@context = context
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :context
|
24
|
+
|
25
|
+
def call(severity, time, _progname, msg)
|
26
|
+
loc = meaningful_location
|
27
|
+
short_severity = severity[0, 1]
|
28
|
+
time_format = time.utc.strftime('%T')
|
29
|
+
context = @context.context
|
30
|
+
context_msg = context.empty? ? '' : "#{context.to_json} "
|
31
|
+
|
32
|
+
"#{short_severity}]#{time_format}" \
|
33
|
+
"[#{loc[:filename]}##{loc[:method]}:#{loc[:lineno]}] " \
|
34
|
+
"#{context_msg}" \
|
35
|
+
"#{msg}\n".colorize(DECORATION[severity])
|
36
|
+
end
|
37
|
+
|
38
|
+
def meaningful_location
|
39
|
+
location = find_location
|
40
|
+
{
|
41
|
+
filename: File.basename(location.path),
|
42
|
+
method: location.label,
|
43
|
+
lineno: location.lineno,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
PATHS = %w[
|
48
|
+
/log.rb
|
49
|
+
/logger.rb
|
50
|
+
/loggable.rb
|
51
|
+
/forwardable.rb
|
52
|
+
].freeze
|
53
|
+
|
54
|
+
def find_location
|
55
|
+
caller_locations.find do |location_|
|
56
|
+
location_.path != __FILE__ &&
|
57
|
+
PATHS.none? { |path| location_.path.end_with?(path) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def initialize(context)
|
63
|
+
super($stderr, formatter: Formatter.new(context))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/uu/version.rb
CHANGED
data/lib/uu.rb
CHANGED
@@ -6,4 +6,9 @@ module UU
|
|
6
6
|
autoload :Remotable, 'uu/remotable'
|
7
7
|
autoload :RemoteServer, 'uu/remote_server'
|
8
8
|
autoload :Remote, 'uu/remote'
|
9
|
+
autoload :LoggerStderr, 'uu/logger_stderr'
|
10
|
+
autoload :LoggerFluent, 'uu/logger_fluent'
|
11
|
+
autoload :LogContext, 'uu/log_context'
|
12
|
+
autoload :Loggable, 'uu/loggable'
|
13
|
+
autoload :Log, 'uu/log'
|
9
14
|
end
|
data/uu.gemspec
CHANGED
@@ -24,7 +24,11 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
|
+
spec.add_dependency 'colorize'
|
28
|
+
spec.add_dependency 'fluent-logger'
|
27
29
|
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'byebug'
|
31
|
+
spec.add_development_dependency 'dotenv'
|
28
32
|
spec.add_development_dependency 'guard'
|
29
33
|
spec.add_development_dependency 'guard-bundler'
|
30
34
|
spec.add_development_dependency 'guard-rspec'
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minwoo Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fluent-logger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +52,34 @@ dependencies:
|
|
24
52
|
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: guard
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,6 +241,7 @@ executables: []
|
|
185
241
|
extensions: []
|
186
242
|
extra_rdoc_files: []
|
187
243
|
files:
|
244
|
+
- ".env.example"
|
188
245
|
- ".gitignore"
|
189
246
|
- ".rspec"
|
190
247
|
- ".rubocop.local.yml"
|
@@ -201,6 +258,11 @@ files:
|
|
201
258
|
- lib/drb/http0helper.rb
|
202
259
|
- lib/drb/http0serv.rb
|
203
260
|
- lib/uu.rb
|
261
|
+
- lib/uu/log.rb
|
262
|
+
- lib/uu/log_context.rb
|
263
|
+
- lib/uu/loggable.rb
|
264
|
+
- lib/uu/logger_fluent.rb
|
265
|
+
- lib/uu/logger_stderr.rb
|
204
266
|
- lib/uu/remotable.rb
|
205
267
|
- lib/uu/remote.rb
|
206
268
|
- lib/uu/remote_server.rb
|
@@ -225,8 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
287
|
- !ruby/object:Gem::Version
|
226
288
|
version: '0'
|
227
289
|
requirements: []
|
228
|
-
|
229
|
-
rubygems_version: 2.7.3
|
290
|
+
rubygems_version: 3.0.1
|
230
291
|
signing_key:
|
231
292
|
specification_version: 4
|
232
293
|
summary: UU
|