logging_assist 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/logging_assist/logging.rb +46 -5
- data/logging_assist.gemspec +22 -21
- data/spec/logging_assist/logging_spec.rb +29 -4
- metadata +29 -16
- data/.gitignore +0 -21
data/Rakefile
CHANGED
@@ -9,8 +9,9 @@ begin
|
|
9
9
|
gem.authors = ["Kristian Mandrup"]
|
10
10
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
11
11
|
gem.add_dependency "require_all", "~> 1.2.0"
|
12
|
+
gem.add_dependency "colorize", "~> 0.5.8"
|
12
13
|
gem.add_dependency "sugar-high", "~> 0.3.0"
|
13
|
-
gem.add_dependency "log4r",
|
14
|
+
gem.add_dependency "log4r-color", ">= 1.2"
|
14
15
|
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
17
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
-
require 'log4r'
|
2
|
+
require 'log4r-color'
|
3
3
|
include Log4r
|
4
4
|
|
5
5
|
module Rails3::Assist::BasicLogger
|
@@ -11,7 +11,9 @@ end
|
|
11
11
|
module Rails3::Assist
|
12
12
|
class Logging
|
13
13
|
|
14
|
-
attr_reader :logger
|
14
|
+
attr_reader :logger
|
15
|
+
|
16
|
+
attr_accessor :info_color, :debug_color, :warn_color, :error_color, :fatal_color
|
15
17
|
|
16
18
|
def logfile
|
17
19
|
gen_logfile = RSpec::Generator.logfile if defined?(RSpec::Generator)
|
@@ -23,12 +25,13 @@ module Rails3::Assist
|
|
23
25
|
end
|
24
26
|
|
25
27
|
# DEBUG < INFO < WARN < ERROR < FATAL
|
26
|
-
DEBUG_LVS = [:debug, :info, :warn, :error, :fatal]
|
28
|
+
DEBUG_LVS = [:debug, :info, :warn, :error, :fatal]
|
27
29
|
|
28
30
|
def initialize options = {:level => :debug}
|
29
31
|
Log4r::Logger.global.level = Log4r::ALL
|
30
32
|
@logger ||= Log4r::Logger.new('logger')
|
31
33
|
add_stdout options[:level]
|
34
|
+
color_options = options[:color_options] if options
|
32
35
|
end
|
33
36
|
|
34
37
|
def add_outputter outputter
|
@@ -47,8 +50,46 @@ module Rails3::Assist
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def add_stdout level = :debug
|
50
|
-
add_outputter Log4r::
|
53
|
+
add_outputter Log4r::ColorOutputter.new 'color', :formatter => simple_formatter, :level => get_lv(level), :colors => default_colors
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_colors
|
57
|
+
DEBUG_LVS.inject({}) do |res, lv|
|
58
|
+
res[lv] = send :"default_#{lv}_color"
|
59
|
+
res
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_color name, color_options = {}
|
64
|
+
send :"#{name}_color=", color_options
|
65
|
+
Outputter['color'].colors[name.to_sym] = color_options
|
66
|
+
Outputter['color'].colors
|
67
|
+
end
|
68
|
+
|
69
|
+
# def available_levels
|
70
|
+
# DEBUG_LVS # [:debug, :info, :warn, :error, :fatal]
|
71
|
+
# end
|
72
|
+
|
73
|
+
def default_debug_color
|
74
|
+
:cyan
|
51
75
|
end
|
76
|
+
|
77
|
+
def default_info_color
|
78
|
+
:light_blue
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_warn_color
|
82
|
+
:yellow
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_error_color
|
86
|
+
:red
|
87
|
+
end
|
88
|
+
|
89
|
+
def default_fatal_color
|
90
|
+
{:color => :white, :background => :red}
|
91
|
+
end
|
92
|
+
|
52
93
|
|
53
94
|
def add_logfile options = {}
|
54
95
|
add_outputter FileOutputter.new "logfile", :filename => options[:logfile] || logfile, :formatter => simple_formatter, :level => get_lv(options[:level] || :debug)
|
@@ -113,7 +154,7 @@ module Rails3::Assist
|
|
113
154
|
end
|
114
155
|
|
115
156
|
def draw_line options = {:size => 40, :char => '-'}
|
116
|
-
options[:char] * options[:size]
|
157
|
+
options[:char] * (options[:size] || 40)
|
117
158
|
end
|
118
159
|
end
|
119
160
|
end
|
data/logging_assist.gemspec
CHANGED
@@ -1,44 +1,42 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{logging_assist}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-09}
|
13
13
|
s.description = %q{Wraps logging in a nice and convenient way making it easy to apply on any project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"spec/spec_helper.rb"
|
21
|
+
".rspec",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/logging_assist.rb",
|
27
|
+
"lib/logging_assist/logging.rb",
|
28
|
+
"lib/logging_assist/namespaces.rb",
|
29
|
+
"logging_assist.gemspec",
|
30
|
+
"spec/logging_assist/logging_spec.rb",
|
31
|
+
"spec/spec_helper.rb"
|
33
32
|
]
|
34
33
|
s.homepage = %q{http://github.com/kristianmandrup/generator_assist}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
34
|
s.require_paths = ["lib"]
|
37
35
|
s.rubygems_version = %q{1.3.7}
|
38
36
|
s.summary = %q{Assists you in adding logging to any class such as a Generator}
|
39
37
|
s.test_files = [
|
40
38
|
"spec/logging_assist/logging_spec.rb",
|
41
|
-
|
39
|
+
"spec/spec_helper.rb"
|
42
40
|
]
|
43
41
|
|
44
42
|
if s.respond_to? :specification_version then
|
@@ -48,19 +46,22 @@ Gem::Specification.new do |s|
|
|
48
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
47
|
s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
|
50
48
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
49
|
+
s.add_runtime_dependency(%q<colorize>, ["~> 0.5.8"])
|
51
50
|
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
52
|
-
s.add_runtime_dependency(%q<log4r>, ["
|
51
|
+
s.add_runtime_dependency(%q<log4r-color>, [">= 1.2"])
|
53
52
|
else
|
54
53
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
55
54
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
55
|
+
s.add_dependency(%q<colorize>, ["~> 0.5.8"])
|
56
56
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
57
|
-
s.add_dependency(%q<log4r>, ["
|
57
|
+
s.add_dependency(%q<log4r-color>, [">= 1.2"])
|
58
58
|
end
|
59
59
|
else
|
60
60
|
s.add_dependency(%q<rspec>, [">= 2.0.0"])
|
61
61
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
62
|
+
s.add_dependency(%q<colorize>, ["~> 0.5.8"])
|
62
63
|
s.add_dependency(%q<sugar-high>, ["~> 0.3.0"])
|
63
|
-
s.add_dependency(%q<log4r>, ["
|
64
|
+
s.add_dependency(%q<log4r-color>, [">= 1.2"])
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -4,19 +4,44 @@ class Abra
|
|
4
4
|
include Rails3::Assist::BasicLogger
|
5
5
|
end
|
6
6
|
|
7
|
+
def do_logging obj
|
8
|
+
obj.logger.debug 'debugged msg'
|
9
|
+
obj.logger.info 'info msg here'
|
10
|
+
obj.logger.warn 'warn msg here'
|
11
|
+
obj.logger.error 'error msg here'
|
12
|
+
obj.logger.fatal 'error msg here'
|
13
|
+
end
|
14
|
+
|
7
15
|
describe 'BasicGenerator' do
|
8
16
|
before do
|
9
17
|
@abra = Abra.new
|
10
18
|
end
|
11
19
|
|
12
20
|
it "should log to stdout" do
|
13
|
-
@abra
|
14
|
-
|
21
|
+
do_logging @abra
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow change of color for each level" do
|
25
|
+
obj = @abra
|
26
|
+
|
27
|
+
obj.logger.set_color :debug, {:color => :blue, :background => :white}
|
28
|
+
obj.logger.info 'blue on white!'
|
29
|
+
|
30
|
+
obj.logger.set_color :info, {:color => :green, :background => :white}
|
31
|
+
obj.logger.info 'green on white!'
|
32
|
+
|
33
|
+
obj.logger.info_color[:color].should == :green
|
34
|
+
obj.logger.info_color[:background].should == :white
|
35
|
+
|
36
|
+
obj.logger.set_color :warn, {:color => :black, :background => :white}
|
37
|
+
obj.logger.warn 'black on white!'
|
38
|
+
|
39
|
+
obj.logger.warn_color[:color].should == :black
|
40
|
+
obj.logger.warn_color[:background].should == :white
|
15
41
|
end
|
16
42
|
|
17
43
|
it "should log to logfile" do
|
18
44
|
@abra.logger.add_logfile :logfile => 'here.log'
|
19
|
-
@abra
|
20
|
-
@abra.logger.info 'info msg here'
|
45
|
+
do_logging @abra
|
21
46
|
end
|
22
47
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-09 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,7 @@ dependencies:
|
|
48
48
|
type: :runtime
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
|
-
name:
|
51
|
+
name: colorize
|
52
52
|
prerelease: false
|
53
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
@@ -57,13 +57,13 @@ dependencies:
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
segments:
|
59
59
|
- 0
|
60
|
-
-
|
61
|
-
-
|
62
|
-
version: 0.
|
60
|
+
- 5
|
61
|
+
- 8
|
62
|
+
version: 0.5.8
|
63
63
|
type: :runtime
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
66
|
+
name: sugar-high
|
67
67
|
prerelease: false
|
68
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
@@ -71,12 +71,26 @@ dependencies:
|
|
71
71
|
- - ~>
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
segments:
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
version:
|
74
|
+
- 0
|
75
|
+
- 3
|
76
|
+
- 0
|
77
|
+
version: 0.3.0
|
78
78
|
type: :runtime
|
79
79
|
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: log4r-color
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 2
|
91
|
+
version: "1.2"
|
92
|
+
type: :runtime
|
93
|
+
version_requirements: *id005
|
80
94
|
description: Wraps logging in a nice and convenient way making it easy to apply on any project
|
81
95
|
email: kmandrup@gmail.com
|
82
96
|
executables: []
|
@@ -88,7 +102,6 @@ extra_rdoc_files:
|
|
88
102
|
- README.markdown
|
89
103
|
files:
|
90
104
|
- .document
|
91
|
-
- .gitignore
|
92
105
|
- .rspec
|
93
106
|
- LICENSE
|
94
107
|
- README.markdown
|
@@ -105,8 +118,8 @@ homepage: http://github.com/kristianmandrup/generator_assist
|
|
105
118
|
licenses: []
|
106
119
|
|
107
120
|
post_install_message:
|
108
|
-
rdoc_options:
|
109
|
-
|
121
|
+
rdoc_options: []
|
122
|
+
|
110
123
|
require_paths:
|
111
124
|
- lib
|
112
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|