semantic_logger 4.1.1 → 4.2.0
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.rb +6 -13
- data/lib/semantic_logger/ansi_colors.rb +10 -10
- data/lib/semantic_logger/appender.rb +42 -26
- data/lib/semantic_logger/appender/async.rb +179 -0
- data/lib/semantic_logger/appender/async_batch.rb +95 -0
- data/lib/semantic_logger/appender/bugsnag.rb +2 -1
- data/lib/semantic_logger/appender/elasticsearch.rb +113 -81
- data/lib/semantic_logger/appender/elasticsearch_http.rb +1 -3
- data/lib/semantic_logger/appender/file.rb +1 -3
- data/lib/semantic_logger/appender/graylog.rb +6 -5
- data/lib/semantic_logger/appender/honeybadger.rb +0 -2
- data/lib/semantic_logger/appender/http.rb +25 -10
- data/lib/semantic_logger/appender/kafka.rb +1 -3
- data/lib/semantic_logger/appender/mongodb.rb +1 -3
- data/lib/semantic_logger/appender/new_relic.rb +7 -3
- data/lib/semantic_logger/appender/sentry.rb +6 -7
- data/lib/semantic_logger/appender/splunk.rb +1 -2
- data/lib/semantic_logger/appender/splunk_http.rb +3 -4
- data/lib/semantic_logger/appender/syslog.rb +1 -3
- data/lib/semantic_logger/appender/tcp.rb +7 -9
- data/lib/semantic_logger/appender/udp.rb +0 -2
- data/lib/semantic_logger/appender/wrapper.rb +0 -2
- data/lib/semantic_logger/base.rb +76 -19
- data/lib/semantic_logger/formatters.rb +37 -0
- data/lib/semantic_logger/formatters/base.rb +10 -3
- data/lib/semantic_logger/formatters/json.rb +2 -6
- data/lib/semantic_logger/formatters/one_line.rb +18 -0
- data/lib/semantic_logger/formatters/raw.rb +8 -2
- data/lib/semantic_logger/formatters/signalfx.rb +169 -0
- data/lib/semantic_logger/log.rb +23 -14
- data/lib/semantic_logger/loggable.rb +88 -15
- data/lib/semantic_logger/logger.rb +0 -20
- data/lib/semantic_logger/metric/new_relic.rb +75 -0
- data/lib/semantic_logger/metric/signalfx.rb +123 -0
- data/lib/semantic_logger/{metrics → metric}/statsd.rb +20 -8
- data/lib/semantic_logger/processor.rb +67 -169
- data/lib/semantic_logger/semantic_logger.rb +7 -31
- data/lib/semantic_logger/subscriber.rb +32 -36
- data/lib/semantic_logger/utils.rb +47 -0
- data/lib/semantic_logger/version.rb +1 -1
- data/test/appender/async_batch_test.rb +61 -0
- data/test/appender/async_test.rb +45 -0
- data/test/appender/elasticsearch_http_test.rb +3 -3
- data/test/appender/elasticsearch_test.rb +211 -49
- data/test/appender/file_test.rb +9 -8
- data/test/appender/mongodb_test.rb +3 -3
- data/test/appender/newrelic_rpm.rb +6 -0
- data/test/appender/sentry_test.rb +3 -1
- data/test/appender/wrapper_test.rb +29 -0
- data/test/concerns/compatibility_test.rb +64 -60
- data/test/debug_as_trace_logger_test.rb +62 -77
- data/test/formatters/one_line_test.rb +61 -0
- data/test/formatters/signalfx_test.rb +200 -0
- data/test/formatters_test.rb +36 -0
- data/test/in_memory_appender.rb +9 -0
- data/test/in_memory_appender_helper.rb +43 -0
- data/test/in_memory_batch_appender.rb +9 -0
- data/test/in_memory_metrics_appender.rb +14 -0
- data/test/loggable_test.rb +15 -30
- data/test/logger_test.rb +181 -135
- data/test/measure_test.rb +212 -113
- data/test/metric/new_relic_test.rb +36 -0
- data/test/metric/signalfx_test.rb +78 -0
- data/test/semantic_logger_test.rb +58 -65
- data/test/test_helper.rb +19 -2
- metadata +33 -7
- data/lib/semantic_logger/metrics/new_relic.rb +0 -30
- data/lib/semantic_logger/metrics/udp.rb +0 -80
- data/test/mock_logger.rb +0 -29
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
module SemanticLogger
|
3
|
-
module Metrics
|
4
|
-
class Udp < Subscriber
|
5
|
-
attr_accessor :server, :separator, :udp_flags
|
6
|
-
attr_reader :socket
|
7
|
-
|
8
|
-
# Write metrics to in JSON format to Udp
|
9
|
-
#
|
10
|
-
# Parameters:
|
11
|
-
# server: [String]
|
12
|
-
# Host name and port to write UDP messages to
|
13
|
-
# Example:
|
14
|
-
# localhost:8125
|
15
|
-
#
|
16
|
-
# udp_flags: [Integer]
|
17
|
-
# Should be a bitwise OR of Socket::MSG_* constants.
|
18
|
-
# Default: 0
|
19
|
-
#
|
20
|
-
# Limitations:
|
21
|
-
# * UDP packet size is limited by the connected network and any routers etc
|
22
|
-
# that the message has to traverse. See https://en.wikipedia.org/wiki/Maximum_transmission_unit
|
23
|
-
#
|
24
|
-
# Example:
|
25
|
-
# subscriber = SemanticLogger::Metrics::Udp.new(server: 'localhost:8125')
|
26
|
-
# SemanticLogger.on_metric(subscriber)
|
27
|
-
def initialize(options = {}, &block)
|
28
|
-
options = options.dup
|
29
|
-
@server = options.delete(:server)
|
30
|
-
@udp_flags = options.delete(:udp_flags) || 0
|
31
|
-
raise(ArgumentError, 'Missing mandatory argument: :server') unless @server
|
32
|
-
|
33
|
-
super(options, &block)
|
34
|
-
reopen
|
35
|
-
end
|
36
|
-
|
37
|
-
# After forking an active process call #reopen to re-open
|
38
|
-
# open the handles to resources
|
39
|
-
def reopen
|
40
|
-
close
|
41
|
-
@socket = UDPSocket.new
|
42
|
-
host, port = server.split(':')
|
43
|
-
@socket.connect(host, port)
|
44
|
-
end
|
45
|
-
|
46
|
-
def call(log)
|
47
|
-
metric = log.metric
|
48
|
-
if duration = log.duration
|
49
|
-
@statsd.timing(metric, duration)
|
50
|
-
else
|
51
|
-
amount = (log.metric_amount || 1).round
|
52
|
-
if amount < 0
|
53
|
-
amount.times { @statsd.decrement(metric) }
|
54
|
-
else
|
55
|
-
amount.times { @statsd.increment(metric) }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
@socket.send(data, udp_flags)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Flush is called by the semantic_logger during shutdown.
|
62
|
-
def flush
|
63
|
-
@socket.flush if @socket
|
64
|
-
end
|
65
|
-
|
66
|
-
# Close is called during shutdown, or with reopen
|
67
|
-
def close
|
68
|
-
@socket.close if @socket
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
# Returns [SemanticLogger::Formatters::Default] formatter default for this Appender
|
74
|
-
def default_formatter
|
75
|
-
SemanticLogger::Formatters::Json.new
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
data/test/mock_logger.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Looks like a standard Ruby Logger or Rails Logger
|
2
|
-
# Except that it stores the last logged entry in the instance variable: message
|
3
|
-
class MockLogger
|
4
|
-
attr_accessor :message
|
5
|
-
|
6
|
-
Logger::Severity.constants.each do |level|
|
7
|
-
class_eval <<-EOT, __FILE__, __LINE__
|
8
|
-
def #{level.downcase}(message = nil, progname = nil)
|
9
|
-
if message
|
10
|
-
self.message = message
|
11
|
-
elsif block_given?
|
12
|
-
self.message = yield
|
13
|
-
else
|
14
|
-
self.message = progname
|
15
|
-
end
|
16
|
-
self.message
|
17
|
-
end
|
18
|
-
|
19
|
-
def #{level}?
|
20
|
-
@true
|
21
|
-
end
|
22
|
-
EOT
|
23
|
-
end
|
24
|
-
|
25
|
-
def flush
|
26
|
-
true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|