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.
Files changed (47) hide show
  1. data/.gitignore +7 -1
  2. data/.rspec +1 -0
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +95 -1
  5. data/lib/reasonable_log4r.rb +2 -0
  6. data/lib/reasonable_log4r/monkey_patch_log4r.rb +0 -121
  7. data/lib/reasonable_log4r/monkey_patch_logger_factory.rb +55 -0
  8. data/lib/reasonable_log4r/monkey_patch_yaml_configurator.rb +68 -0
  9. data/lib/reasonable_log4r/version.rb +1 -1
  10. data/reasonable_log4r.gemspec +4 -1
  11. data/spec/dummy/.rspec +1 -0
  12. data/spec/dummy/README +1 -0
  13. data/spec/dummy/Rakefile +7 -0
  14. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  15. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  17. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  18. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/spec/dummy/config.ru +4 -0
  20. data/spec/dummy/config/application.rb +65 -0
  21. data/spec/dummy/config/boot.rb +10 -0
  22. data/spec/dummy/config/database-sample.yml +32 -0
  23. data/spec/dummy/config/environment.rb +5 -0
  24. data/spec/dummy/config/environments/development.rb +37 -0
  25. data/spec/dummy/config/environments/production.rb +67 -0
  26. data/spec/dummy/config/environments/test.rb +37 -0
  27. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  28. data/spec/dummy/config/initializers/inflections.rb +15 -0
  29. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  30. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  31. data/spec/dummy/config/initializers/session_store.rb +8 -0
  32. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  33. data/spec/dummy/config/locales/en.yml +5 -0
  34. data/spec/dummy/config/routes.rb +58 -0
  35. data/spec/dummy/public/404.html +26 -0
  36. data/spec/dummy/public/422.html +26 -0
  37. data/spec/dummy/public/500.html +25 -0
  38. data/spec/dummy/public/favicon.ico +0 -0
  39. data/spec/dummy/script/rails +6 -0
  40. data/spec/dummy/spec/spec_helper.rb +38 -0
  41. data/spec/monkey_patch_log4r_spec.rb +151 -0
  42. data/spec/monkey_patch_logger_factory_spec.rb +66 -0
  43. data/spec/monkey_patch_yaml_configurator_spec.rb +129 -0
  44. data/spec/spec_helper.rb +33 -0
  45. metadata +122 -5
  46. data/init.rb +0 -1
  47. data/lib/tasks/desirable_tasks.rake +0 -4
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,38 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # ## Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = "random"
38
+ end
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+
3
+ module Log4r
4
+ describe RootLogger do
5
+
6
+ subject { Log4r::RootLogger.instance }
7
+
8
+ before do
9
+ Log4r::RootLogger.instance_variable_set(:@singleton__instance__, nil)
10
+ Log4r::GlobalLogger.instance_variable_set(:@singleton__instance__, nil)
11
+ Logger::Repository.instance_variable_set(:@singleton__instance__, nil)
12
+ end
13
+
14
+ context "method implements the singleton" do
15
+ context "when try to create a new object" do
16
+ it "raises NoMethodError" do
17
+ lambda { Log4r::RootLogger.new }.
18
+ should raise_error(NoMethodError, "private method `new' called for Log4r::RootLogger:Class")
19
+ end
20
+ end # when try to create a new object
21
+
22
+ context "when try to create a new object with instance method" do
23
+ it "return single object" do
24
+ subject.kind_of?(Log4r::RootLogger).should be_true
25
+ end
26
+
27
+ it "Logger::Repository['global'] includes instance object" do
28
+ subject
29
+ Logger::Repository['root'].should == subject
30
+ end
31
+ end # when try to create a new object with instance method
32
+ end # method implements the singleton
33
+
34
+ context "is_root?" do
35
+ it "returns true" do
36
+ subject.is_root?.should be_true
37
+ end
38
+ end # is_root?
39
+
40
+ context "level=" do
41
+ it "sets level name" do
42
+ subject.level=3
43
+ subject.instance_variable_get(:@level).should == 3
44
+ end
45
+ end # level=
46
+
47
+ context "additive=" do
48
+ it "does nothing" do
49
+ subject.additive='foo'.should == 'foo'
50
+ end
51
+ end # additive=
52
+
53
+ context "outputters=" do
54
+ it "sets outputters" do
55
+ subject.outputters=Log4r::Outputter.new('stdout', { :level => 3 })
56
+ subject.instance_variable_get(:@outputters).
57
+ first.kind_of?(Log4r::Outputter).should be_true
58
+ end
59
+ end # outputters=
60
+
61
+ context "trace=" do
62
+ it "sets trace" do
63
+ subject.trace = true
64
+ subject.instance_variable_get(:@trace).should be_true
65
+ end
66
+ end # trace=
67
+
68
+ context "add" do
69
+ it "added outputters" do
70
+ subject.add(Log4r::Outputter.new('stdout', { :level => 3 })).
71
+ first.kind_of?(Log4r::Outputter).should be_true
72
+ end
73
+ end # add
74
+
75
+ context "remove" do
76
+ it "removed outputters" do
77
+ subject.add(Log4r::Outputter.new('stdout', { :level => 3 }))
78
+ subject.remove('stdout')
79
+ subject.instance_variable_get(:@outputters).should == []
80
+ end
81
+ end # remove
82
+ end # RootLogger
83
+
84
+ describe GlobalLogger do
85
+
86
+ subject { Log4r::GlobalLogger.instance }
87
+
88
+ context "method implements the singleton" do
89
+ context "when try to create a new object" do
90
+ it "raises NoMethodError" do
91
+ lambda { Log4r::GlobalLogger.new }.
92
+ should raise_error(NoMethodError, "private method `new' called for Log4r::GlobalLogger:Class")
93
+ end
94
+ end # when try to create a new object
95
+
96
+ context "when try to create a new object with instance method" do
97
+ it "return single object" do
98
+ subject.kind_of?(Log4r::GlobalLogger).should be_true
99
+ end
100
+
101
+ it "Logger::Repository['global'] includes instance object" do
102
+ subject
103
+ Logger::Repository['global'].should == subject
104
+ end
105
+ end # when try to create a new object with instance method
106
+ end # method implements the singleton
107
+
108
+ context "is_root?" do
109
+ it "returns true" do
110
+ subject.is_root?.should be_true
111
+ end
112
+ end # is_root?
113
+
114
+ context "level=" do
115
+ it "sets level name" do
116
+ subject.level=('debug')
117
+ subject.instance_variable_get(:@level).should == "debug"
118
+ end
119
+ end # level=
120
+
121
+ context "outputters=" do
122
+ it "does nothing" do
123
+ subject.outputters='foo'.should == 'foo'
124
+ end
125
+ end # outputters=
126
+
127
+ context "trace=" do
128
+ it "does nothing" do
129
+ subject.trace='foo'.should == 'foo'
130
+ end
131
+ end # trace=
132
+
133
+ context "additive=" do
134
+ it "does nothing" do
135
+ subject.additive='foo'.should == 'foo'
136
+ end
137
+ end # additive=
138
+
139
+ context "add" do
140
+ it "does nothing" do
141
+ subject.add('foo').should be_nil
142
+ end
143
+ end # add
144
+
145
+ context "remove" do
146
+ it "does nothing" do
147
+ subject.remove('foo').should be_nil
148
+ end
149
+ end # remove
150
+ end # GlobalLogger
151
+ end # Log4r
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ module Log4r
4
+ describe Logger do
5
+
6
+ before do
7
+ Log4r::RootLogger.instance_variable_set(:@singleton__instance__, nil)
8
+ Log4r::GlobalLogger.instance_variable_set(:@singleton__instance__, nil)
9
+ Logger::Repository.instance_variable_set(:@singleton__instance__, nil)
10
+ end
11
+
12
+ describe "#root" do
13
+ it "returns Log4r::RootLogger object" do
14
+ Log4r::Logger.root.kind_of?(Log4r::RootLogger).should be_true
15
+ end
16
+ end # #root
17
+
18
+ describe "#global" do
19
+ it "returns Log4r::GlobalLogger object" do
20
+ Log4r::Logger.global.kind_of?(Log4r::GlobalLogger).should be_true
21
+ end
22
+ end # #global
23
+
24
+ describe "#[]" do
25
+ context "when _fullname=='root'" do
26
+ it "returns Log4r::RootLogger object" do
27
+ Log4r::Logger.[]('root').kind_of?(Log4r::RootLogger).should be_true
28
+ end
29
+ end # when _fullname=='root'
30
+
31
+ context "when _fullname=='global'" do
32
+ it "returns Log4r::globalLogger object" do
33
+ Log4r::Logger.[]('global').kind_of?(Log4r::GlobalLogger).should be_true
34
+ end
35
+ end # when _fullname=='global'
36
+
37
+ context "when _fullname isn't 'root' or 'global'" do
38
+ it "returns object from Logger::Repository" do
39
+ Logger::Repository['string'] = 1
40
+ Log4r::Logger.[]('string').should == 1
41
+ end
42
+ end # when _fullname isn't 'root' or 'global'
43
+ end # #[]
44
+
45
+ describe Logger::LoggerFactory do
46
+
47
+ let!(:log) { Log4r::Logger.new('temp') }
48
+
49
+ describe "#define_methods" do
50
+ it "receives set_log method once" do
51
+ Log4r::Logger['global'].instance_variable_set(:@level, 5)
52
+ Logger::LoggerFactory.should_receive(:set_log)
53
+ Logger::LoggerFactory.define_methods(log)
54
+ end
55
+ end # #define_methods
56
+
57
+ describe "#set_log" do
58
+ it "creates 'temp' method for logging" do
59
+ Logger::LoggerFactory.set_log(log, 'TEMP')
60
+ log.methods.select{ |x| x == :temp }.should have(1).item
61
+ end
62
+ end # #set_log
63
+
64
+ end # Logger::LoggerFactory
65
+ end # Logger
66
+ end # Log4r
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Log4r::YamlConfigurator do
4
+
5
+ let!(:yml) { Log4r::YamlConfigurator }
6
+ let!(:pre_config) { {
7
+ "custom_levels" => [ "DEBUG", "DEBUG_FINE", "DEBUG_MEDIUM",
8
+ "DEBUG_GROSS", "DETAIL", "INFO", "WARN",
9
+ "ALARM", "ERROR", "FATAL"
10
+ ],
11
+ "global" => { "level"=>"ALL" },
12
+ "root" => { "level"=>"ALL" }
13
+ } }
14
+ let!(:outputters) { {
15
+ "type" => "StdoutOutputter",
16
+ "name" => "stdout",
17
+ "level" => "DEBUG",
18
+ "formatter" => {
19
+ "date_pattern" => "%y%m%d %H:%M:%S.%L",
20
+ "pattern" => "%d %p %C %l %M",
21
+ "type" => "PatternFormatter"
22
+ }
23
+ } }
24
+ let!(:logger) { {
25
+ "name" => "root",
26
+ "level" => "ALL",
27
+ "outputters" => ["stdout"]
28
+ } }
29
+
30
+ describe "#load_yaml_files" do
31
+ it "receives decode_pre_config" do
32
+ yml.stub!(:decode_outputter)
33
+ yml.should_receive(:decode_pre_config).with(pre_config)
34
+ yml.load_yaml_files(['logging/configure-log4r.yml'])
35
+ end
36
+
37
+ it "receives decode_outputter" do
38
+ yml.should_receive(:decode_outputter).with(outputters)
39
+ yml.load_yaml_files(['logging/configure-log4r.yml'])
40
+ end
41
+
42
+ it "receives decode_logger" do
43
+ yml.should_receive(:decode_logger).with(logger)
44
+ yml.load_yaml_files(['logging/configure-log4r.yml'])
45
+ end
46
+
47
+ it "receives decode_logserver" do
48
+ # because config-log4.yml hasn't a logserver option
49
+ yml.should_not_receive(:decode_logserver)
50
+ yml.load_yaml_files(['logging/configure-log4r.yml'])
51
+ end
52
+ end # #load_yaml_files
53
+
54
+ describe "#decode_pre_config" do
55
+ context "when pre_config is nil" do
56
+ it "returns Log4r::RootLogger object" do
57
+ yml.decode_pre_config(nil).kind_of?(Log4r::RootLogger).should be_true
58
+ end
59
+ end
60
+
61
+ it "receives decode_custom_levels" do
62
+ yml.should_receive(:decode_custom_levels).with(pre_config['custom_levels'])
63
+ yml.decode_pre_config(pre_config)
64
+ end
65
+
66
+ it "receives global_config" do
67
+ yml.should_receive(:global_config).with(pre_config['global'])
68
+ yml.decode_pre_config(pre_config)
69
+ end
70
+
71
+ it "receives root_config" do
72
+ yml.should_receive(:root_config).with(pre_config['root'])
73
+ yml.decode_pre_config(pre_config)
74
+ end
75
+
76
+ it "receives decode_parameters" do
77
+ yml.should_receive(:decode_parameters).with(pre_config['parameters'])
78
+ yml.decode_pre_config(pre_config)
79
+ end
80
+ end # #decode_pre_config
81
+
82
+ describe "#root_config" do
83
+ context "when 'root' is nul" do
84
+ it { yml.root_config(nil).should be_nil }
85
+ end
86
+
87
+ context "when 'level' is nul" do
88
+ it "returns nil" do
89
+ pre_config['root']['level'] = nil
90
+ yml.root_config(pre_config['root']).should be_nil
91
+ end
92
+ end
93
+
94
+ context "when 'level' is 'FATAL'" do
95
+ it "root level equal five" do
96
+ pre_config['root']['level'] = 'FATAL'
97
+ yml.root_config(pre_config['root'])
98
+ Log4r::Logger.root.level.should == 5
99
+ end
100
+ end
101
+ end # #root_config
102
+
103
+ describe "#decode_logger" do
104
+ context "when logger name is 'root'" do
105
+ it "receives decode_logger_common with root logger" do
106
+ yml.should_receive(:decode_logger_common).with(Log4r::Logger.root, logger)
107
+ yml.decode_logger(logger)
108
+ end
109
+ end # when logger name is 'root'
110
+
111
+ context "when logger name is 'global'" do
112
+ it "receives decode_logger_common with global logger" do
113
+ logger['name'] = 'global'
114
+ yml.should_receive(:decode_logger_common).with(Log4r::Logger.global, logger)
115
+ yml.decode_logger(logger)
116
+ end
117
+ end # when logger name is 'global'
118
+
119
+ context "when logger name isn't 'global' or 'root'" do
120
+ it "receives decode_logger_common with global logger" do
121
+ logger['name'] = 'new_name'
122
+ new_log = Log4r::Logger.new('new_name')
123
+ Log4r::Logger.stub!(:new).and_return(new_log)
124
+ yml.should_receive(:decode_logger_common).with(new_log, logger)
125
+ yml.decode_logger(logger)
126
+ end
127
+ end # when logger name isn't 'global' or 'root'
128
+ end # #decode_logger
129
+ end # Log4r::YamlConfigurator