semantic_logger 2.2.0 → 2.3.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/Rakefile +1 -18
- data/lib/semantic_logger/appender/base.rb +48 -0
- data/lib/semantic_logger/base.rb +4 -6
- data/lib/semantic_logger/logger.rb +9 -1
- data/lib/semantic_logger/version.rb +1 -1
- data/test/logger_test.rb +4 -0
- metadata +13 -10
- data/Gemfile +0 -10
- data/Gemfile.lock +0 -39
- data/others.txt +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e40f9cdb04c659a6463e341124bfa599fc6e1573
|
4
|
+
data.tar.gz: 837e26e9d736231379778a1dc031a3aa1a9b1da5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0289dacbdb9bdee70f9efe3b2203f7452863305cb562237c2067ec434739a8ae0af7b04eb14b57aff79f8783c3d7fc414f59890dcf2445fb229a6ed0139b7c48
|
7
|
+
data.tar.gz: a50be52d3059bef02aa2d77080dee298c28d02f6da1b4d749f678511285af4be64a6849a385f4cfbef5ed993b58ee5743a0ba164249fac9db3b7ae84ed22a0ac
|
data/Rakefile
CHANGED
@@ -5,28 +5,11 @@ require 'rubygems'
|
|
5
5
|
require 'rubygems/package'
|
6
6
|
require 'rake/clean'
|
7
7
|
require 'rake/testtask'
|
8
|
-
require 'date'
|
9
8
|
require 'semantic_logger/version'
|
10
9
|
|
11
10
|
desc "Build gem"
|
12
11
|
task :gem do |t|
|
13
|
-
|
14
|
-
spec.name = 'semantic_logger'
|
15
|
-
spec.version = SemanticLogger::VERSION
|
16
|
-
spec.platform = Gem::Platform::RUBY
|
17
|
-
spec.authors = ['Reid Morrison']
|
18
|
-
spec.email = ['reidmo@gmail.com']
|
19
|
-
spec.homepage = 'https://github.com/ClarityServices/semantic_logger'
|
20
|
-
spec.date = Date.today.to_s
|
21
|
-
spec.summary = "Improved logging for Ruby"
|
22
|
-
spec.description = "Semantic Logger takes logging in Ruby to a new level by adding several new capabilities to the commonly used Logging API"
|
23
|
-
spec.files = FileList["./**/*"].exclude(/\.gem$/, /\.log$/,/nbproject/).map{|f| f.sub(/^\.\//, '')}
|
24
|
-
spec.license = "Apache License V2.0"
|
25
|
-
spec.has_rdoc = true
|
26
|
-
spec.add_dependency 'sync_attr', '>= 1.0'
|
27
|
-
spec.add_dependency 'thread_safe', '>= 0.1.0'
|
28
|
-
end
|
29
|
-
Gem::Package.build gemspec
|
12
|
+
Gem::Package.build(Gem::Specification.load('semantic_logger.gemspec'))
|
30
13
|
end
|
31
14
|
|
32
15
|
desc "Run Test Suite"
|
@@ -8,6 +8,21 @@
|
|
8
8
|
#
|
9
9
|
module SemanticLogger
|
10
10
|
module Appender
|
11
|
+
|
12
|
+
# Formatting & colors used by optional colorized_formatter
|
13
|
+
module AnsiColors
|
14
|
+
CLEAR = "\e[0m"
|
15
|
+
BOLD = "\e[1m"
|
16
|
+
BLACK = "\e[30m"
|
17
|
+
RED = "\e[31m"
|
18
|
+
GREEN = "\e[32m"
|
19
|
+
YELLOW = "\e[33m"
|
20
|
+
BLUE = "\e[34m"
|
21
|
+
MAGENTA = "\e[35m"
|
22
|
+
CYAN = "\e[36m"
|
23
|
+
WHITE = "\e[37m"
|
24
|
+
end
|
25
|
+
|
11
26
|
class Base < SemanticLogger::Base
|
12
27
|
attr_accessor :formatter
|
13
28
|
|
@@ -29,6 +44,39 @@ module SemanticLogger
|
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
47
|
+
# Optional log formatter to colorize log output
|
48
|
+
# To use this formatter
|
49
|
+
# SemanticLogger.add_appender($stdout, nil, &SemanticLogger::Logger.colorized_formatter)
|
50
|
+
#
|
51
|
+
# 2011-07-19 14:36:15.660 D [1149:ScriptThreadProcess] Rails -- Hello World
|
52
|
+
def self.colorized_formatter
|
53
|
+
Proc.new do |log|
|
54
|
+
colors = SemanticLogger::Appender::AnsiColors
|
55
|
+
tags = log.tags.collect { |tag| "[#{colors::CYAN}#{tag}#{colors::CLEAR}]" }.join(' ') + ' ' if log.tags && (log.tags.size > 0)
|
56
|
+
|
57
|
+
message = log.message.to_s.dup
|
58
|
+
message << " -- " << log.payload.inspect if log.payload
|
59
|
+
message << " -- " << "#{colors::BOLD}#{log.exception.class}: #{log.exception.message}#{colors::CLEAR}\n#{(log.exception.backtrace || []).join("\n")}" if log.exception
|
60
|
+
|
61
|
+
duration_str = log.duration ? "(#{colors::BOLD}#{'%.1f' % log.duration}ms#{colors::CLEAR}) " : ''
|
62
|
+
|
63
|
+
level_color = case log.level
|
64
|
+
when :trace
|
65
|
+
colors::MAGENTA
|
66
|
+
when :debug
|
67
|
+
colors::CYAN
|
68
|
+
when :info
|
69
|
+
colors::GREEN
|
70
|
+
when :warn
|
71
|
+
colors::YELLOW
|
72
|
+
when :error, :fatal
|
73
|
+
colors::RED
|
74
|
+
end
|
75
|
+
|
76
|
+
"#{SemanticLogger::Appender::Base.formatted_time(log.time)} #{level_color}#{colors::BOLD}#{log.level.to_s[0..0].upcase}#{colors::CLEAR} [#{$$}:#{log.thread_name}] #{tags}#{duration_str}#{level_color}#{log.name}#{colors::CLEAR} -- #{message}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
32
80
|
############################################################################
|
33
81
|
protected
|
34
82
|
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -161,22 +161,20 @@ module SemanticLogger
|
|
161
161
|
# Returns [Array] of [String] tags currently active for this thread
|
162
162
|
# Returns nil if no tags are set
|
163
163
|
def tags
|
164
|
-
Thread.current[:semantic_logger_tags]
|
164
|
+
Thread.current[:semantic_logger_tags] ||= []
|
165
165
|
end
|
166
166
|
|
167
167
|
# Add tags to the current scope
|
168
168
|
# To support: ActiveSupport::TaggedLogging V4 and above
|
169
169
|
def push_tags *tags
|
170
170
|
# Check for nil tags
|
171
|
-
Thread.current[:semantic_logger_tags] =
|
171
|
+
Thread.current[:semantic_logger_tags] = self.tags.concat(tags)
|
172
172
|
end
|
173
173
|
|
174
174
|
# Remove specified number of tags from the current tag list
|
175
175
|
# To support: ActiveSupport::TaggedLogging V4 and above
|
176
|
-
def pop_tags(quantity)
|
177
|
-
|
178
|
-
Thread.current[:semantic_logger_tags] = tags.pop(quantity)
|
179
|
-
end
|
176
|
+
def pop_tags(quantity=1)
|
177
|
+
tags.pop(quantity)
|
180
178
|
end
|
181
179
|
|
182
180
|
# Thread specific context information to be logged with every log entry
|
@@ -5,8 +5,16 @@ require 'thread_safe'
|
|
5
5
|
module SemanticLogger
|
6
6
|
class Logger < Base
|
7
7
|
|
8
|
-
#
|
8
|
+
# DO NOT USE. Adding unused formatter to support Rails 4 logging
|
9
9
|
# Formatters must be set at the appender level, not at the logger level
|
10
|
+
#
|
11
|
+
# Due to the following code in Rails::Server#start that cannot be changed
|
12
|
+
# without patching the entire method
|
13
|
+
# console = ActiveSupport::Logger.new($stdout)
|
14
|
+
# console.formatter = Rails.logger.formatter
|
15
|
+
# console.level = Rails.logger.level
|
16
|
+
#
|
17
|
+
# Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
|
10
18
|
attr_accessor :formatter
|
11
19
|
|
12
20
|
# Returns a Logger instance
|
data/test/logger_test.rb
CHANGED
@@ -21,6 +21,7 @@ class LoggerTest < Test::Unit::TestCase
|
|
21
21
|
@logger = SemanticLogger::Logger.new(self.class, :trace)
|
22
22
|
@hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
|
23
23
|
@hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
|
24
|
+
assert_equal [], @logger.tags
|
24
25
|
end
|
25
26
|
|
26
27
|
teardown do
|
@@ -53,6 +54,9 @@ class LoggerTest < Test::Unit::TestCase
|
|
53
54
|
SemanticLogger.flush
|
54
55
|
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ \w \[\d+:.+\] \[First Level\] \[tags\] \[Second Level\] LoggerTest -- Hello world/, @mock_logger.message
|
55
56
|
end
|
57
|
+
assert_equal 2, @logger.tags.count, @logger.tags
|
58
|
+
assert_equal 'First Level', @logger.tags.first
|
59
|
+
assert_equal 'tags', @logger.tags.last
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
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: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sync_attr
|
@@ -46,12 +46,6 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
-
- Gemfile
|
50
|
-
- Gemfile.lock
|
51
|
-
- LICENSE.txt
|
52
|
-
- README.md
|
53
|
-
- Rakefile
|
54
|
-
- lib/semantic_logger.rb
|
55
49
|
- lib/semantic_logger/appender/base.rb
|
56
50
|
- lib/semantic_logger/appender/file.rb
|
57
51
|
- lib/semantic_logger/appender/mongodb.rb
|
@@ -61,7 +55,10 @@ files:
|
|
61
55
|
- lib/semantic_logger/logger.rb
|
62
56
|
- lib/semantic_logger/semantic_logger.rb
|
63
57
|
- lib/semantic_logger/version.rb
|
64
|
-
-
|
58
|
+
- lib/semantic_logger.rb
|
59
|
+
- LICENSE.txt
|
60
|
+
- Rakefile
|
61
|
+
- README.md
|
65
62
|
- test/appender_file_test.rb
|
66
63
|
- test/appender_mongodb_test.rb
|
67
64
|
- test/appender_wrapper_test.rb
|
@@ -92,4 +89,10 @@ rubygems_version: 2.0.3
|
|
92
89
|
signing_key:
|
93
90
|
specification_version: 4
|
94
91
|
summary: Improved logging for Ruby
|
95
|
-
test_files:
|
92
|
+
test_files:
|
93
|
+
- test/appender_file_test.rb
|
94
|
+
- test/appender_mongodb_test.rb
|
95
|
+
- test/appender_wrapper_test.rb
|
96
|
+
- test/loggable_test.rb
|
97
|
+
- test/logger_test.rb
|
98
|
+
- test/mock_logger.rb
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activesupport (3.2.13)
|
5
|
-
i18n (= 0.6.1)
|
6
|
-
multi_json (~> 1.0)
|
7
|
-
atomic (1.1.8)
|
8
|
-
bourne (1.4.0)
|
9
|
-
mocha (~> 0.13.2)
|
10
|
-
bson (1.8.5)
|
11
|
-
bson_ext (1.8.5)
|
12
|
-
bson (~> 1.8.5)
|
13
|
-
i18n (0.6.1)
|
14
|
-
metaclass (0.0.1)
|
15
|
-
mocha (0.13.3)
|
16
|
-
metaclass (~> 0.0.1)
|
17
|
-
mongo (1.8.5)
|
18
|
-
bson (~> 1.8.5)
|
19
|
-
multi_json (1.7.2)
|
20
|
-
shoulda (3.4.0)
|
21
|
-
shoulda-context (~> 1.0, >= 1.0.1)
|
22
|
-
shoulda-matchers (~> 1.0, >= 1.4.1)
|
23
|
-
shoulda-context (1.1.1)
|
24
|
-
shoulda-matchers (1.5.6)
|
25
|
-
activesupport (>= 3.0.0)
|
26
|
-
bourne (~> 1.3)
|
27
|
-
sync_attr (1.0.0)
|
28
|
-
thread_safe (0.1.0)
|
29
|
-
atomic
|
30
|
-
|
31
|
-
PLATFORMS
|
32
|
-
ruby
|
33
|
-
|
34
|
-
DEPENDENCIES
|
35
|
-
bson_ext
|
36
|
-
mongo
|
37
|
-
shoulda
|
38
|
-
sync_attr
|
39
|
-
thread_safe
|