mongoid_colored_logger 0.1.5 → 0.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.
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/VERSION +1 -1
- data/lib/mongoid_colored_logger/logger_decorator.rb +28 -27
- data/lib/mongoid_colored_logger/railtie.rb +4 -3
- data/mongoid_colored_logger.gemspec +5 -5
- metadata +7 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -8,7 +8,7 @@ GEM
|
|
|
8
8
|
i18n (~> 0.6)
|
|
9
9
|
multi_json (~> 1.0)
|
|
10
10
|
bson (1.7.0)
|
|
11
|
-
builder (3.0.
|
|
11
|
+
builder (3.0.4)
|
|
12
12
|
git (1.2.5)
|
|
13
13
|
i18n (0.6.1)
|
|
14
14
|
jeweler (1.8.4)
|
|
@@ -27,7 +27,7 @@ GEM
|
|
|
27
27
|
rake (0.9.2.2)
|
|
28
28
|
rdoc (3.12)
|
|
29
29
|
json (~> 1.4)
|
|
30
|
-
tzinfo (0.3.
|
|
30
|
+
tzinfo (0.3.34)
|
|
31
31
|
|
|
32
32
|
PLATFORMS
|
|
33
33
|
ruby
|
|
@@ -36,5 +36,5 @@ DEPENDENCIES
|
|
|
36
36
|
bundler (~> 1.0)
|
|
37
37
|
jeweler (~> 1.8.0)
|
|
38
38
|
mongo (~> 1.6)
|
|
39
|
-
mongoid
|
|
39
|
+
mongoid
|
|
40
40
|
rdoc (~> 3.12)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
module MongoidColoredLogger
|
|
2
2
|
class LoggerDecorator
|
|
3
|
-
module Severity
|
|
4
|
-
DEBUG = 0
|
|
5
|
-
INFO = 1
|
|
6
|
-
WARN = 2
|
|
7
|
-
ERROR = 3
|
|
8
|
-
FATAL = 4
|
|
9
|
-
UNKNOWN = 5
|
|
10
|
-
end
|
|
11
|
-
include Severity
|
|
12
|
-
|
|
13
3
|
WHITE = "\e[37m"
|
|
14
4
|
CYAN = "\e[36m"
|
|
15
5
|
MAGENTA = "\e[35m"
|
|
@@ -26,20 +16,15 @@ module MongoidColoredLogger
|
|
|
26
16
|
@logger = logger
|
|
27
17
|
end
|
|
28
18
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
|
39
|
-
def #{method}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
|
|
40
|
-
add(#{method.upcase}, message, progname, &block) # add(DEBUG, message, progname, &block)
|
|
41
|
-
end # end
|
|
42
|
-
EOT
|
|
19
|
+
colorize_method = Mongoid::VERSION.to_f >= 3.0 ? :colorize_message : :colorize_legacy_message
|
|
20
|
+
|
|
21
|
+
%w[debug info warn error fatal unknown].each.with_index do |method, severity|
|
|
22
|
+
define_method(method) do |message = nil, progname = nil, &block|
|
|
23
|
+
message = block.call if message.nil? and block_given?
|
|
24
|
+
message = self.send(colorize_method, message.to_s)
|
|
25
|
+
|
|
26
|
+
@logger.add(severity, message, progname, &block)
|
|
27
|
+
end
|
|
43
28
|
end
|
|
44
29
|
|
|
45
30
|
# Proxy everything else to the logger instance
|
|
@@ -47,7 +32,7 @@ module MongoidColoredLogger
|
|
|
47
32
|
super || @logger.respond_to?(method)
|
|
48
33
|
end
|
|
49
34
|
|
|
50
|
-
|
|
35
|
+
private
|
|
51
36
|
def method_missing(method, *args, &block)
|
|
52
37
|
@logger.send(method, *args, &block)
|
|
53
38
|
end
|
|
@@ -58,10 +43,26 @@ module MongoidColoredLogger
|
|
|
58
43
|
"#{bold}#{color}#{text}#{CLEAR}"
|
|
59
44
|
end
|
|
60
45
|
|
|
46
|
+
# Used for Mongoid < 3.0
|
|
47
|
+
def colorize_legacy_message(message)
|
|
48
|
+
message.sub('MONGODB', color('MONGODB', odd? ? CYAN : MAGENTA)).
|
|
49
|
+
sub(%r{(?<=\[')([^']+)}) {|m| color(m, BLUE)}.
|
|
50
|
+
sub(%r{(?<=\]\.)\w+}) {|m| color(m, YELLOW)}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Used for Mongoid >= 3.0
|
|
54
|
+
def colorize_message(message)
|
|
55
|
+
message = message.sub('MONGODB', color('MONGODB', odd? ? CYAN : MAGENTA)).
|
|
56
|
+
sub(%r{(?<=\[')([^']+)}) {|m| color(m, BLUE)}.
|
|
57
|
+
sub(%r{(?<=\]\.)\w+}) {|m| color(m, YELLOW)}
|
|
58
|
+
message.sub('MOPED:', color('MOPED:', odd? ? CYAN : MAGENTA)).
|
|
59
|
+
sub(/\{.+?\}\s/) { |m| color(m, BLUE) }.
|
|
60
|
+
sub(/COMMAND|QUERY|KILL_CURSORS/) { |m| color(m, YELLOW) }.
|
|
61
|
+
sub(/[\d\.]+ms/) { |m| color(m, GREEN) }
|
|
62
|
+
end
|
|
63
|
+
|
|
61
64
|
def odd?
|
|
62
65
|
@odd_or_even = ! @odd_or_even
|
|
63
66
|
end
|
|
64
|
-
|
|
65
67
|
end
|
|
66
|
-
|
|
67
68
|
end
|
|
@@ -3,14 +3,15 @@ require 'mongoid_colored_logger/logger_decorator'
|
|
|
3
3
|
module MongoidColoredLogger
|
|
4
4
|
|
|
5
5
|
class Railtie < Rails::Railtie
|
|
6
|
+
base = Mongoid::VERSION.to_f >= 3.0 ? Moped : config.mongoid
|
|
7
|
+
|
|
6
8
|
initializer 'logger_decorator', :after => :initialize_logger do
|
|
7
|
-
|
|
9
|
+
base.logger = MongoidColoredLogger::LoggerDecorator.new(Rails.logger)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
# Make it output to STDERR in console
|
|
11
13
|
console do |app|
|
|
12
|
-
|
|
14
|
+
base.logger = MongoidColoredLogger::LoggerDecorator.new(Logger.new(STDERR))
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
|
-
|
|
16
17
|
end
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "mongoid_colored_logger"
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.2.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Roman Shterenzon"]
|
|
12
|
-
s.date = "2012-
|
|
12
|
+
s.date = "2012-11-01"
|
|
13
13
|
s.description = "Beautiful logging for Mongoid"
|
|
14
14
|
s.email = "romanbsd@yahoo.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -40,20 +40,20 @@ Gem::Specification.new do |s|
|
|
|
40
40
|
s.specification_version = 3
|
|
41
41
|
|
|
42
42
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
43
|
-
s.add_runtime_dependency(%q<mongoid>, ["
|
|
43
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 0"])
|
|
44
44
|
s.add_runtime_dependency(%q<mongo>, ["~> 1.6"])
|
|
45
45
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
46
46
|
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
|
47
47
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
|
|
48
48
|
else
|
|
49
|
-
s.add_dependency(%q<mongoid>, ["
|
|
49
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
|
50
50
|
s.add_dependency(%q<mongo>, ["~> 1.6"])
|
|
51
51
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
52
52
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
|
53
53
|
s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
|
|
54
54
|
end
|
|
55
55
|
else
|
|
56
|
-
s.add_dependency(%q<mongoid>, ["
|
|
56
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
|
57
57
|
s.add_dependency(%q<mongo>, ["~> 1.6"])
|
|
58
58
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
59
59
|
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid_colored_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,24 +9,24 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2012-
|
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mongoid
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - ! '>='
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '
|
|
21
|
+
version: '0'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ! '>='
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '
|
|
29
|
+
version: '0'
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: mongo
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
126
126
|
version: '0'
|
|
127
127
|
segments:
|
|
128
128
|
- 0
|
|
129
|
-
hash:
|
|
129
|
+
hash: 686914334206650253
|
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
131
|
none: false
|
|
132
132
|
requirements:
|