semantic_logger 4.5.0 → 4.6.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/semantic_logger/ansi_colors.rb +0 -10
- data/lib/semantic_logger/appender.rb +34 -43
- data/lib/semantic_logger/appender/async.rb +1 -0
- data/lib/semantic_logger/appender/elasticsearch.rb +2 -1
- data/lib/semantic_logger/appender/splunk.rb +1 -0
- data/lib/semantic_logger/appender/splunk_http.rb +1 -0
- data/lib/semantic_logger/appender/tcp.rb +4 -4
- data/lib/semantic_logger/appenders.rb +2 -23
- data/lib/semantic_logger/base.rb +1 -13
- data/lib/semantic_logger/formatters/base.rb +8 -4
- data/lib/semantic_logger/formatters/color.rb +2 -7
- data/lib/semantic_logger/formatters/fluentd.rb +5 -16
- data/lib/semantic_logger/formatters/json.rb +2 -4
- data/lib/semantic_logger/formatters/raw.rb +9 -4
- data/lib/semantic_logger/formatters/signalfx.rb +5 -13
- data/lib/semantic_logger/log.rb +0 -16
- data/lib/semantic_logger/semantic_logger.rb +15 -3
- data/lib/semantic_logger/subscriber.rb +8 -2
- data/lib/semantic_logger/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bafa2ce169caccee2a851d7ad8a5b5b7d1e3104fa6894ff8c21756e78f59621f
|
4
|
+
data.tar.gz: 110b972e305d619672761cbc34652556615d79015824c1c538c8819e69a01ec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec35476ebcc1af48f5b056b7f109652d86c437da257e70e82a2514dfdbf280d12cc7acd29c9c09a49ed76fbd7d7b09ac200a9d3477089685e4e2a45b9d899fe
|
7
|
+
data.tar.gz: 501e8708e49344fb056e9959c8d77b2a907fbbfe938893a5000edbb1dd9f57d710abd341e5b0566f7aafdb624ea424a38815de89fa845fcdaf01563aa41c0d72
|
@@ -11,15 +11,5 @@ module SemanticLogger
|
|
11
11
|
MAGENTA = "\e[35m".freeze
|
12
12
|
CYAN = "\e[36m".freeze
|
13
13
|
WHITE = "\e[37m".freeze
|
14
|
-
|
15
|
-
# DEPRECATED - NOT USED
|
16
|
-
LEVEL_MAP = {
|
17
|
-
trace: MAGENTA,
|
18
|
-
debug: GREEN,
|
19
|
-
info: CYAN,
|
20
|
-
warn: BOLD,
|
21
|
-
error: RED,
|
22
|
-
fatal: RED
|
23
|
-
}.freeze
|
24
14
|
end
|
25
15
|
end
|
@@ -23,71 +23,62 @@ module SemanticLogger
|
|
23
23
|
autoload :Wrapper, 'semantic_logger/appender/wrapper'
|
24
24
|
# @formatter:on
|
25
25
|
|
26
|
-
# DEPRECATED, use SemanticLogger::AnsiColors
|
27
|
-
AnsiColors = SemanticLogger::AnsiColors
|
28
|
-
|
29
|
-
# DEPRECATED: use SemanticLogger::Formatters::Color.new
|
30
|
-
def self.colorized_formatter
|
31
|
-
SemanticLogger::Formatters::Color.new
|
32
|
-
end
|
33
|
-
|
34
|
-
# DEPRECATED: use SemanticLogger::Formatters::Json.new
|
35
|
-
def self.json_formatter
|
36
|
-
SemanticLogger::Formatters::Json.new
|
37
|
-
end
|
38
|
-
|
39
26
|
# Returns [SemanticLogger::Subscriber] appender for the supplied options
|
40
|
-
def self.factory(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
ASYNC_OPTION_KEYS.each { |key| proxy_options[key] = options.delete(key) if options.key?(key) }
|
48
|
-
|
49
|
-
appender = build(options, &block)
|
27
|
+
def self.factory(async: false, batch: nil,
|
28
|
+
max_queue_size: 10_000, lag_check_interval: 1_000, lag_threshold_s: 30,
|
29
|
+
batch_size: 300, batch_seconds: 5,
|
30
|
+
**args,
|
31
|
+
&block
|
32
|
+
)
|
33
|
+
appender = build(**args, &block)
|
50
34
|
|
51
35
|
# If appender implements #batch, then it should use the batch proxy by default.
|
52
36
|
batch = true if batch.nil? && appender.respond_to?(:batch)
|
53
37
|
|
54
38
|
if batch == true
|
55
|
-
|
56
|
-
|
39
|
+
Appender::AsyncBatch.new(
|
40
|
+
appender: appender,
|
41
|
+
max_queue_size: max_queue_size,
|
42
|
+
lag_threshold_s: lag_threshold_s,
|
43
|
+
batch_size: batch_size,
|
44
|
+
batch_seconds: batch_seconds
|
45
|
+
)
|
57
46
|
elsif async == true
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
Appender::Async.new(
|
48
|
+
appender: appender,
|
49
|
+
max_queue_size: max_queue_size,
|
50
|
+
lag_check_interval: lag_check_interval,
|
51
|
+
lag_threshold_s: lag_threshold_s
|
52
|
+
)
|
62
53
|
else
|
63
54
|
appender
|
64
55
|
end
|
65
56
|
end
|
66
57
|
|
67
|
-
ASYNC_OPTION_KEYS = %i[max_queue_size lag_threshold_s batch_size batch_seconds lag_check_interval].freeze
|
68
|
-
|
69
58
|
# Returns [Subscriber] instance from the supplied options.
|
70
|
-
def self.build(
|
71
|
-
if
|
72
|
-
SemanticLogger::Appender::File.new(
|
73
|
-
elsif
|
59
|
+
def self.build(io: nil, file_name: nil, appender: nil, metric: nil, logger: nil, **args, &block)
|
60
|
+
if io || file_name
|
61
|
+
SemanticLogger::Appender::File.new(io: io, file_name: file_name, **args, &block)
|
62
|
+
elsif logger
|
63
|
+
SemanticLogger::Appender::Wrapper.new(logger: logger, **args, &block)
|
64
|
+
elsif appender
|
74
65
|
if appender.is_a?(Symbol)
|
75
|
-
SemanticLogger::Utils.constantize_symbol(appender).new(
|
66
|
+
SemanticLogger::Utils.constantize_symbol(appender).new(**args)
|
76
67
|
elsif appender.is_a?(Subscriber)
|
77
68
|
appender
|
78
69
|
else
|
79
70
|
raise(ArgumentError, "Parameter :appender must be either a Symbol or an object derived from SemanticLogger::Subscriber, not: #{appender.inspect}")
|
80
71
|
end
|
81
|
-
elsif
|
82
|
-
if
|
83
|
-
SemanticLogger::Utils.constantize_symbol(
|
84
|
-
elsif
|
85
|
-
|
72
|
+
elsif metric
|
73
|
+
if metric.is_a?(Symbol)
|
74
|
+
SemanticLogger::Utils.constantize_symbol(metric, 'SemanticLogger::Metric').new(**args)
|
75
|
+
elsif metric.is_a?(Subscriber)
|
76
|
+
metric
|
86
77
|
else
|
87
78
|
raise(ArgumentError, "Parameter :metric must be either a Symbol or an object derived from SemanticLogger::Subscriber, not: #{appender.inspect}")
|
88
79
|
end
|
89
|
-
|
90
|
-
|
80
|
+
else
|
81
|
+
raise(ArgumentError, 'To create an appender it must supply one of the following: :io, :file_name, :appender, :metric, or :logger')
|
91
82
|
end
|
92
83
|
end
|
93
84
|
|
@@ -15,6 +15,7 @@ module SemanticLogger
|
|
15
15
|
def_delegator :@appender, :filter
|
16
16
|
def_delegator :@appender, :host
|
17
17
|
def_delegator :@appender, :application
|
18
|
+
def_delegator :@appender, :environment
|
18
19
|
def_delegator :@appender, :level
|
19
20
|
def_delegator :@appender, :level=
|
20
21
|
def_delegator :@appender, :logger
|
@@ -131,6 +131,7 @@ module SemanticLogger
|
|
131
131
|
formatter: nil,
|
132
132
|
filter: nil,
|
133
133
|
application: nil,
|
134
|
+
environment: nil,
|
134
135
|
host: nil,
|
135
136
|
metrics: false,
|
136
137
|
**elasticsearch_args,
|
@@ -144,7 +145,7 @@ module SemanticLogger
|
|
144
145
|
@elasticsearch_args[:url] = url if url && !elasticsearch_args[:hosts]
|
145
146
|
@elasticsearch_args[:logger] = logger
|
146
147
|
|
147
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, metrics: false, &block)
|
148
|
+
super(level: level, formatter: formatter, filter: filter, application: application, environment: environment, host: host, metrics: false, &block)
|
148
149
|
reopen
|
149
150
|
end
|
150
151
|
|
@@ -89,7 +89,7 @@ module SemanticLogger
|
|
89
89
|
# where multiple sends are expected during a single response
|
90
90
|
# Default: true
|
91
91
|
#
|
92
|
-
# :connect_retry_count [
|
92
|
+
# :connect_retry_count [Integer]
|
93
93
|
# Number of times to retry connecting when a connection fails
|
94
94
|
# Default: 10
|
95
95
|
#
|
@@ -97,7 +97,7 @@ module SemanticLogger
|
|
97
97
|
# Number of seconds between connection retry attempts after the first failed attempt
|
98
98
|
# Default: 0.5
|
99
99
|
#
|
100
|
-
# :retry_count [
|
100
|
+
# :retry_count [Integer]
|
101
101
|
# Number of times to retry when calling #retry_on_connection_failure
|
102
102
|
# This is independent of :connect_retry_count which still applies with
|
103
103
|
# connection failures. This retry controls upto how many times to retry the
|
@@ -182,7 +182,7 @@ module SemanticLogger
|
|
182
182
|
# connect_retry_count: 5
|
183
183
|
# )
|
184
184
|
def initialize(separator: "\n",
|
185
|
-
level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false,
|
185
|
+
level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: false,
|
186
186
|
**tcp_client_args, &block)
|
187
187
|
@separator = separator
|
188
188
|
@tcp_client_args = tcp_client_args
|
@@ -191,7 +191,7 @@ module SemanticLogger
|
|
191
191
|
Net::TCPClient.logger = logger
|
192
192
|
Net::TCPClient.logger.name = 'Net::TCPClient'
|
193
193
|
|
194
|
-
super(level: level, formatter: formatter, filter: filter, application: application, host: host, &block)
|
194
|
+
super(level: level, formatter: formatter, filter: filter, application: application, environment: environment, host: host, &block)
|
195
195
|
reopen
|
196
196
|
end
|
197
197
|
|
@@ -8,9 +8,8 @@ module SemanticLogger
|
|
8
8
|
@logger.name = self.class.name
|
9
9
|
end
|
10
10
|
|
11
|
-
def add(
|
12
|
-
|
13
|
-
appender = SemanticLogger::Appender.factory(options, &block)
|
11
|
+
def add(**args, &block)
|
12
|
+
appender = SemanticLogger::Appender.factory(**args, &block)
|
14
13
|
self << appender
|
15
14
|
appender
|
16
15
|
end
|
@@ -65,25 +64,5 @@ module SemanticLogger
|
|
65
64
|
end
|
66
65
|
logger.trace 'All appenders re-opened'
|
67
66
|
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
# Backward compatibility
|
72
|
-
def convert_old_appender_args(appender, level)
|
73
|
-
options = {}
|
74
|
-
options[:level] = level if level
|
75
|
-
|
76
|
-
if appender.is_a?(String)
|
77
|
-
options[:file_name] = appender
|
78
|
-
elsif appender.is_a?(IO)
|
79
|
-
options[:io] = appender
|
80
|
-
elsif appender.is_a?(Symbol) || appender.is_a?(Subscriber)
|
81
|
-
options[:appender] = appender
|
82
|
-
else
|
83
|
-
options[:logger] = appender
|
84
|
-
end
|
85
|
-
warn "[DEPRECATED] SemanticLogger.add_appender parameters have changed. Please use: #{options.inspect}"
|
86
|
-
options
|
87
|
-
end
|
88
67
|
end
|
89
68
|
end
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -233,23 +233,11 @@ module SemanticLogger
|
|
233
233
|
SemanticLogger.silence(new_level, &block)
|
234
234
|
end
|
235
235
|
|
236
|
-
#
|
236
|
+
# :nodoc:
|
237
237
|
def fast_tag(tag, &block)
|
238
238
|
SemanticLogger.fast_tag(tag, &block)
|
239
239
|
end
|
240
240
|
|
241
|
-
# :nodoc:
|
242
|
-
def with_payload(payload, &block)
|
243
|
-
warn '#with_payload is deprecated, use SemanticLogger.named_tagged'
|
244
|
-
SemanticLogger.named_tagged(payload, &block)
|
245
|
-
end
|
246
|
-
|
247
|
-
# :nodoc:
|
248
|
-
def payload
|
249
|
-
warn '#payload is deprecated, use SemanticLogger.named_tags'
|
250
|
-
SemanticLogger.named_tags
|
251
|
-
end
|
252
|
-
|
253
241
|
# Write log data to underlying data storage
|
254
242
|
def log(_log_)
|
255
243
|
raise NotImplementedError, 'Logging Appender must implement #log(log)'
|
@@ -2,11 +2,11 @@ require 'time'
|
|
2
2
|
module SemanticLogger
|
3
3
|
module Formatters
|
4
4
|
class Base
|
5
|
-
attr_accessor :time_format, :log_host, :log_application, :precision
|
5
|
+
attr_accessor :time_format, :log_host, :log_application, :log_environment, :precision
|
6
6
|
|
7
7
|
# Time precision varies by Ruby interpreter
|
8
8
|
# JRuby 9.1.8.0 supports microseconds
|
9
|
-
PRECISION
|
9
|
+
PRECISION =
|
10
10
|
if defined?(JRuby)
|
11
11
|
if JRUBY_VERSION.to_f >= 9.1
|
12
12
|
maint = JRUBY_VERSION.match(/\A\d+\.\d+\.(\d+)\./)[1].to_i
|
@@ -34,11 +34,15 @@ module SemanticLogger
|
|
34
34
|
# precision: [Integer]
|
35
35
|
# How many fractional digits to log times with.
|
36
36
|
# Default: PRECISION (6, except on older JRuby, where 3)
|
37
|
-
def initialize(time_format: nil,
|
37
|
+
def initialize(time_format: nil,
|
38
|
+
log_host: true,
|
39
|
+
log_application: true,
|
40
|
+
log_environment: true,
|
38
41
|
precision: PRECISION)
|
39
42
|
@time_format = time_format || self.class.build_time_format(precision)
|
40
43
|
@log_host = log_host
|
41
44
|
@log_application = log_application
|
45
|
+
@log_environment = log_environment
|
42
46
|
@precision = precision
|
43
47
|
end
|
44
48
|
|
@@ -48,7 +52,7 @@ module SemanticLogger
|
|
48
52
|
# precision: [Integer]
|
49
53
|
# How many fractional digits to log times with.
|
50
54
|
# Default: PRECISION (6, except on older JRuby, where 3)
|
51
|
-
def self.build_time_format(precision=PRECISION)
|
55
|
+
def self.build_time_format(precision = PRECISION)
|
52
56
|
"%Y-%m-%d %H:%M:%S.%#{precision}N"
|
53
57
|
end
|
54
58
|
|
@@ -70,15 +70,10 @@ module SemanticLogger
|
|
70
70
|
#
|
71
71
|
# color_map: [Hash | SemanticLogger::Formatters::Color::ColorMap]
|
72
72
|
# ColorMaps each of the log levels to a color
|
73
|
-
def initialize(ap: {multiline: false},
|
74
|
-
color_map: ColorMap.new,
|
75
|
-
time_format: nil,
|
76
|
-
log_host: false,
|
77
|
-
log_application: false,
|
78
|
-
precision: PRECISION)
|
73
|
+
def initialize(ap: {multiline: false}, color_map: ColorMap.new, **args)
|
79
74
|
@ai_options = ap
|
80
75
|
@color_map = color_map.is_a?(ColorMap) ? color_map : ColorMap.new(color_map)
|
81
|
-
super(
|
76
|
+
super(**args)
|
82
77
|
end
|
83
78
|
|
84
79
|
def level
|
@@ -2,18 +2,18 @@ require 'json'
|
|
2
2
|
|
3
3
|
module SemanticLogger
|
4
4
|
module Formatters
|
5
|
-
# Fluentd is similar to SemanticLogger::Formatters::Json but with log
|
5
|
+
# Fluentd is similar to SemanticLogger::Formatters::Json but with log levels that are recognized
|
6
6
|
# by kubernetes fluentd.
|
7
7
|
class Fluentd < Json
|
8
8
|
attr_reader :need_process_info
|
9
9
|
|
10
|
-
def initialize(
|
10
|
+
def initialize(time_format: :rfc_3339, time_key: :time, need_process_info: false, **args)
|
11
11
|
@need_process_info = need_process_info
|
12
|
-
super(
|
12
|
+
super(time_format: time_format, time_key: time_key, **args)
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
hash['severity']
|
15
|
+
def level
|
16
|
+
hash['severity'] = log.level
|
17
17
|
hash['severity_index'] = log.level_index
|
18
18
|
end
|
19
19
|
|
@@ -21,17 +21,6 @@ module SemanticLogger
|
|
21
21
|
# Ignore fields: pid, thread, file and line by default
|
22
22
|
super() if need_process_info
|
23
23
|
end
|
24
|
-
|
25
|
-
def call(log, logger)
|
26
|
-
self.hash = {}
|
27
|
-
self.log = log
|
28
|
-
self.logger = logger
|
29
|
-
|
30
|
-
host; application; time; severity; process_info; duration; tags; named_tags; name; message; payload; exception; metric
|
31
|
-
hash
|
32
|
-
|
33
|
-
hash.to_json
|
34
|
-
end
|
35
24
|
end
|
36
25
|
end
|
37
26
|
end
|
@@ -3,10 +3,8 @@ module SemanticLogger
|
|
3
3
|
module Formatters
|
4
4
|
class Json < Raw
|
5
5
|
# Default JSON time format is ISO8601
|
6
|
-
def initialize(time_format: :iso_8601,
|
7
|
-
|
8
|
-
super(time_format: time_format, log_host: log_host, log_application: log_application, time_key: time_key,
|
9
|
-
precision: precision)
|
6
|
+
def initialize(time_format: :iso_8601, time_key: :timestamp, **args)
|
7
|
+
super(time_format: time_format, time_key: time_key, **args)
|
10
8
|
end
|
11
9
|
|
12
10
|
# Returns log messages in JSON format
|
@@ -6,9 +6,9 @@ module SemanticLogger
|
|
6
6
|
attr_accessor :hash, :log, :logger, :time_key
|
7
7
|
|
8
8
|
# By default Raw formatter does not reformat the time
|
9
|
-
def initialize(time_format: :none,
|
9
|
+
def initialize(time_format: :none, time_key: :time, **args)
|
10
10
|
@time_key = time_key
|
11
|
-
super(time_format: time_format,
|
11
|
+
super(time_format: time_format, **args)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Host name
|
@@ -18,7 +18,12 @@ module SemanticLogger
|
|
18
18
|
|
19
19
|
# Application name
|
20
20
|
def application
|
21
|
-
hash[:application] = logger.application if log_application && logger.application
|
21
|
+
hash[:application] = logger.application if log_application && logger && logger.application
|
22
|
+
end
|
23
|
+
|
24
|
+
# Environment
|
25
|
+
def environment
|
26
|
+
hash[:environment] = logger.environment if log_environment && logger && logger.environment
|
22
27
|
end
|
23
28
|
|
24
29
|
# Date & time
|
@@ -104,7 +109,7 @@ module SemanticLogger
|
|
104
109
|
self.log = log
|
105
110
|
self.logger = logger
|
106
111
|
|
107
|
-
host; application; time; level; process_info; duration; tags; named_tags; name; message; payload; exception; metric
|
112
|
+
host; application; environment; time; level; process_info; duration; tags; named_tags; name; message; payload; exception; metric
|
108
113
|
hash
|
109
114
|
end
|
110
115
|
end
|
@@ -2,29 +2,21 @@ require 'json'
|
|
2
2
|
module SemanticLogger
|
3
3
|
module Formatters
|
4
4
|
class Signalfx < Base
|
5
|
-
attr_accessor :token, :dimensions, :hash, :log, :logger, :gauge_name, :counter_name
|
5
|
+
attr_accessor :token, :dimensions, :hash, :log, :logger, :gauge_name, :counter_name
|
6
6
|
|
7
7
|
def initialize(token:,
|
8
8
|
dimensions: nil,
|
9
|
-
log_host: true,
|
10
|
-
log_application: true,
|
11
9
|
gauge_name: 'Application.average',
|
12
10
|
counter_name: 'Application.counter',
|
13
|
-
|
14
|
-
|
11
|
+
time_format: :ms,
|
12
|
+
**args)
|
15
13
|
|
16
14
|
@token = token
|
17
15
|
@dimensions = dimensions.map(&:to_sym) if dimensions
|
18
16
|
@gauge_name = gauge_name
|
19
17
|
@counter_name = counter_name
|
20
18
|
|
21
|
-
|
22
|
-
@environment = defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
23
|
-
elsif environment
|
24
|
-
@environment = environment
|
25
|
-
end
|
26
|
-
|
27
|
-
super(time_format: :ms, log_host: log_host, log_application: log_application, precision: precision)
|
19
|
+
super(time_format: time_format, **args)
|
28
20
|
end
|
29
21
|
|
30
22
|
# Create SignalFx friendly metric.
|
@@ -80,7 +72,7 @@ module SemanticLogger
|
|
80
72
|
end
|
81
73
|
h[:host] = logger.host if log_host && logger.host
|
82
74
|
h[:application] = logger.application if log_application && logger.application
|
83
|
-
h[:environment] = environment if environment
|
75
|
+
h[:environment] = logger.environment if log_environment && logger.environment
|
84
76
|
end
|
85
77
|
|
86
78
|
# Returns [Hash] log message in Signalfx format.
|
data/lib/semantic_logger/log.rb
CHANGED
@@ -279,22 +279,6 @@ module SemanticLogger
|
|
279
279
|
!(payload.nil? || (payload.respond_to?(:empty?) && payload.empty?))
|
280
280
|
end
|
281
281
|
|
282
|
-
# DEPRECATED
|
283
|
-
alias has_payload? payload?
|
284
|
-
|
285
|
-
# DEPRECATED
|
286
|
-
def formatted_time
|
287
|
-
time.strftime(Formatters::Base.build_time_format)
|
288
|
-
end
|
289
|
-
|
290
|
-
DeprecatedLogger = Struct.new(:host, :application)
|
291
|
-
|
292
|
-
# DEPRECATED: Use SemanticLogger::Formatters::Raw
|
293
|
-
def to_h(host = SemanticLogger.host, application = SemanticLogger.application)
|
294
|
-
logger = DeprecatedLogger.new(host, application)
|
295
|
-
SemanticLogger::Formatters::Raw.new.call(self, logger)
|
296
|
-
end
|
297
|
-
|
298
282
|
# Lazy initializes the context hash and assigns a key value pair.
|
299
283
|
def set_context(key, value)
|
300
284
|
(self.context ||= {})[key] = value
|
@@ -71,7 +71,19 @@ module SemanticLogger
|
|
71
71
|
@application = application
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
# Returns [String] name of this environment for logging purposes
|
75
|
+
# Note: Not all appenders use `environment`
|
76
|
+
def self.environment
|
77
|
+
@environment
|
78
|
+
end
|
79
|
+
|
80
|
+
# Override the default environment
|
81
|
+
def self.environment=(environment)
|
82
|
+
@environment = environment
|
83
|
+
end
|
84
|
+
|
85
|
+
@application = ENV['SEMANTIC_LOGGER_APP'] || 'Semantic Logger'
|
86
|
+
@environment = ENV['SEMANTIC_LOGGER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
75
87
|
|
76
88
|
# Add a new logging appender as a new destination for all log messages
|
77
89
|
# emitted from Semantic Logger
|
@@ -151,8 +163,8 @@ module SemanticLogger
|
|
151
163
|
# logger = SemanticLogger['Example']
|
152
164
|
# logger.info "Hello World"
|
153
165
|
# logger.debug("Login time", user: 'Joe', duration: 100, ip_address: '127.0.0.1')
|
154
|
-
def self.add_appender(
|
155
|
-
appender = Logger.processor.appenders.add(
|
166
|
+
def self.add_appender(**args, &block)
|
167
|
+
appender = Logger.processor.appenders.add(**args, &block)
|
156
168
|
# Start appender thread if it is not already running
|
157
169
|
Logger.processor.start
|
158
170
|
appender
|
@@ -5,7 +5,7 @@ module SemanticLogger
|
|
5
5
|
class Subscriber < SemanticLogger::Base
|
6
6
|
# Every appender has its own formatter
|
7
7
|
attr_reader :formatter
|
8
|
-
attr_writer :application, :host, :logger, :metrics
|
8
|
+
attr_writer :application, :environment, :host, :logger, :metrics
|
9
9
|
|
10
10
|
# Returns the current log level if set, otherwise it logs everything it receives.
|
11
11
|
def level
|
@@ -32,6 +32,11 @@ module SemanticLogger
|
|
32
32
|
@application || SemanticLogger.application
|
33
33
|
end
|
34
34
|
|
35
|
+
# Allow environment name to be set globally or on a per subscriber basis.
|
36
|
+
def environment
|
37
|
+
@environment || SemanticLogger.environment
|
38
|
+
end
|
39
|
+
|
35
40
|
# Allow host name to be set globally or on a per subscriber basis.
|
36
41
|
def host
|
37
42
|
@host || SemanticLogger.host
|
@@ -92,9 +97,10 @@ module SemanticLogger
|
|
92
97
|
# metrics: [Boolean]
|
93
98
|
# Whether to log metric only entries with this subscriber.
|
94
99
|
# Default: false
|
95
|
-
def initialize(level: nil, formatter: nil, filter: nil, application: nil, host: nil, metrics: false, &block)
|
100
|
+
def initialize(level: nil, formatter: nil, filter: nil, application: nil, environment: nil, host: nil, metrics: false, &block)
|
96
101
|
self.formatter = block || formatter
|
97
102
|
@application = application
|
103
|
+
@environment = environment
|
98
104
|
@host = host
|
99
105
|
@metrics = metrics
|
100
106
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -102,11 +102,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '2.3'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- - "
|
105
|
+
- - ">"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: 1.3.1
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.0.
|
109
|
+
rubygems_version: 3.0.3
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Feature rich logging framework, and replacement for existing Ruby & Rails
|