semantic_logger 2.1.0 → 2.2.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/Gemfile.lock +39 -0
- data/README.md +38 -0
- data/lib/semantic_logger/base.rb +21 -9
- data/lib/semantic_logger/logger.rb +4 -0
- data/lib/semantic_logger/version.rb +1 -1
- data/others.txt +5 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd64eb04f0be456dd95ec325d6ac00af3dba49c1
|
4
|
+
data.tar.gz: 2d48aa4423c72c71ba7cf42e370d4dd5b21adc47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc6dca8b8c4553acedbcc639f5daaeee367043816d23ad6816a0be9360b8529df18a3145fb0717b06a8964d1028bdccf61117e6edcfe5a1f719882cb7058c0b
|
7
|
+
data.tar.gz: e552b8b33ef2b967c3d18321cb8f1dd9e2d3173a57eaef32f3e25261767b0864ba6735d54e12a4ceb3dc0e7038077f10727fc72eb049130336b04621bcda7d2b
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
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
|
data/README.md
CHANGED
@@ -589,6 +589,44 @@ level_index [Integer]
|
|
589
589
|
|
590
590
|
* Internal use only. Index of the log level
|
591
591
|
|
592
|
+
#### Mixing Logging Levels
|
593
|
+
|
594
|
+
It is sometimes useful to log a subset of the log messages to a separate file
|
595
|
+
or appender. For example, log :error and :fatal level messages to a special
|
596
|
+
error file.
|
597
|
+
|
598
|
+
Below is a stand-alone example that better shows this behavior:
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
require 'semantic_logger'
|
602
|
+
|
603
|
+
# Set default log level for new logger instances
|
604
|
+
SemanticLogger.default_level = :info
|
605
|
+
|
606
|
+
# Log all warning messages and above to warnings.log
|
607
|
+
SemanticLogger.add_appender('log/warnings.log', :warn)
|
608
|
+
|
609
|
+
# Log all trace messages and above to trace.log
|
610
|
+
SemanticLogger.add_appender('log/trace.log', :trace)
|
611
|
+
|
612
|
+
logger = SemanticLogger['MyClass']
|
613
|
+
logger.level = :trace
|
614
|
+
logger.trace "This is a trace message"
|
615
|
+
logger.info "This is an info message"
|
616
|
+
logger.warn "This is a warning message"
|
617
|
+
```
|
618
|
+
|
619
|
+
The output is as follows:
|
620
|
+
```bash
|
621
|
+
==> trace.log <==
|
622
|
+
2013-08-02 14:15:56.733532 T [35669:70176909690580] MyClass -- This is a trace message
|
623
|
+
2013-08-02 14:15:56.734273 I [35669:70176909690580] MyClass -- This is an info message
|
624
|
+
2013-08-02 14:15:56.735273 W [35669:70176909690580] MyClass -- This is a warning message
|
625
|
+
|
626
|
+
==> warnings.log <==
|
627
|
+
2013-08-02 14:15:56.735273 W [35669:70176909690580] MyClass -- This is a warning message
|
628
|
+
```
|
629
|
+
|
592
630
|
#### Custom Formatters
|
593
631
|
|
594
632
|
The formatting for each appender can be replaced with custom code. To replace the
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -147,19 +147,16 @@ module SemanticLogger
|
|
147
147
|
# Add the supplied tags to the list of tags to log for this thread whilst
|
148
148
|
# the supplied block is active
|
149
149
|
# Returns nil if no tags are currently set
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
if tags
|
154
|
-
Thread.current[:semantic_logger_tags] = current_tags ? current_tags + tags : tags
|
155
|
-
end
|
150
|
+
# To support: ActiveSupport::TaggedLogging V3 and above
|
151
|
+
def tagged(*tags)
|
152
|
+
push_tags(*tags)
|
156
153
|
yield
|
157
154
|
ensure
|
158
|
-
|
155
|
+
pop_tags(tags.size)
|
159
156
|
end
|
160
157
|
|
161
|
-
#
|
162
|
-
alias_method :
|
158
|
+
# Previous method for supplying tags
|
159
|
+
alias_method :with_tags, :tagged
|
163
160
|
|
164
161
|
# Returns [Array] of [String] tags currently active for this thread
|
165
162
|
# Returns nil if no tags are set
|
@@ -167,6 +164,21 @@ module SemanticLogger
|
|
167
164
|
Thread.current[:semantic_logger_tags]
|
168
165
|
end
|
169
166
|
|
167
|
+
# Add tags to the current scope
|
168
|
+
# To support: ActiveSupport::TaggedLogging V4 and above
|
169
|
+
def push_tags *tags
|
170
|
+
# Check for nil tags
|
171
|
+
Thread.current[:semantic_logger_tags] = (self.tags || []) + tags if tags
|
172
|
+
end
|
173
|
+
|
174
|
+
# Remove specified number of tags from the current tag list
|
175
|
+
# To support: ActiveSupport::TaggedLogging V4 and above
|
176
|
+
def pop_tags(quantity)
|
177
|
+
if tags = self.tags
|
178
|
+
Thread.current[:semantic_logger_tags] = tags.pop(quantity)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
170
182
|
# Thread specific context information to be logged with every log entry
|
171
183
|
#
|
172
184
|
# Add a payload to all log calls on This Thread within the supplied block
|
@@ -5,6 +5,10 @@ require 'thread_safe'
|
|
5
5
|
module SemanticLogger
|
6
6
|
class Logger < Base
|
7
7
|
|
8
|
+
# Add unused formatter to support Rails 4 logging
|
9
|
+
# Formatters must be set at the appender level, not at the logger level
|
10
|
+
attr_accessor :formatter
|
11
|
+
|
8
12
|
# Returns a Logger instance
|
9
13
|
#
|
10
14
|
# Return the logger for a specific class, supports class specific log levels
|
data/others.txt
ADDED
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.2.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-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sync_attr
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/semantic_logger/logger.rb
|
61
62
|
- lib/semantic_logger/semantic_logger.rb
|
62
63
|
- lib/semantic_logger/version.rb
|
64
|
+
- others.txt
|
63
65
|
- test/appender_file_test.rb
|
64
66
|
- test/appender_mongodb_test.rb
|
65
67
|
- test/appender_wrapper_test.rb
|
@@ -86,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
88
|
version: '0'
|
87
89
|
requirements: []
|
88
90
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.0.
|
91
|
+
rubygems_version: 2.0.3
|
90
92
|
signing_key:
|
91
93
|
specification_version: 4
|
92
94
|
summary: Improved logging for Ruby
|