logjam_agent 0.33.3 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logjam_agent/buffered_logger.rb +24 -22
- data/lib/logjam_agent/logging_attributes.rb +33 -0
- data/lib/logjam_agent/railtie.rb +9 -15
- data/lib/logjam_agent/syslog_like_formatter.rb +1 -40
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent.rb +7 -7
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3cc7aaf7edaf4f4a2ab8b0cbb9922449fcadf2ca515add756d9052ca30f104a
|
4
|
+
data.tar.gz: 9c648bc52c752ebd7a394b9b74f5a2d2ff1f92aff23393a37dcd714b324339ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29350bbdb8502910e181ee155a369d0a16793a916430b4150aee46e956e931aac3ba697d9066e0bc14c6826918b1085022b492e13d283f3f49b19cd10a2a2c22
|
7
|
+
data.tar.gz: 1798f1ce01b48e947fd4b54455c8f446551e474b93120fed751eefc0ea72584e68b610d7d2cbe4fa7f46b4f6d97a9a82d50049339cb477b5dfad62b9a57c005f
|
@@ -27,17 +27,21 @@ end
|
|
27
27
|
module LogjamAgent
|
28
28
|
class BufferedLogger < ActiveSupport::Logger
|
29
29
|
|
30
|
-
attr_accessor :formatter
|
31
|
-
|
32
30
|
# for backwards compatibility. needs to go away.
|
33
31
|
include LogjamAgent::RequestHandling
|
34
32
|
|
35
33
|
def initialize(*args)
|
36
34
|
super(*args)
|
37
|
-
|
35
|
+
# make sure we always have a formatter
|
36
|
+
self.formatter = Logger::Formatter.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def formatter=(formatter)
|
40
|
+
super
|
41
|
+
@formatter.extend LoggingAttributes
|
38
42
|
end
|
39
43
|
|
40
|
-
def add(severity, message = nil, progname = nil,
|
44
|
+
def add(severity, message = nil, progname = nil, &block)
|
41
45
|
return if level > severity
|
42
46
|
message = progname if message.nil?
|
43
47
|
progname = nil
|
@@ -53,18 +57,12 @@ module LogjamAgent
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
log_to_log_device = LogjamAgent.log_to_log_device?(severity, message)
|
56
|
-
|
60
|
+
attributes = formatter.render_attributes
|
61
|
+
message = "[#{attributes}] #{message}" if attributes
|
57
62
|
time = Time.now
|
58
63
|
if log_to_log_device
|
59
|
-
formatted_message = formatter.call(severity, time, progname, message)
|
60
|
-
|
61
|
-
buffer << formatted_message << "\n"
|
62
|
-
auto_flush
|
63
|
-
elsif @log # @log is a logger (or nil for rails 4)
|
64
|
-
@log << "#{formatted_message}\n"
|
65
|
-
elsif @logdev
|
66
|
-
@logdev.write(formatted_message)
|
67
|
-
end
|
64
|
+
formatted_message = formatter.call(format_severity(severity), time, progname, message)
|
65
|
+
@logdev.write(formatted_message)
|
68
66
|
end
|
69
67
|
request.add_line(severity, time, message) if request
|
70
68
|
message
|
@@ -72,18 +70,22 @@ module LogjamAgent
|
|
72
70
|
|
73
71
|
def logdev=(log_device)
|
74
72
|
raise "cannot connect logger to new log device" unless log_device.respond_to?(:write)
|
75
|
-
|
76
|
-
|
77
|
-
else
|
78
|
-
(@log||self).instance_eval do
|
79
|
-
raise "cannot set log device" unless defined?(@logdev)
|
80
|
-
@logdev = log_device
|
81
|
-
end
|
82
|
-
end
|
73
|
+
raise "cannot set log device" unless defined?(@logdev)
|
74
|
+
@logdev = log_device
|
83
75
|
end
|
84
76
|
|
85
77
|
private
|
86
78
|
|
79
|
+
SEV_LABEL_CACHE = SEV_LABEL.map{|sev| "%-5s" % sev}
|
80
|
+
|
81
|
+
def format_severity(severity)
|
82
|
+
if severity.is_a?(String)
|
83
|
+
"%-5s" % severity
|
84
|
+
else
|
85
|
+
SEV_LABEL_CACHE[severity] || 'ALIEN'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
87
89
|
def detect_logged_exception(message)
|
88
90
|
(matcher = LogjamAgent.exception_matcher) && message[matcher]
|
89
91
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module LogjamAgent
|
2
|
+
module LoggingAttributes
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def attributes=(attributes)
|
7
|
+
Thread.current.thread_variable_set(:__logjam_agent_logging_attributes__, attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def attributes
|
11
|
+
Thread.current.thread_variable_get(:__logjam_agent_logging_attributes__) ||
|
12
|
+
Thread.current.thread_variable_set(:__logjam_agent_logging_attributes__, [])
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_attribute(name, value)
|
16
|
+
if attribute = attributes.detect{|n,v| n == name}
|
17
|
+
attribute[1] = value
|
18
|
+
else
|
19
|
+
attributes << [name, value]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset_attributes
|
24
|
+
self.attributes = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def render_attributes
|
28
|
+
attrs = attributes.select{|k,v| !k.nil? }
|
29
|
+
attrs.empty? ? nil : attrs.map{|k,v| "#{k}=#{v}"}.join(" ")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/logjam_agent/railtie.rb
CHANGED
@@ -8,9 +8,9 @@ module LogjamAgent
|
|
8
8
|
autoload :Middleware, 'logjam_agent/middleware'
|
9
9
|
|
10
10
|
class Railtie < Rails::Railtie
|
11
|
+
|
11
12
|
def logjam_log_path(app)
|
12
|
-
|
13
|
-
(Rails::VERSION::STRING < "3.1" ? paths.log.to_a : paths['log']).first.to_s
|
13
|
+
app.config.paths['log'].first.to_s
|
14
14
|
end
|
15
15
|
|
16
16
|
initializer "initialize_logjam_agent_logger", :before => :initialize_logger do |app|
|
@@ -18,27 +18,21 @@ module LogjamAgent
|
|
18
18
|
begin
|
19
19
|
path = ENV["RAILS_LOG_TO_STDOUT"].present? ? STDOUT : logjam_log_path(app)
|
20
20
|
logger = LogjamAgent::BufferedLogger.new(path)
|
21
|
+
logger.formatter = app.config.log_formatter || LogjamAgent::SyslogLikeFormatter.new
|
22
|
+
logger = ActiveSupport::TaggedLogging.new(logger)
|
21
23
|
logger.level = ::Logger.const_get(app.config.log_level.to_s.upcase)
|
22
24
|
LogjamAgent.log_device_log_level = logger.level
|
23
|
-
logger.formatter = LogjamAgent::SyslogLikeFormatter.new
|
24
|
-
logger.auto_flushing = false if Rails.env.production? && Rails::VERSION::STRING < "3.2"
|
25
|
-
logger = ActiveSupport::TaggedLogging.new(logger) if Rails::VERSION::STRING >= "3.2"
|
26
25
|
LogjamAgent.logger = logger
|
27
|
-
logger
|
28
26
|
rescue StandardError
|
29
27
|
logger = LogjamAgent::BufferedLogger.new(STDERR)
|
30
|
-
logger = ActiveSupport::TaggedLogging.new(logger)
|
31
|
-
LogjamAgent.logger = logger
|
28
|
+
logger = ActiveSupport::TaggedLogging.new(logger)
|
32
29
|
logger.level = ::Logger::WARN
|
33
30
|
logger.warn(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
logger
|
31
|
+
"Logging Error: Unable to access log file. Please ensure that #{path} exists and is writable. " +
|
32
|
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
33
|
+
)
|
34
|
+
LogjamAgent.logger = logger
|
38
35
|
end
|
39
|
-
if Rails::VERSION::STRING < "3.2"
|
40
|
-
at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) }
|
41
|
-
end
|
42
36
|
end
|
43
37
|
|
44
38
|
initializer "logjam_agent", :after => "time_bandits" do |app|
|
@@ -1,32 +1,8 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
module LogjamAgent
|
4
2
|
class SyslogLikeFormatter
|
5
3
|
def initialize
|
6
4
|
@hostname = LogjamAgent.hostname
|
7
5
|
@app_name = "rails"
|
8
|
-
@newline = ActiveSupport::VERSION::STRING < "4.0" ? "" : "\n"
|
9
|
-
end
|
10
|
-
|
11
|
-
def attributes=(attributes)
|
12
|
-
Thread.current.thread_variable_set(:__logjam_formatter_attributes__, attributes)
|
13
|
-
end
|
14
|
-
|
15
|
-
def attributes
|
16
|
-
unless attributes = Thread.current.thread_variable_get(:__logjam_formatter_attributes__)
|
17
|
-
attributes = Thread.current.thread_variable_set(:__logjam_formatter_attributes__, [])
|
18
|
-
end
|
19
|
-
attributes
|
20
|
-
end
|
21
|
-
|
22
|
-
SEV_LABEL = Logger::SEV_LABEL.map{|sev| "%-5s" % sev}
|
23
|
-
|
24
|
-
def format_severity(severity)
|
25
|
-
if severity.is_a?(String)
|
26
|
-
"%-5s" % severity
|
27
|
-
else
|
28
|
-
SEV_LABEL[severity] || 'ALIEN'
|
29
|
-
end
|
30
6
|
end
|
31
7
|
|
32
8
|
def format_time(timestamp)
|
@@ -38,7 +14,7 @@ module LogjamAgent
|
|
38
14
|
end
|
39
15
|
|
40
16
|
def call(severity, timestamp, progname, msg)
|
41
|
-
"#{
|
17
|
+
"#{severity} #{format_time(timestamp)}#{format_host_info(progname)}: #{format_message(msg)}\n"
|
42
18
|
end
|
43
19
|
|
44
20
|
if !defined?(Rails::Railtie) || Rails.env.development?
|
@@ -49,20 +25,5 @@ module LogjamAgent
|
|
49
25
|
end
|
50
26
|
end
|
51
27
|
|
52
|
-
def render_attributes
|
53
|
-
attributes.map{|key, value| " #{key}[#{value}]"}.join
|
54
|
-
end
|
55
|
-
|
56
|
-
def set_attribute(name, value)
|
57
|
-
if attribute = attributes.detect{|n,v| n == name}
|
58
|
-
attribute[1] = value
|
59
|
-
else
|
60
|
-
attributes << [name, value]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def reset_attributes
|
65
|
-
self.attributes = []
|
66
|
-
end
|
67
28
|
end
|
68
29
|
end
|
data/lib/logjam_agent/version.rb
CHANGED
data/lib/logjam_agent.rb
CHANGED
@@ -2,6 +2,12 @@ require "socket"
|
|
2
2
|
require "time_bandits"
|
3
3
|
require "logjam_agent/monkey_patches/ffi-rzmq-patch"
|
4
4
|
|
5
|
+
# monkey patch log levels to include NONE
|
6
|
+
require "logger"
|
7
|
+
module Logger::Severity
|
8
|
+
NONE = UNKNOWN + 1
|
9
|
+
end
|
10
|
+
|
5
11
|
module LogjamAgent
|
6
12
|
module RequestHandling
|
7
13
|
def request
|
@@ -35,16 +41,10 @@ require "logjam_agent/zmq_forwarder"
|
|
35
41
|
require "logjam_agent/forwarders"
|
36
42
|
require "logjam_agent/request"
|
37
43
|
require "logjam_agent/buffered_logger"
|
44
|
+
require "logjam_agent/logging_attributes"
|
38
45
|
require "logjam_agent/syslog_like_formatter"
|
39
|
-
|
40
46
|
require "logjam_agent/railtie" if defined?(Rails::Railtie)
|
41
47
|
|
42
|
-
# monkey patch log levels to include NONE
|
43
|
-
require 'logger'
|
44
|
-
module Logger::Severity
|
45
|
-
NONE = UNKNOWN + 1
|
46
|
-
end
|
47
|
-
|
48
48
|
module LogjamAgent
|
49
49
|
|
50
50
|
class ForwardingError < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -235,6 +235,7 @@ files:
|
|
235
235
|
- lib/logjam_agent/active_support/parameter_filter.rb
|
236
236
|
- lib/logjam_agent/buffered_logger.rb
|
237
237
|
- lib/logjam_agent/forwarders.rb
|
238
|
+
- lib/logjam_agent/logging_attributes.rb
|
238
239
|
- lib/logjam_agent/middleware.rb
|
239
240
|
- lib/logjam_agent/monkey_patches/ffi-rzmq-patch.rb
|
240
241
|
- lib/logjam_agent/rack/logger.rb
|
@@ -275,16 +276,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
276
|
- !ruby/object:Gem::Version
|
276
277
|
version: '0'
|
277
278
|
requirements: []
|
278
|
-
rubygems_version: 3.3.
|
279
|
+
rubygems_version: 3.3.19
|
279
280
|
signing_key:
|
280
281
|
specification_version: 4
|
281
282
|
summary: Logjam client library to be used with logjam
|
282
283
|
test_files:
|
283
|
-
- test/request_test.rb
|
284
284
|
- test/sinatra_app.rb
|
285
|
-
- test/sinatra_classic_app.rb
|
286
285
|
- test/sinatra_classic_test.rb
|
287
|
-
- test/
|
288
|
-
- test/
|
289
|
-
- test/util_test.rb
|
286
|
+
- test/sinatra_classic_app.rb
|
287
|
+
- test/request_test.rb
|
290
288
|
- test/zmq_forwarder_test.rb
|
289
|
+
- test/util_test.rb
|
290
|
+
- test/test_helper.rb
|
291
|
+
- test/sinatra_test.rb
|