uu 0.2.0 → 0.2.1

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: 73d99f426e2be9be3bdf189a6462aca5c00d0465eb44c721679024d3e7e722f7
4
- data.tar.gz: f9213a72553bcc9e27e97e0e5e7816d0c3fc0581626b4db5be4ffa5989a7d6b1
3
+ metadata.gz: 8b7321eb0a2d0928bc20c2ee316c730243f3cb10b1fe4eda29d18d4d6507a81a
4
+ data.tar.gz: cedd60c4e5b0606e31e7f2aec8fe6db9dd426f00cf2c8d8e768d52a6268e0d58
5
5
  SHA512:
6
- metadata.gz: 4528a5cf71ccd0d87b4e6aa2e50b58f41cf297ab94dd801c10ac101b91d5f843fa095d40dcecc0bc8f927c759f40ca932f174da6cdd6d6bf366825624836405c
7
- data.tar.gz: 014d2f831489df7e18fe726f58bc680976f78cac8dfc4c55bab1d652bc24ec0c577ad5b324c7a7794810b395d64b9a8403f5ef8c9cb299c3c4a7b3a29131ff03
6
+ metadata.gz: 99a5ff6fc748b2f6632f76f987f53130127c427a81ad1ff4d92fbede3fb989703e6e19d15cfcdb3391455cf5a27b8d8be9fd4c7c4b1fe2a1778200175e310ce8
7
+ data.tar.gz: 2a48f11663da10487d6be1cc117dbb09add2325a5056c169684dc4d0fdaf6011ab1eb7cb2507dcaf07d00d822224e88805da8dc612f2d6fa3a4941ae95fb4796
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uu (0.2.0)
4
+ uu (0.2.1)
5
5
  colorize
6
6
  fluent-logger
7
7
 
data/lib/uu/log.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  module UU
4
4
  class Log
5
- include LogContext
6
5
  include Loggable
6
+ include LogContext
7
7
 
8
8
  def self.instance
9
9
  Thread.current[:logger] ||= new
@@ -10,6 +10,10 @@ module UU
10
10
  @context ||= {}
11
11
  end
12
12
 
13
+ def append_context(context_)
14
+ self.context = context.merge(context_)
15
+ end
16
+
13
17
  def with(context_)
14
18
  original_context = context
15
19
  self.context = context.merge(context_)
data/lib/uu/loggable.rb CHANGED
@@ -13,5 +13,7 @@ module UU
13
13
  def_delegators \
14
14
  :'::UU::Log.instance', \
15
15
  :debug, :info, :warn, :error, :fatal, :with
16
+
17
+ def_delegators :'::UU::LoggerFluent::Formatter', :tag, :tag=
16
18
  end
17
19
  end
@@ -5,19 +5,24 @@ require 'fluent-logger'
5
5
  module UU
6
6
  class LoggerFluent
7
7
  class Formatter
8
- def initialize(context, tag)
8
+ DEFAULT_TAG = 'fluentd'
9
+ @tag = ENV['FLUENTD_TAG'] || DEFAULT_TAG
10
+ class << self
11
+ attr_accessor :tag
12
+ end
13
+
14
+ def initialize(context)
9
15
  @context = context
10
- @tag = tag
11
16
  end
12
17
 
13
18
  attr_reader :context
14
19
 
15
20
  def call(severity, msg)
16
- [@tag, {
21
+ [self.class.tag, {
17
22
  log_level: severity,
18
23
  **metadata,
19
- message: msg,
20
24
  **@context.context,
25
+ **(msg.is_a?(Hash) ? msg : { message: msg }),
21
26
  }]
22
27
  end
23
28
 
@@ -51,29 +56,19 @@ module UU
51
56
 
52
57
  NIL = Nil.new
53
58
 
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
- )
59
+ def initialize(cxt, host: ENV['FLUENTD_HOST'], port: ENV['FLUENTD_PORT'])
60
+ @logger = create_logger(host, port)
61
+ @formatter = Formatter.new(cxt)
61
62
  end
62
63
 
63
- class << self
64
- attr_reader :cached_logger
65
- end
64
+ def create_logger(host, port)
65
+ return NIL unless host
66
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')
67
+ Fluent::Logger::FluentLogger.new(
68
+ nil,
69
+ nanosecond_precision: true,
70
+ host: host, **(port ? { port: port.to_i } : {})
71
+ )
77
72
  end
78
73
 
79
74
  attr_reader :logger
data/lib/uu/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UU
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minwoo Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-16 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize