logging_assist 0.1.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,18 @@
1
+ # Logging assist
2
+
3
+ A *Basic* logging assistant to help debug your projects. Was originally created to make it easy to debug Generators
4
+ Log4r is used as the logging engine which this project wraps.
5
+
6
+ ## Note on Patches/Pull Requests
7
+
8
+ * Fork the project.
9
+ * Make your feature addition or bug fix.
10
+ * Add tests for it. This is important so I don't break it in a
11
+ future version unintentionally.
12
+ * Commit, do not mess with rakefile, version, or history.
13
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ ## Copyright
17
+
18
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "logging_assist"
5
+ gem.summary = %Q{Assists you in adding logging to any class such as a Generator}
6
+ gem.description = %Q{Wraps logging in a nice and convenient way making it easy to apply on any project}
7
+ gem.email = "kmandrup@gmail.com"
8
+ gem.homepage = "http://github.com/kristianmandrup/generator_assist"
9
+ gem.authors = ["Kristian Mandrup"]
10
+ gem.add_development_dependency "rspec", "~> 2.0.0.beta.19"
11
+ gem.add_dependency "require_all", "~> 1.1.0"
12
+ gem.add_dependency "sugar-high", "~> 0.2.3"
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ require 'require_all'
2
+ require 'sugar-high/module'
3
+
4
+ require_all File.dirname(__FILE__) + '/logging_assist'
@@ -0,0 +1,119 @@
1
+ require 'active_support/inflector'
2
+ require 'log4r'
3
+ include Log4r
4
+
5
+ module Rails::Assist::BasicLogging
6
+ def log
7
+ @log ||= Rails::Assist::Logging.new
8
+ end
9
+ end
10
+
11
+ module Rails::Assist
12
+ class Logging
13
+
14
+ attr_reader :logger
15
+
16
+ def logfile
17
+ gen_logfile = RSpec::Generator.logfile if defined?(RSpec::Generator)
18
+ gen_logfile || @logfile || 'logging.log'
19
+ end
20
+
21
+ def logfile= file
22
+ @logfile = file
23
+ end
24
+
25
+ # DEBUG < INFO < WARN < ERROR < FATAL
26
+ DEBUG_LVS = [:debug, :info, :warn, :error, :fatal]
27
+
28
+ def initialize options = {:level => :debug}
29
+ Log4r::Logger.global.level = Log4r::ALL
30
+ @logger ||= Log4r::Logger.new('logger')
31
+ add_stdout options[:level]
32
+ end
33
+
34
+ def add_outputter outputter
35
+ logger.outputters << outputter
36
+ end
37
+
38
+ def remove_outputter outputter
39
+ logger.outputters.delete(outputter)
40
+ end
41
+
42
+ def debug_lv= level
43
+ raise ArgumentError, "Debug lv must be one of #{DEBUG_LVS}" if !DEBUG_LVS.include? lv
44
+ logger.each_outputter do |name, outputter|
45
+ outputter.level = get_lv(level)
46
+ end
47
+ end
48
+
49
+ def add_stdout level = :debug
50
+ add_outputter Log4r::StdoutOutputter.new 'console', :formatter => simple_formatter, :level => get_lv(level)
51
+ end
52
+
53
+ def add_logfile level = :debug
54
+ add_outputter FileOutputter.new "logfile", :filename => logfile, :formatter => simple_formatter, :level => get_lv(level)
55
+ end
56
+
57
+ def debug msg
58
+ set_log_class do
59
+ logger.debug "[#{@log_class}]"
60
+ end
61
+ logger.debug "#{msg}"
62
+ end
63
+
64
+ def info msg
65
+ set_log_class do
66
+ logger.info "[#{@log_class}]"
67
+ end
68
+ logger.info "-- #{msg}"
69
+ end
70
+
71
+ def warn msg
72
+ set_log_class do
73
+ logger.warn "[#{@log_class}]"
74
+ end
75
+ logger.warn draw_line
76
+ logger.warn ":: #{msg}"
77
+ end
78
+
79
+ def error msg
80
+ set_log_class do
81
+ logger.warn "[#{@log_class}]"
82
+ end
83
+ logger.error draw_line
84
+ logger.error "! #{msg.upcase}"
85
+ logger.error
86
+ end
87
+
88
+ def fatal msg
89
+ set_log_class do
90
+ logger.warn "[#{@log_class}]"
91
+ end
92
+ logger.fatal draw_line :char => '='
93
+ logger.error "**** #{msg.upcase} ****"
94
+ logger.fatal draw_line :char => '='
95
+ end
96
+
97
+ protected
98
+
99
+ def get_lv level = :debug
100
+ raise ArgumentError, "Debug lv must be one of #{DEBUG_LVS}" if !DEBUG_LVS.include? level
101
+ "Log4r::#{level.to_s.upcase}".constantize
102
+ end
103
+
104
+ def simple_formatter
105
+ PatternFormatter.new(:pattern => "%m")
106
+ end
107
+
108
+ def set_log_class &block
109
+ if self.class != @log_class
110
+ @log_class = self.class
111
+ yield if block
112
+ end
113
+ end
114
+
115
+ def draw_line options = {:size => 40, :char => '-'}
116
+ options[:char] * options[:size]
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module Rails
2
+ modules :assist
3
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{logging_assist}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = %q{2010-09-11}
13
+ s.description = %q{Wraps logging in a nice and convenient way making it easy to apply on any project}
14
+ s.email = %q{kmandrup@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/logging_assist.rb",
28
+ "lib/logging_assist/logging.rb",
29
+ "lib/logging_assist/namespaces.rb",
30
+ "logging_assist.gemspec",
31
+ "spec/logging_assist/logging_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/kristianmandrup/generator_assist}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Assists you in adding logging to any class such as a Generator}
39
+ s.test_files = [
40
+ "spec/logging_assist/logging_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
50
+ s.add_runtime_dependency(%q<require_all>, ["~> 1.1.0"])
51
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.3"])
52
+ else
53
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
54
+ s.add_dependency(%q<require_all>, ["~> 1.1.0"])
55
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
59
+ s.add_dependency(%q<require_all>, ["~> 1.1.0"])
60
+ s.add_dependency(%q<sugar-high>, ["~> 0.2.3"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ class Abra
4
+ include Rails::Assist::BasicLogging
5
+ end
6
+
7
+ describe 'BasicGenerator' do
8
+ before do
9
+ @abra = Abra.new
10
+ end
11
+
12
+ it "should log to stdout" do
13
+ @abra.log.debug 'debugged msg'
14
+ @abra.log.info 'info msg here'
15
+ end
16
+
17
+ it "should log to logfile" do
18
+ @abra.log.add_logfile
19
+ @abra.log.debug 'debugged msg'
20
+ @abra.log.info 'info msg here'
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+ require 'logging_assist'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :mocha
7
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logging_assist
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kristian Mandrup
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-11 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 0
32
+ - beta
33
+ - 19
34
+ version: 2.0.0.beta.19
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: require_all
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 1
47
+ - 1
48
+ - 0
49
+ version: 1.1.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: sugar-high
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ - 2
63
+ - 3
64
+ version: 0.2.3
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ description: Wraps logging in a nice and convenient way making it easy to apply on any project
68
+ email: kmandrup@gmail.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.markdown
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - .rspec
80
+ - LICENSE
81
+ - README.markdown
82
+ - Rakefile
83
+ - VERSION
84
+ - lib/logging_assist.rb
85
+ - lib/logging_assist/logging.rb
86
+ - lib/logging_assist/namespaces.rb
87
+ - logging_assist.gemspec
88
+ - spec/logging_assist/logging_spec.rb
89
+ - spec/spec_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/kristianmandrup/generator_assist
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Assists you in adding logging to any class such as a Generator
122
+ test_files:
123
+ - spec/logging_assist/logging_spec.rb
124
+ - spec/spec_helper.rb