semantic_logger 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -10
- data/Rakefile +2 -2
- data/lib/semantic_logger.rb +0 -6
- data/lib/semantic_logger/loggable.rb +2 -0
- data/lib/semantic_logger/logger.rb +2 -0
- data/lib/semantic_logger/version.rb +1 -1
- metadata +6 -7
- data/lib/semantic_logger/railtie.rb +0 -73
data/README.md
CHANGED
@@ -5,6 +5,12 @@ Improved logging for Ruby
|
|
5
5
|
|
6
6
|
* http://github.com/ClarityServices/semantic_logger
|
7
7
|
|
8
|
+
### Note:
|
9
|
+
|
10
|
+
As of SemanticLogger V2.0 the Rails logging is no longer automatically replaced
|
11
|
+
when including SemanticLogger. Include the [rails_semantic_logger](http://github.com/ClarityServices/rails_semantic_logger)
|
12
|
+
to replace the Rails default logger with SemanticLogger
|
13
|
+
|
8
14
|
### Overview
|
9
15
|
|
10
16
|
Semantic Logger takes logging in Ruby to a new level by adding several new
|
@@ -433,7 +439,7 @@ logger.with_payload(:user => 'Jack', :zip_code => 12345) do
|
|
433
439
|
end
|
434
440
|
```
|
435
441
|
|
436
|
-
### Using SemanticLogger
|
442
|
+
### Using SemanticLogger standalone
|
437
443
|
|
438
444
|
Example:
|
439
445
|
|
@@ -456,15 +462,15 @@ logger.info "Hello World"
|
|
456
462
|
### Configuration
|
457
463
|
|
458
464
|
The Semantic Logger follows the principle where multiple appenders can be active
|
459
|
-
at the same time.
|
460
|
-
|
465
|
+
at the same time. For example, this allows one to log to MongoDB and the Rails
|
466
|
+
log file at the same time.
|
461
467
|
|
462
468
|
#### Rails Configuration
|
463
469
|
|
464
470
|
Add the following line to Gemfile
|
465
471
|
|
466
472
|
```ruby
|
467
|
-
gem '
|
473
|
+
gem 'rails_semantic_logger'
|
468
474
|
```
|
469
475
|
|
470
476
|
Also add the following line to Gemfile if you want to log to MongoDB
|
@@ -753,7 +759,6 @@ See the [MongoDB Appender Test](https://github.com/ClarityServices/semantic_logg
|
|
753
759
|
### Dependencies
|
754
760
|
|
755
761
|
- Ruby MRI 1.8.7, 1.9.3 (or above) Or, JRuby 1.6.3 (or above)
|
756
|
-
- Optional: Rails 3.0.10 (or above)
|
757
762
|
- Optional: To log to MongoDB, Mongo Ruby Driver 1.5.2 or above
|
758
763
|
|
759
764
|
### Install
|
@@ -766,12 +771,9 @@ To log to MongoDB, it also needs the Ruby Mongo Driver
|
|
766
771
|
|
767
772
|
### Future
|
768
773
|
|
769
|
-
-
|
770
|
-
automatically
|
771
|
-
- In V1: Add support for a configuration file that can set log level by class name
|
772
|
-
- Configuration file to support setting the log level for a specific class
|
774
|
+
- Add support for a configuration file that can set log level by class name
|
773
775
|
- Configuration file to support adding appenders
|
774
|
-
- Based on demand add appenders for: Syslog, hadoop, redis
|
776
|
+
- Based on end-user demand add appenders for: Syslog, hadoop, redis, etc..
|
775
777
|
|
776
778
|
Development
|
777
779
|
-----------
|
data/Rakefile
CHANGED
@@ -17,8 +17,8 @@ task :gem do |t|
|
|
17
17
|
spec.email = ['reidmo@gmail.com']
|
18
18
|
spec.homepage = 'https://github.com/ClarityServices/semantic_logger'
|
19
19
|
spec.date = Date.today.to_s
|
20
|
-
spec.summary = "
|
21
|
-
spec.description = "
|
20
|
+
spec.summary = "Improved logging for Ruby"
|
21
|
+
spec.description = "Semantic Logger takes logging in Ruby to a new level by adding several new capabilities to the commonly used Logging API"
|
22
22
|
spec.files = FileList["./**/*"].exclude(/.gem$/, /.log$/,/^nbproject/).map{|f| f.sub(/^\.\//, '')}
|
23
23
|
spec.has_rdoc = true
|
24
24
|
spec.add_dependency 'sync_attr'
|
data/lib/semantic_logger.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Place requires here to prevent issues on JRuby with global.require.lock=true
|
2
2
|
require 'thread'
|
3
|
-
require 'thread_safe'
|
4
|
-
require 'sync_attr'
|
5
3
|
require 'semantic_logger/version'
|
6
4
|
|
7
5
|
module SemanticLogger
|
@@ -19,7 +17,3 @@ module SemanticLogger
|
|
19
17
|
# Logging levels in order with most detailed logging first
|
20
18
|
LEVELS = [:trace, :debug, :info, :warn, :error, :fatal]
|
21
19
|
end
|
22
|
-
|
23
|
-
if defined?(Rails)
|
24
|
-
require 'semantic_logger/railtie'
|
25
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sync_attr
|
@@ -59,8 +59,8 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description:
|
63
|
-
|
62
|
+
description: Semantic Logger takes logging in Ruby to a new level by adding several
|
63
|
+
new capabilities to the commonly used Logging API
|
64
64
|
email:
|
65
65
|
- reidmo@gmail.com
|
66
66
|
executables: []
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- lib/semantic_logger/base.rb
|
77
77
|
- lib/semantic_logger/loggable.rb
|
78
78
|
- lib/semantic_logger/logger.rb
|
79
|
-
- lib/semantic_logger/railtie.rb
|
80
79
|
- lib/semantic_logger/version.rb
|
81
80
|
- lib/semantic_logger.rb
|
82
81
|
- LICENSE.txt
|
@@ -108,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
107
|
version: '0'
|
109
108
|
segments:
|
110
109
|
- 0
|
111
|
-
hash:
|
110
|
+
hash: -2743860428818841167
|
112
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
112
|
none: false
|
114
113
|
requirements:
|
@@ -120,5 +119,5 @@ rubyforge_project:
|
|
120
119
|
rubygems_version: 1.8.24
|
121
120
|
signing_key:
|
122
121
|
specification_version: 3
|
123
|
-
summary:
|
122
|
+
summary: Improved logging for Ruby
|
124
123
|
test_files: []
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
module SemanticLogger #:nodoc:
|
3
|
-
class Railtie < Rails::Railtie #:nodoc:
|
4
|
-
# Make the SemanticLogger config available in the Rails application config
|
5
|
-
#
|
6
|
-
# Example: Add the MongoDB logging appender in the Rails environment
|
7
|
-
# initializer in file config/environments/development.rb
|
8
|
-
#
|
9
|
-
# Claritybase::Application.configure do
|
10
|
-
# # Add the MongoDB logger appender only once Rails is initialized
|
11
|
-
# config.after_initialize do
|
12
|
-
# config.semantic_logger.appenders << SemanticLogger::Appender::Mongo.new(
|
13
|
-
# :db => Mongo::Connection.new['development_development']
|
14
|
-
# )
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
config.semantic_logger = ::SemanticLogger::Logger
|
18
|
-
|
19
|
-
# Initialize SemanticLogger. In a Rails environment it will automatically
|
20
|
-
# insert itself above the configured rails logger to add support for its
|
21
|
-
# additional features
|
22
|
-
#
|
23
|
-
# Also, if Mongoid is installed it will automatically start logging to Mongoid
|
24
|
-
#
|
25
|
-
# Loaded after Rails logging is initialized since SemanticLogger will continue
|
26
|
-
# to forward logging to the Rails Logger
|
27
|
-
initializer :initialize_semantic_logger, :before => :initialize_logger do
|
28
|
-
config = Rails.application.config
|
29
|
-
|
30
|
-
# Set the default log level based on the Rails config
|
31
|
-
SemanticLogger::Logger.default_level = config.log_level
|
32
|
-
|
33
|
-
# Existing loggers are ignored because servers like trinidad supply their
|
34
|
-
# own file loggers which would result in duplicate logging to the same log file
|
35
|
-
Rails.logger = config.logger = begin
|
36
|
-
# First check for Rails 3.2 path, then fallback to pre-3.2
|
37
|
-
path = ((config.paths.log.to_a rescue nil) || config.paths['log']).first
|
38
|
-
unless File.exist? File.dirname path
|
39
|
-
FileUtils.mkdir_p File.dirname path
|
40
|
-
end
|
41
|
-
|
42
|
-
# Set internal logger to log to file only, in case another appender
|
43
|
-
# experiences errors during writes
|
44
|
-
appender = SemanticLogger::Appender::File.new(path, config.log_level)
|
45
|
-
appender.name = "SemanticLogger::Logger"
|
46
|
-
SemanticLogger::Logger.logger = appender
|
47
|
-
|
48
|
-
# Add the log file to the list of appenders
|
49
|
-
SemanticLogger::Logger.appenders << SemanticLogger::Appender::File.new(path)
|
50
|
-
SemanticLogger::Logger.new(Rails)
|
51
|
-
rescue StandardError
|
52
|
-
# If not able to log to file, log to standard error with warning level only
|
53
|
-
SemanticLogger::Logger.default_level = :warn
|
54
|
-
|
55
|
-
SemanticLogger::Logger.logger = SemanticLogger::Appender::File.new(STDERR)
|
56
|
-
SemanticLogger::Logger.appenders << SemanticLogger::Appender::File.new(STDERR)
|
57
|
-
|
58
|
-
logger = SemanticLogger::Logger.new(Rails)
|
59
|
-
logger.warn(
|
60
|
-
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " +
|
61
|
-
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed."
|
62
|
-
)
|
63
|
-
logger
|
64
|
-
end
|
65
|
-
|
66
|
-
# Replace the default Rails loggers
|
67
|
-
ActiveSupport.on_load(:active_record) { self.logger = SemanticLogger::Logger.new('ActiveRecord') }
|
68
|
-
ActiveSupport.on_load(:action_controller) { self.logger = SemanticLogger::Logger.new('ActionController') }
|
69
|
-
ActiveSupport.on_load(:action_mailer) { self.logger = SemanticLogger::Logger.new('ActionMailer') }
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|