logging_assist 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +105 -0
- data/VERSION +1 -1
- data/lib/logging_assist/logging.rb +14 -0
- data/logging_assist.gemspec +3 -3
- data/spec/logging_assist/logging_spec.rb +4 -1
- metadata +4 -4
- data/README.markdown +0 -18
data/README.textile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
h1. Logging assist
|
2
|
+
|
3
|
+
A wrapper of "Log4r-color":https://github.com/kristianmandrup/log4r-color to make it easy to add logging to your projects.
|
4
|
+
This project was originally born from a need to make it easy to debug Rails 3 Generators. It is used extensively in the "Cream":https://github.com/kristianmandrup/cream framework
|
5
|
+
|
6
|
+
h2. Install
|
7
|
+
|
8
|
+
<pre>gem install logging_assist</pre>
|
9
|
+
|
10
|
+
h2. Usage
|
11
|
+
|
12
|
+
The default logger logs to a _ColorOutputter_ with a default color scheme for each log level.
|
13
|
+
|
14
|
+
h3. Setup
|
15
|
+
|
16
|
+
Inside any class you want to add logging
|
17
|
+
|
18
|
+
<pre>class MyClassToBeLogged
|
19
|
+
include Rails3::Assist::BasicLogger
|
20
|
+
...
|
21
|
+
end
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
h3. Logging
|
25
|
+
|
26
|
+
You can use the methods _#debug_, _#info_, _#warn_, _#error_ and _#fatal_
|
27
|
+
|
28
|
+
<pre>def my_method
|
29
|
+
logger.debug 'wtf??'
|
30
|
+
logger.info "now inside #my_method"
|
31
|
+
end
|
32
|
+
</pre>
|
33
|
+
|
34
|
+
h3. Add outputters
|
35
|
+
|
36
|
+
You can easily add one or more file outputters to the mix
|
37
|
+
|
38
|
+
<pre>class MyClassToBeLogged
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
# setup logging file
|
42
|
+
logger.add_logfile :logfile => 'here.log'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
</pre>
|
46
|
+
|
47
|
+
h4. Custom outputters
|
48
|
+
|
49
|
+
For custom outputters (any supported by log4r) you can use <code>logger.add_outputter(my_custom_outputter)</code>
|
50
|
+
Here _my_custom_outputter_ must be an instance of a subclass of _Log4r::Outputter_
|
51
|
+
|
52
|
+
You can remove the outputter like this <code>logger.remove_outputter(my_custom_outputter)</code>
|
53
|
+
|
54
|
+
h4. Advanced outputter configuration
|
55
|
+
|
56
|
+
Every logger also takes a _:formatter_ and _:level_ option. Use like this:
|
57
|
+
|
58
|
+
<pre>def initialize
|
59
|
+
my_custom_formatter = PatternFormatter.new(:pattern => "[%l] %d :: %.40m")
|
60
|
+
logger.add_logfile :logfile => 'here.log', :formatter => my_custom_formatter, :level => :info
|
61
|
+
end
|
62
|
+
</pre>
|
63
|
+
|
64
|
+
See "PatternFormatter docs":http://log4r.sourceforge.net/rdoc/files/log4r/formatter/patternformatter_rb.html for more info on customizing the output formats
|
65
|
+
|
66
|
+
Currently the formatter and level of an outputter can only (easily) be set on creation when added.
|
67
|
+
|
68
|
+
h3. Remove outputters
|
69
|
+
|
70
|
+
You can remove color output to the console like this:
|
71
|
+
|
72
|
+
<pre>class MyClassToBeLogged
|
73
|
+
|
74
|
+
def initialize
|
75
|
+
# setup logging file
|
76
|
+
logger.remove_outputs :color
|
77
|
+
end
|
78
|
+
end
|
79
|
+
</pre>
|
80
|
+
|
81
|
+
Remove file outputs <code>logger.remove_outputs :file</code>
|
82
|
+
|
83
|
+
Here The following convention: _Log4r::[name]Outputter_ is used to find the types of Outputter to remove.
|
84
|
+
|
85
|
+
h3. Define custom color schemes
|
86
|
+
|
87
|
+
A color scheme can be set for any log level like this
|
88
|
+
|
89
|
+
<code>obj.logger.set_color :info, {:color => :green, :background => :white}</code>
|
90
|
+
|
91
|
+
Please see "colorize":https://github.com/fazibear/colorize for more info. Use <code>String.colors</code> to see list of available colors.
|
92
|
+
|
93
|
+
h2. Note on Patches/Pull Requests
|
94
|
+
|
95
|
+
* Fork the project.
|
96
|
+
* Make your feature addition or bug fix.
|
97
|
+
* Add tests for it. This is important so I don't break it in a
|
98
|
+
future version unintentionally.
|
99
|
+
* Commit, do not mess with rakefile, version, or history.
|
100
|
+
(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)
|
101
|
+
* Send me a pull request. Bonus points for topic branches.
|
102
|
+
|
103
|
+
h2. Copyright
|
104
|
+
|
105
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
require 'log4r-color'
|
3
|
+
require 'active_support'
|
3
4
|
include Log4r
|
4
5
|
|
5
6
|
module Rails3::Assist::BasicLogger
|
@@ -42,6 +43,19 @@ module Rails3::Assist
|
|
42
43
|
logger.outputters.delete(outputter)
|
43
44
|
end
|
44
45
|
|
46
|
+
def remove_outputs type
|
47
|
+
klass = "Log4r::#{type.to_s.classify}Outputter".constantize
|
48
|
+
logger.outputters.each do |outp|
|
49
|
+
logger.outputters.delete(outp) if outp.kind_of? klass
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# def remove_all_file_outputs
|
54
|
+
# logger.outputters.each do |outp|
|
55
|
+
# logger.outputters.delete(outp) if outp.kind_of? Log4r::FileOutputter
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
|
45
59
|
def debug_lv= level
|
46
60
|
raise ArgumentError, "Debug lv must be one of #{DEBUG_LVS}" if !DEBUG_LVS.include? lv
|
47
61
|
logger.each_outputter do |name, outputter|
|
data/logging_assist.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{logging_assist}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
@@ -14,13 +14,13 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.textile"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
22
|
"LICENSE",
|
23
|
-
"README.
|
23
|
+
"README.textile",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/logging_assist.rb",
|
@@ -37,7 +37,10 @@ describe 'BasicGenerator' do
|
|
37
37
|
obj.logger.warn 'black on white!'
|
38
38
|
|
39
39
|
obj.logger.warn_color[:color].should == :black
|
40
|
-
obj.logger.warn_color[:background].should == :white
|
40
|
+
obj.logger.warn_color[:background].should == :white
|
41
|
+
|
42
|
+
obj.logger.remove_outputs :color
|
43
|
+
obj.logger.warn 'should not be printed to screen'
|
41
44
|
end
|
42
45
|
|
43
46
|
it "should log to logfile" do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -99,12 +99,12 @@ extensions: []
|
|
99
99
|
|
100
100
|
extra_rdoc_files:
|
101
101
|
- LICENSE
|
102
|
-
- README.
|
102
|
+
- README.textile
|
103
103
|
files:
|
104
104
|
- .document
|
105
105
|
- .rspec
|
106
106
|
- LICENSE
|
107
|
-
- README.
|
107
|
+
- README.textile
|
108
108
|
- Rakefile
|
109
109
|
- VERSION
|
110
110
|
- lib/logging_assist.rb
|
data/README.markdown
DELETED
@@ -1,18 +0,0 @@
|
|
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.
|