semantic_logger 2.15.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -47
- data/Rakefile +5 -5
- data/lib/semantic_logger.rb +2 -0
- data/lib/semantic_logger/appender/base.rb +24 -19
- data/lib/semantic_logger/appender/bugsnag.rb +1 -1
- data/lib/semantic_logger/appender/file.rb +9 -8
- data/lib/semantic_logger/appender/mongodb.rb +14 -14
- data/lib/semantic_logger/appender/new_relic.rb +7 -7
- data/lib/semantic_logger/appender/splunk.rb +3 -3
- data/lib/semantic_logger/appender/syslog.rb +33 -33
- data/lib/semantic_logger/appender/wrapper.rb +3 -3
- data/lib/semantic_logger/base.rb +31 -29
- data/lib/semantic_logger/jruby/garbage_collection_logger.rb +2 -2
- data/lib/semantic_logger/loggable.rb +2 -2
- data/lib/semantic_logger/logger.rb +12 -12
- data/lib/semantic_logger/semantic_logger.rb +39 -39
- data/lib/semantic_logger/version.rb +1 -1
- data/test/appender_bugsnag_test.rb +9 -9
- data/test/appender_file_test.rb +20 -20
- data/test/appender_mongodb_test.rb +16 -16
- data/test/appender_new_relic_test.rb +10 -10
- data/test/appender_splunk_test.rb +12 -18
- data/test/appender_syslog_test.rb +8 -8
- data/test/appender_wrapper_test.rb +27 -27
- data/test/debug_as_trace_logger_test.rb +37 -37
- data/test/loggable_test.rb +12 -12
- data/test/logger_test.rb +90 -91
- data/test/test_helper.rb +0 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d4e0a0bfded65004b557ad08aa6729d70387841
|
4
|
+
data.tar.gz: 9c8f8584584afb4d29c71467f09ab0d87c61fd4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dea37b7135aba5a357aa012ff879345d521a5cc25d45f26b14c1292ab2716c644ebfd29b6ed7eaca6aba109c1b945501c43698a9a7c20c9919c85eb8cfeaa12
|
7
|
+
data.tar.gz: a061d2c0989485fc5cba5dafc5d96d9d39376805c3d509046c05a46e0dc1c8be4d17d728be939d3cd94315971be1817b95da8baa0b2e223adc156d4de14bdbfc
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# semantic_logger
|
2
|
+
   
|
3
3
|
|
4
4
|
Low latency, high throughput, enterprise-scale logging system for Ruby
|
5
5
|
|
6
|
-
* http://github.com/
|
6
|
+
* http://github.com/rocketjob/semantic_logger
|
7
7
|
|
8
8
|
## Documentation
|
9
9
|
|
10
|
-
[Semantic Logger Guide](http://
|
10
|
+
[Semantic Logger Guide](http://rocketjob.github.io/semantic_logger)
|
11
11
|
|
12
|
-
|
12
|
+
[Reference Documentation](http://www.rubydoc.info/gems/semantic_logger/)
|
13
13
|
|
14
14
|
## Supports
|
15
15
|
|
@@ -30,12 +30,17 @@ the log information is being saved. Semantic Logger avoids this slowdown by push
|
|
30
30
|
log events to an in-memory queue that is serviced by a separate thread that only
|
31
31
|
handles saving log information to multiple destinations at the same time.
|
32
32
|
|
33
|
-
##
|
33
|
+
## Rails
|
34
|
+
|
35
|
+
When running Rails, use [rails_semantic_logger](http://github.com/rocketjob/rails_semantic_logger)
|
36
|
+
instead of Semantic Logger directly since it will automatically replace the Rails default logger with Semantic Logger.
|
37
|
+
|
38
|
+
## Supports
|
34
39
|
|
35
40
|
Semantic Logger is tested and supported on the following Ruby platforms:
|
36
41
|
- Ruby 2.0 and above
|
37
42
|
- JRuby 1.7 and above
|
38
|
-
- JRuby 9.0
|
43
|
+
- JRuby 9.0 and above
|
39
44
|
- Rubinius 2.5 and above
|
40
45
|
|
41
46
|
The following gems are only required when their corresponding appenders are being used,
|
@@ -51,48 +56,12 @@ and are therefore not automatically included by this gem:
|
|
51
56
|
|
52
57
|
gem install semantic_logger
|
53
58
|
|
54
|
-
## Upgrade Notes:
|
55
|
-
|
56
|
-
### V2.10
|
57
|
-
|
58
|
-
Ruby 1.8 is no longer supported, see [Ruby 1.8.7 EOL](https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/)
|
59
|
-
|
60
|
-
### V2.0
|
61
|
-
|
62
|
-
Rails logging is no longer automatically replaced when including SemanticLogger.
|
63
|
-
Include the [rails_semantic_logger](http://github.com/reidmorrison/rails_semantic_logger)
|
64
|
-
gem to replace the Rails default logger with SemanticLogger
|
65
|
-
|
66
|
-
## Meta
|
67
|
-
|
68
|
-
* Code: `git clone git://github.com/reidmorrison/semantic_logger.git`
|
69
|
-
* Home: <https://github.com/reidmorrison/semantic_logger>
|
70
|
-
* Bugs: <http://github.com/reidmorrison/semantic_logger/issues>
|
71
|
-
* Gems: <http://rubygems.org/gems/semantic_logger>
|
72
|
-
|
73
|
-
This project uses [Semantic Versioning](http://semver.org/).
|
74
|
-
|
75
59
|
## Author
|
76
60
|
|
77
|
-
[Reid Morrison](https://github.com/reidmorrison)
|
78
|
-
|
79
|
-
## Contributors
|
61
|
+
[Reid Morrison](https://github.com/reidmorrison)
|
80
62
|
|
81
|
-
|
82
|
-
* [Andrew Medeiros](https://github.com/amedeiros)
|
63
|
+
[Contributors](https://github.com/rocketjob/semantic_logger/graphs/contributors)
|
83
64
|
|
84
|
-
##
|
65
|
+
## Versioning
|
85
66
|
|
86
|
-
|
87
|
-
|
88
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
89
|
-
you may not use this file except in compliance with the License.
|
90
|
-
You may obtain a copy of the License at
|
91
|
-
|
92
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
93
|
-
|
94
|
-
Unless required by applicable law or agreed to in writing, software
|
95
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
96
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
97
|
-
See the License for the specific language governing permissions and
|
98
|
-
limitations under the License.
|
67
|
+
This project uses [Semantic Versioning](http://semver.org/).
|
data/Rakefile
CHANGED
@@ -5,17 +5,17 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
|
5
5
|
require 'semantic_logger/version'
|
6
6
|
|
7
7
|
task :gem do
|
8
|
-
system
|
8
|
+
system 'gem build semantic_logger.gemspec'
|
9
9
|
end
|
10
10
|
|
11
|
-
task :
|
11
|
+
task publish: :gem do
|
12
12
|
system "git tag -a v#{SemanticLogger::VERSION} -m 'Tagging #{SemanticLogger::VERSION}'"
|
13
|
-
system
|
13
|
+
system 'git push --tags'
|
14
14
|
system "gem push semantic_logger-#{SemanticLogger::VERSION}.gem"
|
15
15
|
system "rm semantic_logger-#{SemanticLogger::VERSION}.gem"
|
16
16
|
end
|
17
17
|
|
18
|
-
desc
|
18
|
+
desc 'Run Test Suite'
|
19
19
|
task :test do
|
20
20
|
Rake::TestTask.new(:functional) do |t|
|
21
21
|
t.test_files = FileList['test/*_test.rb']
|
@@ -25,4 +25,4 @@ task :test do
|
|
25
25
|
Rake::Task['functional'].invoke
|
26
26
|
end
|
27
27
|
|
28
|
-
task :
|
28
|
+
task default: :test
|
data/lib/semantic_logger.rb
CHANGED
@@ -2,6 +2,7 @@ require 'semantic_logger/core_ext/thread'
|
|
2
2
|
require 'semantic_logger/version'
|
3
3
|
require 'semantic_logger/semantic_logger'
|
4
4
|
|
5
|
+
# @formatter:off
|
5
6
|
module SemanticLogger
|
6
7
|
autoload :Base, 'semantic_logger/base'
|
7
8
|
autoload :Logger, 'semantic_logger/logger'
|
@@ -18,6 +19,7 @@ module SemanticLogger
|
|
18
19
|
autoload :Splunk, 'semantic_logger/appender/splunk'
|
19
20
|
autoload :Bugsnag, 'semantic_logger/appender/bugsnag'
|
20
21
|
end
|
22
|
+
# @formatter:on
|
21
23
|
|
22
24
|
if defined?(JRuby)
|
23
25
|
module JRuby
|
@@ -32,11 +32,11 @@ module SemanticLogger
|
|
32
32
|
# 2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails -- Hello World
|
33
33
|
def default_formatter
|
34
34
|
Proc.new do |log|
|
35
|
-
tags = log.tags.collect { |tag| "[#{tag}]" }.join(
|
35
|
+
tags = log.tags.collect { |tag| "[#{tag}]" }.join(' ') + ' ' if log.tags && (log.tags.size > 0)
|
36
36
|
|
37
37
|
message = log.message.to_s.dup
|
38
|
-
message <<
|
39
|
-
message <<
|
38
|
+
message << ' -- ' << log.payload.inspect unless log.payload.nil? || log.payload.empty?
|
39
|
+
message << ' -- Exception: ' << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
40
40
|
|
41
41
|
duration_str = log.duration ? "(#{'%.1f' % log.duration}ms) " : ''
|
42
42
|
|
@@ -52,26 +52,31 @@ module SemanticLogger
|
|
52
52
|
def self.colorized_formatter
|
53
53
|
Proc.new do |log|
|
54
54
|
colors = SemanticLogger::Appender::AnsiColors
|
55
|
-
tags
|
55
|
+
tags = log.tags.collect { |tag| "[#{colors::CYAN}#{tag}#{colors::CLEAR}]" }.join(' ') + ' ' if log.tags && (log.tags.size > 0)
|
56
56
|
|
57
57
|
message = log.message.to_s.dup
|
58
|
-
|
59
|
-
|
58
|
+
unless log.payload.nil? || log.payload.empty?
|
59
|
+
payload = log.payload
|
60
|
+
payload = (defined?(AwesomePrint) && payload.respond_to?(:ai)) ? payload.ai(multiline: false) : payload.inspect
|
61
|
+
message << ' -- ' << payload
|
62
|
+
end
|
63
|
+
message << ' -- Exception: ' << "#{colors::BOLD}#{log.exception.class}: #{log.exception.message}#{colors::CLEAR}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
60
64
|
|
61
65
|
duration_str = log.duration ? "(#{colors::BOLD}#{'%.1f' % log.duration}ms#{colors::CLEAR}) " : ''
|
62
66
|
|
63
|
-
level_color =
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
level_color =
|
68
|
+
case log.level
|
69
|
+
when :trace
|
70
|
+
colors::MAGENTA
|
71
|
+
when :debug
|
72
|
+
colors::GREEN
|
73
|
+
when :info
|
74
|
+
colors::CYAN
|
75
|
+
when :warn
|
76
|
+
colors::BOLD
|
77
|
+
when :error, :fatal
|
78
|
+
colors::RED
|
79
|
+
end
|
75
80
|
|
76
81
|
"#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{level_color}#{colors::BOLD}#{log.level.to_s[0..0].upcase}#{colors::CLEAR} [#{$$}:#{'%.30s' % log.thread_name}] #{tags}#{duration_str}#{level_color}#{log.name}#{colors::CLEAR} -- #{message}"
|
77
82
|
end
|
@@ -135,4 +140,4 @@ module SemanticLogger
|
|
135
140
|
|
136
141
|
end
|
137
142
|
end
|
138
|
-
end
|
143
|
+
end
|
@@ -54,7 +54,7 @@ class SemanticLogger::Appender::Bugsnag < SemanticLogger::Appender::Base
|
|
54
54
|
# Returns [Hash] of parameters to send to Bugsnag.
|
55
55
|
def default_formatter
|
56
56
|
proc do |log|
|
57
|
-
h = {
|
57
|
+
h = {severity: log_level(log), tags: log.tags, class: log.name}
|
58
58
|
h.merge!(log.payload) if log.payload
|
59
59
|
h
|
60
60
|
end
|
@@ -40,13 +40,14 @@ module SemanticLogger
|
|
40
40
|
# logger.info 'Hello World'
|
41
41
|
#
|
42
42
|
def initialize(filename, level=nil, filter=nil, &block)
|
43
|
-
raise
|
44
|
-
@log =
|
45
|
-
filename
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
raise 'filename cannot be null when initializing the SemanticLogging::Appender::File' unless filename
|
44
|
+
@log =
|
45
|
+
if filename.respond_to?(:write) and filename.respond_to?(:close)
|
46
|
+
filename
|
47
|
+
else
|
48
|
+
@filename = filename
|
49
|
+
reopen
|
50
|
+
end
|
50
51
|
|
51
52
|
# Set the log level and formatter if supplied
|
52
53
|
super(level, filter, &block)
|
@@ -60,7 +61,7 @@ module SemanticLogger
|
|
60
61
|
def reopen
|
61
62
|
return unless @filename
|
62
63
|
|
63
|
-
@log
|
64
|
+
@log = open(@filename, (::File::WRONLY | ::File::APPEND | ::File::CREAT))
|
64
65
|
# Force all log entries to write immediately without buffering
|
65
66
|
# Allows multiple processes to write to the same log file simultaneously
|
66
67
|
@log.sync = true
|
@@ -35,7 +35,7 @@ module SemanticLogger
|
|
35
35
|
|
36
36
|
# Create a MongoDB Appender instance
|
37
37
|
#
|
38
|
-
# SemanticLogger::Appender::MongoDB.new(:
|
38
|
+
# SemanticLogger::Appender::MongoDB.new(db: Mongo::Connection.new['database'])
|
39
39
|
#
|
40
40
|
# Parameters:
|
41
41
|
# :db [Mongo::Database]
|
@@ -116,7 +116,7 @@ module SemanticLogger
|
|
116
116
|
#
|
117
117
|
# Creates an index based on tags to support faster lookups
|
118
118
|
def create_indexes
|
119
|
-
options
|
119
|
+
options = {capped: true, size: @collection_size}
|
120
120
|
options[:max] = @collection_max if @collection_max
|
121
121
|
db.create_collection(collection_name, options)
|
122
122
|
db[@collection_name].ensure_index('tags')
|
@@ -141,14 +141,14 @@ module SemanticLogger
|
|
141
141
|
# Replace this formatter by supplying a Block to the initializer
|
142
142
|
def default_formatter
|
143
143
|
Proc.new do |log|
|
144
|
-
document
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
144
|
+
document = {
|
145
|
+
time: log.time,
|
146
|
+
host_name: host_name,
|
147
|
+
pid: $$,
|
148
|
+
thread_name: log.thread_name,
|
149
|
+
name: log.name,
|
150
|
+
level: log.level,
|
151
|
+
level_index: log.level_index,
|
152
152
|
}
|
153
153
|
document[:application] = application if application
|
154
154
|
document[:message] = self.class.strip_colorizing(log.message) if log.message
|
@@ -156,9 +156,9 @@ module SemanticLogger
|
|
156
156
|
document[:tags] = log.tags if log.tags && (log.tags.size > 0)
|
157
157
|
document[:payload] = log.payload if log.payload
|
158
158
|
document[:exception] = {
|
159
|
-
:
|
160
|
-
:
|
161
|
-
:
|
159
|
+
name: log.exception.class.name,
|
160
|
+
message: log.exception.message,
|
161
|
+
stack_trace: log.exception.backtrace
|
162
162
|
} if log.exception
|
163
163
|
document
|
164
164
|
end
|
@@ -191,4 +191,4 @@ module SemanticLogger
|
|
191
191
|
|
192
192
|
end
|
193
193
|
end
|
194
|
-
end
|
194
|
+
end
|
@@ -63,7 +63,7 @@ class SemanticLogger::Appender::NewRelic < SemanticLogger::Appender::Base
|
|
63
63
|
# Allow the level for this appender to be overwritten
|
64
64
|
# Default: :error
|
65
65
|
# Note: Not recommended to set the log level to :info, :debug, or :trace as that would flood NewRelic with Error notices
|
66
|
-
def initialize(level=:error
|
66
|
+
def initialize(level=:error, &block)
|
67
67
|
# Pass on the level and custom formatter if supplied
|
68
68
|
super(level, &block)
|
69
69
|
end
|
@@ -77,16 +77,16 @@ class SemanticLogger::Appender::NewRelic < SemanticLogger::Appender::Base
|
|
77
77
|
def default_formatter
|
78
78
|
Proc.new do |log|
|
79
79
|
short_message = self.class.first_non_empty_line(log.message)
|
80
|
-
metric
|
80
|
+
metric = log.metric || "#{log.name}/#{short_message}"
|
81
81
|
|
82
|
-
custom_params
|
82
|
+
custom_params = {thread_name: log.thread_name}
|
83
83
|
# Only show the message under custom attributes if the error message uses an exception or shortened message (first non-empty line).
|
84
|
-
custom_params[:message] = log.message
|
84
|
+
custom_params[:message] = log.message if log.message && (log.exception || log.message != short_message)
|
85
85
|
custom_params[:duration] = "#{log.duration} ms" if log.duration
|
86
|
-
custom_params[:payload] = log.payload
|
87
|
-
custom_params[:tags] = log.tags
|
86
|
+
custom_params[:payload] = log.payload if log.payload
|
87
|
+
custom_params[:tags] = log.tags if log.tags && (log.tags.size > 0)
|
88
88
|
|
89
|
-
{
|
89
|
+
{metric: metric, custom_params: custom_params}
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -20,7 +20,7 @@ class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
|
|
20
20
|
# open the handles to resources
|
21
21
|
def reopen
|
22
22
|
# Connect to splunk. Connect is a synonym for creating a Service by hand and calling login.
|
23
|
-
@service
|
23
|
+
@service = Splunk::connect(@config)
|
24
24
|
|
25
25
|
# The index we are logging to
|
26
26
|
@service_index = @service.indexes[@index]
|
@@ -46,7 +46,7 @@ class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
|
|
46
46
|
password: options[:password]
|
47
47
|
}
|
48
48
|
|
49
|
-
@index = options[:index]
|
49
|
+
@index = options[:index] || 'main'
|
50
50
|
|
51
51
|
if @config[:username].nil?
|
52
52
|
raise ArgumentError, 'Must supply a username.'
|
@@ -56,4 +56,4 @@ class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
|
|
56
56
|
raise ArgumentError, 'Must supply an index.'
|
57
57
|
end
|
58
58
|
end
|
59
|
-
end
|
59
|
+
end
|
@@ -48,12 +48,12 @@ module SemanticLogger
|
|
48
48
|
# ::Syslog::LOG_INFO - "Informational message"
|
49
49
|
# ::Syslog::LOG_DEBUG - "Debugging information"
|
50
50
|
DEFAULT_LEVEL_MAP = {
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
51
|
+
fatal: ::Syslog::LOG_CRIT,
|
52
|
+
error: ::Syslog::LOG_ERR,
|
53
|
+
warn: ::Syslog::LOG_WARNING,
|
54
|
+
info: ::Syslog::LOG_NOTICE,
|
55
|
+
debug: ::Syslog::LOG_INFO,
|
56
|
+
trace: ::Syslog::LOG_DEBUG
|
57
57
|
}
|
58
58
|
|
59
59
|
# For more information on the Syslog constants used below see http://ruby-doc.org/stdlib-2.0.0/libdoc/syslog/rdoc/Syslog.html
|
@@ -106,18 +106,18 @@ module SemanticLogger
|
|
106
106
|
#
|
107
107
|
# :level_map [Hash]
|
108
108
|
# Supply a custom map of SemanticLogger levels to syslog levels.
|
109
|
-
# For example, passing in { :
|
109
|
+
# For example, passing in { warn: ::Syslog::LOG_NOTICE }
|
110
110
|
# would result in a log mapping that matches the default level map,
|
111
111
|
# except for :warn, which ends up with a LOG_NOTICE level instead of a
|
112
112
|
# LOG_WARNING one.
|
113
113
|
# Without overriding any parameters, the level map will be
|
114
114
|
# LEVEL_MAP = {
|
115
|
-
# :
|
116
|
-
# :
|
117
|
-
# :
|
118
|
-
# :
|
119
|
-
# :
|
120
|
-
# :
|
115
|
+
# fatal: ::Syslog::LOG_CRIT,
|
116
|
+
# error: ::Syslog::LOG_ERR,
|
117
|
+
# warn: ::Syslog::LOG_WARNING,
|
118
|
+
# info: ::Syslog::LOG_NOTICE,
|
119
|
+
# debug: ::Syslog::LOG_INFO,
|
120
|
+
# trace: ::Syslog::LOG_DEBUG
|
121
121
|
# }
|
122
122
|
#
|
123
123
|
# :local_hostname [String]
|
@@ -143,19 +143,19 @@ module SemanticLogger
|
|
143
143
|
# For a list of options see the net_tcp_client documentation:
|
144
144
|
# https://www.omniref.com/ruby/gems/net_tcp_client/1.0.0/symbols/Net::TCPClient/initialize
|
145
145
|
def initialize(params = {}, &block)
|
146
|
-
params
|
147
|
-
@ident
|
148
|
-
@options
|
149
|
-
@facility
|
150
|
-
filter
|
151
|
-
level
|
152
|
-
level_map
|
153
|
-
@level_map
|
146
|
+
params = params.dup
|
147
|
+
@ident = params.delete(:ident) || 'ruby'
|
148
|
+
@options = params.delete(:options) || (::Syslog::LOG_PID | ::Syslog::LOG_CONS)
|
149
|
+
@facility = params.delete(:facility) || ::Syslog::LOG_USER
|
150
|
+
filter = params.delete(:filter)
|
151
|
+
level = params.delete(:level)
|
152
|
+
level_map = params.delete(:level_map)
|
153
|
+
@level_map = DEFAULT_LEVEL_MAP.dup
|
154
154
|
@level_map.update(level_map) if level_map
|
155
|
-
@server
|
156
|
-
uri
|
157
|
-
@host
|
158
|
-
@protocol
|
155
|
+
@server = params.delete(:server) || 'syslog://localhost'
|
156
|
+
uri = URI(@server)
|
157
|
+
@host = uri.host || 'localhost'
|
158
|
+
@protocol = (uri.scheme || :syslog).to_sym
|
159
159
|
raise "Unknown protocol #{@protocol}!" unless [:syslog, :tcp, :udp].include?(@protocol)
|
160
160
|
@host = 'localhost' if @protocol == :syslog
|
161
161
|
@port = URI(@server).port || 514
|
@@ -163,7 +163,7 @@ module SemanticLogger
|
|
163
163
|
@tcp_client_options = params.delete(:tcp_client)
|
164
164
|
|
165
165
|
# Warn about any unknown configuration options.
|
166
|
-
params.each_pair { |key,val| SemanticLogger::Logger.logger.warn "Ignoring unknown configuration option: #{key.inspect} => #{val.inspect}" }
|
166
|
+
params.each_pair { |key, val| SemanticLogger::Logger.logger.warn "Ignoring unknown configuration option: #{key.inspect} => #{val.inspect}" }
|
167
167
|
|
168
168
|
# The syslog_protocol gem is required when logging over TCP or UDP.
|
169
169
|
if [:tcp, :udp].include?(@protocol)
|
@@ -175,7 +175,7 @@ module SemanticLogger
|
|
175
175
|
|
176
176
|
# The net_tcp_client gem is required when logging over TCP.
|
177
177
|
if protocol == :tcp
|
178
|
-
@tcp_client_options
|
178
|
+
@tcp_client_options ||= {}
|
179
179
|
@tcp_client_options[:server] = "#{@host}:#{@port}"
|
180
180
|
begin
|
181
181
|
require 'net/tcp_client'
|
@@ -199,7 +199,7 @@ module SemanticLogger
|
|
199
199
|
when :tcp
|
200
200
|
# Use the local logger for @remote_syslog so errors with the remote logger can be recorded locally.
|
201
201
|
@tcp_client_options[:logger] = SemanticLogger::Logger.logger
|
202
|
-
@remote_syslog
|
202
|
+
@remote_syslog = Net::TCPClient.new(@tcp_client_options)
|
203
203
|
when :udp
|
204
204
|
@remote_syslog = UDPSocket.new
|
205
205
|
else
|
@@ -215,7 +215,7 @@ module SemanticLogger
|
|
215
215
|
case @protocol
|
216
216
|
when :syslog
|
217
217
|
# Since the Ruby Syslog API supports sprintf format strings, double up all existing '%'
|
218
|
-
message = formatter.call(log).gsub
|
218
|
+
message = formatter.call(log).gsub '%', '%%'
|
219
219
|
::Syslog.log @level_map[log.level], message
|
220
220
|
when :tcp
|
221
221
|
@remote_syslog.retry_on_connection_failure { @remote_syslog.write("#{syslog_packet_formatter(log)}\r\n") }
|
@@ -238,8 +238,8 @@ module SemanticLogger
|
|
238
238
|
tags = log.tags.collect { |tag| "[#{tag}]" }.join(" ") + " " if log.tags && (log.tags.size > 0)
|
239
239
|
|
240
240
|
message = log.message.to_s
|
241
|
-
message <<
|
242
|
-
message <<
|
241
|
+
message << ' -- ' << log.payload.inspect if log.payload
|
242
|
+
message << ' -- ' << "#{log.exception.class}: #{log.exception.message}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
243
243
|
|
244
244
|
duration_str = log.duration ? "(#{'%.1f' % log.duration}ms) " : ''
|
245
245
|
|
@@ -249,10 +249,10 @@ module SemanticLogger
|
|
249
249
|
|
250
250
|
# Format the syslog packet so it can be sent over TCP or UDP
|
251
251
|
def syslog_packet_formatter(log)
|
252
|
-
packet
|
252
|
+
packet = SyslogProtocol::Packet.new
|
253
253
|
packet.hostname = @local_hostname
|
254
254
|
packet.facility = @facility
|
255
|
-
packet.severity =
|
255
|
+
packet.severity = @level_map[log.level]
|
256
256
|
packet.tag = @ident
|
257
257
|
packet.content = default_formatter.call(log)
|
258
258
|
packet.to_s
|