reasonable_log4r 0.9.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 ADDED
@@ -0,0 +1,18 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
16
+ .idea/*
17
+ database.yml
18
+ /log/*.pid
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in partitioned.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ gem 'log4r', '1.1.10'
9
+
10
+ # Declare any dependencies that are still in development here instead of in
11
+ # your gemspec. These might include edge Rails or gems from your path or
12
+ # Git. Remember to move these dependencies to your gemspec before releasing
13
+ # your gem to rubygems.org.
14
+
15
+ # To use debugger
16
+ # gem 'ruby-debug'
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ reasonable_log4r (0.9.0)
5
+ log4r (= 1.1.10)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ log4r (1.1.10)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ log4r (= 1.1.10)
17
+ reasonable_log4r!
data/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2010-2012, Fiksu, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ o Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ o Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ o Fiksu, Inc. nor the names of its contributors may be used to
17
+ endorse or promote products derived from this software without
18
+ specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,10 @@
1
+ Patches for Log4r
2
+ =================
3
+
4
+ * root loggers are no longer null loggers -- you can add outputters to them
5
+ * the global logger is used to set a global log level (root is no longer used for this)
6
+ * yaml configurator has been updated to handle new root logger semantics
7
+ * yaml configurator has been updated to accept a set of files AND sections (default section: log4r_config)
8
+
9
+ What this really means is that you can set up one outputter in the root
10
+ logger to manage the default logging behavior.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ task :default => :spec
9
+
10
+ begin
11
+ require 'rdoc/task'
12
+ rescue LoadError
13
+ require 'rdoc/rdoc'
14
+ require 'rake/rdoctask'
15
+ RDoc::Task = Rake::RDocTask
16
+ end
17
+
18
+ RDoc::Task.new(:rdoc) do |rdoc|
19
+ rdoc.rdoc_dir = 'rdoc'
20
+ rdoc.title = 'ReasonableLog4r'
21
+ rdoc.options << '--line-numbers'
22
+ rdoc.rdoc_files.include('README')
23
+ rdoc.rdoc_files.include('lib/**/*.rb')
24
+ end
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'reasonable_log4r.rb'
@@ -0,0 +1,2 @@
1
+ require 'reasonable_log4r/monkey_patch_log4r'
2
+ require 'reasonable_log4r/version'
@@ -0,0 +1,188 @@
1
+ require 'log4r/logger'
2
+ require 'log4r/yamlconfigurator'
3
+
4
+ module Log4r
5
+ class RootLogger < Logger
6
+ def initialize
7
+ Log4r.define_levels(*Log4rConfig::LogLevels) # ensure levels are loaded
8
+ @level = ALL
9
+ @outputters = []
10
+ Repository['root'] = self
11
+ LoggerFactory.define_methods(self)
12
+ end
13
+
14
+ def is_root?; true end
15
+
16
+ # Set the global level. Any loggers defined thereafter will
17
+ # not log below the global level regardless of their levels.
18
+
19
+ def level=(alevel); @level = alevel end
20
+
21
+ # Does nothing
22
+ def additive=(foo); end
23
+
24
+ def outputters=(foo)
25
+ super
26
+ end
27
+ def trace=(foo)
28
+ super
29
+ end
30
+ def add(*foo)
31
+ super
32
+ end
33
+ def remove(*foo)
34
+ super
35
+ end
36
+ end
37
+
38
+ class GlobalLogger < Logger
39
+ include Singleton
40
+
41
+ def initialize
42
+ Log4r.define_levels(*Log4rConfig::LogLevels) # ensure levels are loaded
43
+ @level = ALL
44
+ @outputters = []
45
+ Repository['global'] = self
46
+ LoggerFactory.undefine_methods(self)
47
+ end
48
+
49
+ def is_root?; true end
50
+
51
+ # Set the global level. Any loggers defined thereafter will
52
+ # not log below the global level regardless of their levels.
53
+
54
+ def level=(alevel); @level = alevel end
55
+
56
+ # Does nothing
57
+ def outputters=(foo); end
58
+ # Does nothing
59
+ def trace=(foo); end
60
+ # Does nothing
61
+ def additive=(foo); end
62
+ # Does nothing
63
+ def add(*foo); end
64
+ # Does nothing
65
+ def remove(*foo); end
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
+ end
@@ -0,0 +1,4 @@
1
+ module ReasonableLog4r
2
+ # the current version of this gem
3
+ VERSION = "0.9.0"
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :desirable do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,32 @@
1
+ log4r_config:
2
+ pre_config:
3
+ custom_levels:
4
+ - DEBUG
5
+ - DEBUG_FINE
6
+ - DEBUG_MEDIUM
7
+ - DEBUG_GROSS
8
+ - DETAIL
9
+ - INFO
10
+ - WARN
11
+ - ALARM
12
+ - ERROR
13
+ - FATAL
14
+ global:
15
+ level: ALL
16
+ root :
17
+ level: ALL
18
+
19
+ loggers:
20
+ - name : root
21
+ level : ALL
22
+ outputters:
23
+ - stdout
24
+
25
+ outputters:
26
+ - type : StdoutOutputter
27
+ name : stdout
28
+ level : DEBUG
29
+ formatter:
30
+ date_pattern: '%y%m%d %H:%M:%S.%L'
31
+ pattern : '%d %p %C %l %M'
32
+ type : PatternFormatter
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "reasonable_log4r/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'reasonable_log4r'
8
+ s.version = ReasonableLog4r::VERSION
9
+ s.license = 'New BSD License'
10
+ s.date = '2012-09-16'
11
+ s.summary = "Patches log4r gem to make it work in a reasonable way(Tm)."
12
+ s.description = "Reasonable patches to log4r gem including root loggers having outputters and yaml configurator supporting many files and yaml sections."
13
+ s.authors = ["Keith Gabryelski"]
14
+ s.email = 'keith@fiksu.com'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.require_path = 'lib'
18
+ s.homepage = 'http://github.com/fiksu/reasonable_log4r'
19
+ s.add_dependency 'log4r', '1.1.10'
20
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reasonable_log4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keith Gabryelski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: log4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.10
30
+ description: Reasonable patches to log4r gem including root loggers having outputters
31
+ and yaml configurator supporting many files and yaml sections.
32
+ email: keith@fiksu.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE
41
+ - README
42
+ - Rakefile
43
+ - init.rb
44
+ - lib/reasonable_log4r.rb
45
+ - lib/reasonable_log4r/monkey_patch_log4r.rb
46
+ - lib/reasonable_log4r/version.rb
47
+ - lib/tasks/desirable_tasks.rake
48
+ - logging/configure-log4r.yml
49
+ - reasonable_log4r.gemspec
50
+ homepage: http://github.com/fiksu/reasonable_log4r
51
+ licenses:
52
+ - New BSD License
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Patches log4r gem to make it work in a reasonable way(Tm).
75
+ test_files: []