reasonable_log4r 0.9.0 → 1.0.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/.gitignore +7 -1
- data/.rspec +1 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +95 -1
- data/lib/reasonable_log4r.rb +2 -0
- data/lib/reasonable_log4r/monkey_patch_log4r.rb +0 -121
- data/lib/reasonable_log4r/monkey_patch_logger_factory.rb +55 -0
- data/lib/reasonable_log4r/monkey_patch_yaml_configurator.rb +68 -0
- data/lib/reasonable_log4r/version.rb +1 -1
- data/reasonable_log4r.gemspec +4 -1
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README +1 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database-sample.yml +32 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec/spec_helper.rb +38 -0
- data/spec/monkey_patch_log4r_spec.rb +151 -0
- data/spec/monkey_patch_logger_factory_spec.rb +66 -0
- data/spec/monkey_patch_yaml_configurator_spec.rb +129 -0
- data/spec/spec_helper.rb +33 -0
- metadata +122 -5
- data/init.rb +0 -1
- data/lib/tasks/desirable_tasks.rake +0 -4
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
CHANGED
@@ -5,8 +5,6 @@ source "http://rubygems.org"
|
|
5
5
|
# development dependencies will be added by default to the :development group.
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem 'log4r', '1.1.10'
|
9
|
-
|
10
8
|
# Declare any dependencies that are still in development here instead of in
|
11
9
|
# your gemspec. These might include edge Rails or gems from your path or
|
12
10
|
# Git. Remember to move these dependencies to your gemspec before releasing
|
@@ -14,3 +12,4 @@ gem 'log4r', '1.1.10'
|
|
14
12
|
|
15
13
|
# To use debugger
|
16
14
|
# gem 'ruby-debug'
|
15
|
+
gem 'log4r', '1.1.10'
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,107 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
reasonable_log4r (0.
|
4
|
+
reasonable_log4r (1.0.0)
|
5
5
|
log4r (= 1.1.10)
|
6
|
+
pg
|
7
|
+
rails (>= 3.0.0)
|
8
|
+
rspec-rails
|
6
9
|
|
7
10
|
GEM
|
8
11
|
remote: http://rubygems.org/
|
9
12
|
specs:
|
13
|
+
actionmailer (3.2.8)
|
14
|
+
actionpack (= 3.2.8)
|
15
|
+
mail (~> 2.4.4)
|
16
|
+
actionpack (3.2.8)
|
17
|
+
activemodel (= 3.2.8)
|
18
|
+
activesupport (= 3.2.8)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
erubis (~> 2.7.0)
|
21
|
+
journey (~> 1.0.4)
|
22
|
+
rack (~> 1.4.0)
|
23
|
+
rack-cache (~> 1.2)
|
24
|
+
rack-test (~> 0.6.1)
|
25
|
+
sprockets (~> 2.1.3)
|
26
|
+
activemodel (3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
builder (~> 3.0.0)
|
29
|
+
activerecord (3.2.8)
|
30
|
+
activemodel (= 3.2.8)
|
31
|
+
activesupport (= 3.2.8)
|
32
|
+
arel (~> 3.0.2)
|
33
|
+
tzinfo (~> 0.3.29)
|
34
|
+
activeresource (3.2.8)
|
35
|
+
activemodel (= 3.2.8)
|
36
|
+
activesupport (= 3.2.8)
|
37
|
+
activesupport (3.2.8)
|
38
|
+
i18n (~> 0.6)
|
39
|
+
multi_json (~> 1.0)
|
40
|
+
arel (3.0.2)
|
41
|
+
builder (3.0.3)
|
42
|
+
diff-lcs (1.1.3)
|
43
|
+
erubis (2.7.0)
|
44
|
+
hike (1.2.1)
|
45
|
+
i18n (0.6.1)
|
46
|
+
journey (1.0.4)
|
47
|
+
json (1.7.5)
|
10
48
|
log4r (1.1.10)
|
49
|
+
mail (2.4.4)
|
50
|
+
i18n (>= 0.4.0)
|
51
|
+
mime-types (~> 1.16)
|
52
|
+
treetop (~> 1.4.8)
|
53
|
+
mime-types (1.19)
|
54
|
+
multi_json (1.3.6)
|
55
|
+
pg (0.14.1)
|
56
|
+
polyglot (0.3.3)
|
57
|
+
rack (1.4.1)
|
58
|
+
rack-cache (1.2)
|
59
|
+
rack (>= 0.4)
|
60
|
+
rack-ssl (1.3.2)
|
61
|
+
rack
|
62
|
+
rack-test (0.6.1)
|
63
|
+
rack (>= 1.0)
|
64
|
+
rails (3.2.8)
|
65
|
+
actionmailer (= 3.2.8)
|
66
|
+
actionpack (= 3.2.8)
|
67
|
+
activerecord (= 3.2.8)
|
68
|
+
activeresource (= 3.2.8)
|
69
|
+
activesupport (= 3.2.8)
|
70
|
+
bundler (~> 1.0)
|
71
|
+
railties (= 3.2.8)
|
72
|
+
railties (3.2.8)
|
73
|
+
actionpack (= 3.2.8)
|
74
|
+
activesupport (= 3.2.8)
|
75
|
+
rack-ssl (~> 1.3.2)
|
76
|
+
rake (>= 0.8.7)
|
77
|
+
rdoc (~> 3.4)
|
78
|
+
thor (>= 0.14.6, < 2.0)
|
79
|
+
rake (0.9.2.2)
|
80
|
+
rdoc (3.12)
|
81
|
+
json (~> 1.4)
|
82
|
+
rspec (2.11.0)
|
83
|
+
rspec-core (~> 2.11.0)
|
84
|
+
rspec-expectations (~> 2.11.0)
|
85
|
+
rspec-mocks (~> 2.11.0)
|
86
|
+
rspec-core (2.11.1)
|
87
|
+
rspec-expectations (2.11.3)
|
88
|
+
diff-lcs (~> 1.1.3)
|
89
|
+
rspec-mocks (2.11.3)
|
90
|
+
rspec-rails (2.11.0)
|
91
|
+
actionpack (>= 3.0)
|
92
|
+
activesupport (>= 3.0)
|
93
|
+
railties (>= 3.0)
|
94
|
+
rspec (~> 2.11.0)
|
95
|
+
sprockets (2.1.3)
|
96
|
+
hike (~> 1.2)
|
97
|
+
rack (~> 1.0)
|
98
|
+
tilt (~> 1.1, != 1.3.0)
|
99
|
+
thor (0.16.0)
|
100
|
+
tilt (1.3.3)
|
101
|
+
treetop (1.4.10)
|
102
|
+
polyglot
|
103
|
+
polyglot (>= 0.3.1)
|
104
|
+
tzinfo (0.3.33)
|
11
105
|
|
12
106
|
PLATFORMS
|
13
107
|
ruby
|
data/lib/reasonable_log4r.rb
CHANGED
@@ -64,125 +64,4 @@ module Log4r
|
|
64
64
|
# Does nothing
|
65
65
|
def remove(*foo); end
|
66
66
|
end
|
67
|
-
|
68
|
-
class Logger
|
69
|
-
# Returns the root logger. Identical to Logger.global
|
70
|
-
def self.root; return RootLogger.instance end
|
71
|
-
# Returns the root logger. Identical to Logger.root
|
72
|
-
def self.global; return GlobalLogger.instance end
|
73
|
-
|
74
|
-
# Get a logger with a fullname from the repository or nil if logger
|
75
|
-
# wasn't found.
|
76
|
-
|
77
|
-
def self.[](_fullname)
|
78
|
-
# forces creation of RootLogger if it doesn't exist yet.
|
79
|
-
if _fullname=='root'
|
80
|
-
return RootLogger.instance
|
81
|
-
end
|
82
|
-
if _fullname=='global'
|
83
|
-
return GlobalLogger.instance
|
84
|
-
end
|
85
|
-
Repository[_fullname]
|
86
|
-
end
|
87
|
-
|
88
|
-
class LoggerFactory #:nodoc:
|
89
|
-
# we want to log iff root.lev <= lev && logger.lev <= lev
|
90
|
-
# BTW, root is guaranteed to be defined by this point
|
91
|
-
def self.define_methods(logger)
|
92
|
-
undefine_methods(logger)
|
93
|
-
globlev = Log4r::Logger['global'].level
|
94
|
-
return if logger.level == OFF or globlev == OFF
|
95
|
-
toggle_methods(globlev, logger)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Logger logging methods are defined here.
|
99
|
-
def self.set_log(logger, lname)
|
100
|
-
# invoke caller iff the logger invoked is tracing
|
101
|
-
tracercall = (logger.trace ? "caller" : "nil")
|
102
|
-
# maybe pass parent a logevent. second arg is the switch
|
103
|
-
if logger.additive && !logger.is_root?
|
104
|
-
parentcall = "@parent.#{lname.downcase}(event, true)"
|
105
|
-
end
|
106
|
-
mstr = %-
|
107
|
-
def logger.#{lname.downcase}(data=nil, propagated=false)
|
108
|
-
if propagated then event = data
|
109
|
-
else
|
110
|
-
data = yield if block_given?
|
111
|
-
event = LogEvent.new(#{lname}, self, #{tracercall}, data)
|
112
|
-
end
|
113
|
-
@outputters.each {|o| o.#{lname.downcase}(event) }
|
114
|
-
#{parentcall}
|
115
|
-
end
|
116
|
-
-
|
117
|
-
module_eval mstr
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
class YamlConfigurator
|
123
|
-
# Given a filename, loads the YAML configuration for Log4r.
|
124
|
-
def self.load_yaml_files(filenames, yaml_sections = ['log4r_config'])
|
125
|
-
cfgs = []
|
126
|
-
yaml_sections.each do |yaml_section|
|
127
|
-
filenames.each do |filename|
|
128
|
-
log4r_config = nil
|
129
|
-
docs = File.open(filename)
|
130
|
-
begin
|
131
|
-
YAML.load_documents(docs) do |doc|
|
132
|
-
doc.has_key?(yaml_section) and log4r_config = doc[yaml_section] and break
|
133
|
-
end
|
134
|
-
rescue Exception => e
|
135
|
-
raise "YAML error, file: #{filename}, error=#{e.message}"
|
136
|
-
end
|
137
|
-
if log4r_config
|
138
|
-
cfgs << log4r_config
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
cfgs.each do |cfg|
|
144
|
-
decode_pre_config(cfg['pre_config']) unless cfg['pre_config'].nil?
|
145
|
-
end
|
146
|
-
|
147
|
-
cfgs.each do |cfg|
|
148
|
-
cfg['outputters'].each{ |op| decode_outputter(op)} unless cfg['outputters'].nil?
|
149
|
-
end
|
150
|
-
|
151
|
-
cfgs.each do |cfg|
|
152
|
-
cfg['loggers'].each{ |lo| decode_logger(lo)} unless cfg['loggers'].nil?
|
153
|
-
end
|
154
|
-
|
155
|
-
cfgs.each do |cfg|
|
156
|
-
cfg['logserver'].each{ |lo| decode_logserver(lo)} unless cfg['logserver'].nil?
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
def self.decode_pre_config(pre)
|
161
|
-
return Logger.root if pre.nil?
|
162
|
-
decode_custom_levels( pre['custom_levels'])
|
163
|
-
global_config( pre['global'])
|
164
|
-
root_config( pre['root'])
|
165
|
-
decode_parameters( pre['parameters'])
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.root_config(e)
|
169
|
-
return if e.nil?
|
170
|
-
globlev = e['level']
|
171
|
-
return if globlev.nil?
|
172
|
-
lev = LNAMES.index(globlev) # find value in LNAMES
|
173
|
-
Log4rTools.validate_level(lev, 4) # choke on bad level
|
174
|
-
Logger.root.level = lev
|
175
|
-
end
|
176
|
-
|
177
|
-
def self.decode_logger(lo)
|
178
|
-
if lo['name'] == 'root'
|
179
|
-
l = Logger.root
|
180
|
-
elsif lo['name'] == 'global'
|
181
|
-
l = Logger.global
|
182
|
-
else
|
183
|
-
l = Logger.new lo['name']
|
184
|
-
end
|
185
|
-
decode_logger_common(l, lo)
|
186
|
-
end
|
187
|
-
end
|
188
67
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Log4r
|
2
|
+
class Logger
|
3
|
+
# Returns the root logger. Identical to Logger.global
|
4
|
+
def self.root; return RootLogger.instance end
|
5
|
+
# Returns the root logger. Identical to Logger.root
|
6
|
+
def self.global; return GlobalLogger.instance end
|
7
|
+
|
8
|
+
# Get a logger with a fullname from the repository or nil if logger
|
9
|
+
# wasn't found.
|
10
|
+
|
11
|
+
def self.[](_fullname)
|
12
|
+
# forces creation of RootLogger if it doesn't exist yet.
|
13
|
+
if _fullname=='root'
|
14
|
+
return RootLogger.instance
|
15
|
+
end
|
16
|
+
if _fullname=='global'
|
17
|
+
return GlobalLogger.instance
|
18
|
+
end
|
19
|
+
Repository[_fullname]
|
20
|
+
end
|
21
|
+
|
22
|
+
class LoggerFactory #:nodoc:
|
23
|
+
# we want to log if root.lev <= lev && logger.lev <= lev
|
24
|
+
# BTW, root is guaranteed to be defined by this point
|
25
|
+
def self.define_methods(logger)
|
26
|
+
undefine_methods(logger)
|
27
|
+
globlev = Log4r::Logger['global'].level
|
28
|
+
return if logger.level == OFF or globlev == OFF
|
29
|
+
toggle_methods(globlev, logger)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Logger logging methods are defined here.
|
33
|
+
def self.set_log(logger, lname)
|
34
|
+
# invoke caller iff the logger invoked is tracing
|
35
|
+
tracercall = (logger.trace ? "caller" : "nil")
|
36
|
+
# maybe pass parent a logevent. second arg is the switch
|
37
|
+
if logger.additive && !logger.is_root?
|
38
|
+
parentcall = "@parent.#{lname.downcase}(event, true)"
|
39
|
+
end
|
40
|
+
mstr = %-
|
41
|
+
def logger.#{lname.downcase}(data=nil, propagated=false)
|
42
|
+
if propagated then event = data
|
43
|
+
else
|
44
|
+
data = yield if block_given?
|
45
|
+
event = LogEvent.new(#{lname}, self, #{tracercall}, data)
|
46
|
+
end
|
47
|
+
@outputters.each {|o| o.#{lname.downcase}(event) }
|
48
|
+
#{parentcall}
|
49
|
+
end
|
50
|
+
-
|
51
|
+
module_eval mstr
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Log4r
|
2
|
+
class YamlConfigurator
|
3
|
+
# Given a filename, loads the YAML configuration for Log4r.
|
4
|
+
def self.load_yaml_files(filenames, yaml_sections = ['log4r_config'])
|
5
|
+
cfgs = []
|
6
|
+
yaml_sections.each do |yaml_section|
|
7
|
+
filenames.each do |filename|
|
8
|
+
log4r_config = nil
|
9
|
+
docs = File.open(filename)
|
10
|
+
begin
|
11
|
+
YAML.load_documents(docs) do |doc|
|
12
|
+
doc.has_key?(yaml_section) and log4r_config = doc[yaml_section] and break
|
13
|
+
end
|
14
|
+
rescue Exception => e
|
15
|
+
raise "YAML error, file: #{filename}, error=#{e.message}"
|
16
|
+
end
|
17
|
+
if log4r_config
|
18
|
+
cfgs << log4r_config
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
cfgs.each do |cfg|
|
24
|
+
decode_pre_config(cfg['pre_config']) unless cfg['pre_config'].nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
cfgs.each do |cfg|
|
28
|
+
cfg['outputters'].each{ |op| decode_outputter(op)} unless cfg['outputters'].nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
cfgs.each do |cfg|
|
32
|
+
cfg['loggers'].each{ |lo| decode_logger(lo)} unless cfg['loggers'].nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
cfgs.each do |cfg|
|
36
|
+
cfg['logserver'].each{ |lo| decode_logserver(lo)} unless cfg['logserver'].nil?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.decode_pre_config(pre)
|
41
|
+
return Logger.root if pre.nil?
|
42
|
+
decode_custom_levels( pre['custom_levels'])
|
43
|
+
global_config( pre['global'])
|
44
|
+
root_config( pre['root'])
|
45
|
+
decode_parameters( pre['parameters'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.root_config(e)
|
49
|
+
return if e.nil?
|
50
|
+
globlev = e['level']
|
51
|
+
return if globlev.nil?
|
52
|
+
lev = LNAMES.index(globlev) # find value in LNAMES
|
53
|
+
Log4rTools.validate_level(lev, 4) # choke on bad level
|
54
|
+
Logger.root.level = lev
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.decode_logger(lo)
|
58
|
+
if lo['name'] == 'root'
|
59
|
+
l = Logger.root
|
60
|
+
elsif lo['name'] == 'global'
|
61
|
+
l = Logger.global
|
62
|
+
else
|
63
|
+
l = Logger.new lo['name']
|
64
|
+
end
|
65
|
+
decode_logger_common(l, lo)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/reasonable_log4r.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.name = 'reasonable_log4r'
|
8
8
|
s.version = ReasonableLog4r::VERSION
|
9
9
|
s.license = 'New BSD License'
|
10
|
-
s.date = '2012-09-
|
10
|
+
s.date = '2012-09-26'
|
11
11
|
s.summary = "Patches log4r gem to make it work in a reasonable way(Tm)."
|
12
12
|
s.description = "Reasonable patches to log4r gem including root loggers having outputters and yaml configurator supporting many files and yaml sections."
|
13
13
|
s.authors = ["Keith Gabryelski"]
|
@@ -17,4 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_path = 'lib'
|
18
18
|
s.homepage = 'http://github.com/fiksu/reasonable_log4r'
|
19
19
|
s.add_dependency 'log4r', '1.1.10'
|
20
|
+
s.add_dependency "pg"
|
21
|
+
s.add_dependency "rails", '>= 3.0.0'
|
22
|
+
s.add_dependency 'rspec-rails'
|
20
23
|
end
|
data/spec/dummy/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/dummy/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
== dummy project
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require_tree .
|