flogger 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +11 -6
- data/README.rdoc +21 -5
- data/examples/clear_logs.rb +10 -7
- data/examples/custom_format.rb +22 -0
- data/examples/custom_output.rb +4 -4
- data/examples/default_output.rb +1 -1
- data/flogger.gemspec +1 -1
- data/lib/flogger/log.rb +30 -27
- data/lib/flogger/version.rb +1 -1
- data/specs/log_spec.rb +113 -0
- data/specs/spec_helper.rb +2 -0
- metadata +54 -25
data/CHANGELOG.rdoc
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
+
*0.2.1* September 3, 2011
|
2
|
+
* method <tt>Log#clear</tt> now clears all logs by default
|
3
|
+
* the output format of log messages can now be customized
|
4
|
+
* <tt>logpaths</tt> is now <tt>config</tt> to prepare for future changes
|
5
|
+
|
1
6
|
*0.2.0* September 3, 2011
|
2
|
-
* all log output is now done though the Log#puts method
|
3
|
-
* custom log paths are now applied during Log#new initialization
|
7
|
+
* all log output is now done though the <tt>Log#puts</tt> method
|
8
|
+
* custom log paths are now applied during <tt>Log#new</tt> initialization
|
4
9
|
* most methods have been deprecated, please check the documentation[https://rubygems.org/gems/flogger]
|
5
10
|
|
6
11
|
*0.1.2* August 21, 2011
|
7
|
-
* added
|
8
|
-
* changed default log file to
|
12
|
+
* added <tt>Log#clear</tt> to clear contents of existing log files
|
13
|
+
* changed default log file to <tt>logs/application.txt</tt>
|
9
14
|
|
10
15
|
*0.1.1* August 20, 2011
|
11
|
-
* added error handling when accessing log files
|
12
|
-
* changed default log directory from
|
16
|
+
* added basic error handling when accessing log files
|
17
|
+
* changed default log directory from <tt>log</tt> to <tt>logs</tt>
|
13
18
|
|
14
19
|
*0.1.0* August 20, 2011
|
15
20
|
* initial release
|
data/README.rdoc
CHANGED
@@ -14,14 +14,20 @@ Or you can check out the latest source code via Github:
|
|
14
14
|
|
15
15
|
== Usage and Defaults
|
16
16
|
|
17
|
-
Currently, FLogger can output to various predefined logs (and perhaps more in the future). By default, all logs are placed in the
|
17
|
+
Currently, FLogger can output to various predefined logs (and perhaps more in the future). By default, all logs are placed in the <tt>logs</tt> directory within your current working directory. To change the default path, specify a different one during initialization:
|
18
18
|
|
19
|
-
@log = FLogger::Log.new do |
|
20
|
-
|
21
|
-
|
19
|
+
@log = FLogger::Log.new do |c|
|
20
|
+
c.debug = 'new/path/to/debug.log'
|
21
|
+
c.default = 'new/path/to/default.log'
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
By default, FLogger outputs a message formatted with a preceding date/time slug. To customize the default format of messages, specify a different format during initialization (Note: <tt>%s</tt> will be replaced with the log message):
|
25
|
+
|
26
|
+
@log = FLogger::Log.new do |c|
|
27
|
+
c.format = "#> %s"
|
28
|
+
end
|
29
|
+
|
30
|
+
== Example
|
25
31
|
|
26
32
|
There are a few more detailed examples in the examples directory. However, below is a simple example of using FLogger to output log messages:
|
27
33
|
|
@@ -32,3 +38,13 @@ There are a few more detailed examples in the examples directory. However, below
|
|
32
38
|
log.puts :debug, 'This message will output to logs/debug.txt by default.'
|
33
39
|
log.puts :error, 'This message will output to logs/error.txt by default.'
|
34
40
|
log.puts 'This message will output to logs/application.txt by default.'
|
41
|
+
|
42
|
+
== Log Types
|
43
|
+
|
44
|
+
Currently, there are 4 specific log types, and 1 generic:
|
45
|
+
|
46
|
+
<b>debug</b>: General application debug messages - defaults to <tt>logs/debug.txt</tt>
|
47
|
+
<b>error</b>: For general application error messages - defaults to <tt>logs/error.txt</tt>
|
48
|
+
<b>notice</b>: For general notification messages - defaults to <tt>logs/notice.txt</tt>
|
49
|
+
<b>warning</b>: For application warning messages - defaults to <tt>logs/warning.txt</tt>
|
50
|
+
<b>default</b>: General purpose log file if no other is desired - defaults to <tt>logs/application.txt</tt>
|
data/examples/clear_logs.rb
CHANGED
@@ -2,7 +2,7 @@ require 'flogger'
|
|
2
2
|
|
3
3
|
class LogFiller
|
4
4
|
def initialize
|
5
|
-
# initialize with
|
5
|
+
# initialize with defaults
|
6
6
|
@log = FLogger::Log.new
|
7
7
|
end
|
8
8
|
|
@@ -14,8 +14,14 @@ class LogFiller
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def clear
|
18
|
-
|
17
|
+
def clear
|
18
|
+
# clear specific logs
|
19
|
+
@log.clear :debug
|
20
|
+
@log.clear :error
|
21
|
+
@log.clear :default
|
22
|
+
|
23
|
+
# or clear all logs
|
24
|
+
@log.clear
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
@@ -23,8 +29,5 @@ end
|
|
23
29
|
log_filler = LogFiller.new
|
24
30
|
log_filler.fill
|
25
31
|
|
26
|
-
# clear
|
27
|
-
log_filler.clear :debug
|
28
|
-
|
29
|
-
# clear all logs
|
32
|
+
# clear logs
|
30
33
|
log_filler.clear
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'flogger'
|
2
|
+
|
3
|
+
class LogFiller
|
4
|
+
def initialize
|
5
|
+
# initialize with custom log format
|
6
|
+
@log = FLogger::Log.new do |c|
|
7
|
+
c.format = "#> %s"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def fill
|
12
|
+
100.times do |count|
|
13
|
+
@log.puts :debug, "#{count} - This is logged as a debug message."
|
14
|
+
@log.puts :error, "#{count} - This is logged as an error message."
|
15
|
+
@log.puts "#{count} - This is logged as an application message."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# create and fill logs
|
21
|
+
log_filler = LogFiller.new
|
22
|
+
log_filler.fill
|
data/examples/custom_output.rb
CHANGED
@@ -3,10 +3,10 @@ require 'flogger'
|
|
3
3
|
class LogFiller
|
4
4
|
def initialize
|
5
5
|
# initialize with custom paths
|
6
|
-
@log = FLogger::Log.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
@log = FLogger::Log.new do |c|
|
7
|
+
c.debug = 'custom/log/path/debug.log'
|
8
|
+
c.error = 'custom/log/path/error.log'
|
9
|
+
c.default = 'custom/log/path/application.log'
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/examples/default_output.rb
CHANGED
data/flogger.gemspec
CHANGED
data/lib/flogger/log.rb
CHANGED
@@ -2,20 +2,23 @@ require 'ostruct'
|
|
2
2
|
|
3
3
|
module FLogger
|
4
4
|
class Log
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :config
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
# set default
|
9
|
-
@
|
10
|
-
:debug
|
11
|
-
:error
|
12
|
-
:notice
|
13
|
-
:warning
|
14
|
-
:default
|
8
|
+
# set default configuration
|
9
|
+
@config = OpenStruct.new(
|
10
|
+
:debug => 'logs/debug.txt',
|
11
|
+
:error => 'logs/error.txt',
|
12
|
+
:notice => 'logs/notice.txt',
|
13
|
+
:warning => 'logs/warning.txt',
|
14
|
+
:default => 'logs/application.txt',
|
15
|
+
|
16
|
+
# default format for log output
|
17
|
+
:format => "[#{Time.now.asctime}] %s"
|
15
18
|
)
|
16
19
|
|
17
|
-
# yield to custom
|
18
|
-
yield @
|
20
|
+
# yield to custom configuration
|
21
|
+
yield @config if block_given?
|
19
22
|
end
|
20
23
|
|
21
24
|
# deprecated: use Log#new
|
@@ -55,48 +58,48 @@ module FLogger
|
|
55
58
|
|
56
59
|
case type
|
57
60
|
when :debug
|
58
|
-
output_to_log(@
|
61
|
+
output_to_log(@config.debug, message)
|
59
62
|
|
60
63
|
when :error
|
61
|
-
output_to_log(@
|
64
|
+
output_to_log(@config.error, message)
|
62
65
|
|
63
66
|
when :notice
|
64
|
-
output_to_log(@
|
67
|
+
output_to_log(@config.notice, message)
|
65
68
|
|
66
69
|
when :warning
|
67
|
-
output_to_log(@
|
70
|
+
output_to_log(@config.warning, message)
|
68
71
|
|
69
72
|
when :default
|
70
|
-
output_to_log(@
|
73
|
+
output_to_log(@config.default, message)
|
71
74
|
|
72
75
|
else
|
73
76
|
$stderr.puts "Log type not supported."
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
77
|
-
def clear(type = :
|
80
|
+
def clear(type = :all)
|
78
81
|
case type
|
79
82
|
when :all
|
80
|
-
clear_log_contents @
|
81
|
-
clear_log_contents @
|
82
|
-
clear_log_contents @
|
83
|
-
clear_log_contents @
|
84
|
-
clear_log_contents @
|
83
|
+
clear_log_contents @config.debug
|
84
|
+
clear_log_contents @config.error
|
85
|
+
clear_log_contents @config.notice
|
86
|
+
clear_log_contents @config.warning
|
87
|
+
clear_log_contents @config.default
|
85
88
|
|
86
89
|
when :debug
|
87
|
-
clear_log_contents @
|
90
|
+
clear_log_contents @config.debug
|
88
91
|
|
89
92
|
when :error
|
90
|
-
clear_log_contents @
|
93
|
+
clear_log_contents @config.error
|
91
94
|
|
92
95
|
when :notice
|
93
|
-
clear_log_contents @
|
96
|
+
clear_log_contents @config.notice
|
94
97
|
|
95
98
|
when :warning
|
96
|
-
clear_log_contents @
|
99
|
+
clear_log_contents @config.warning
|
97
100
|
|
98
101
|
when :default
|
99
|
-
clear_log_contents @
|
102
|
+
clear_log_contents @config.default
|
100
103
|
|
101
104
|
else
|
102
105
|
$stderr.puts "Log type not supported."
|
@@ -110,7 +113,7 @@ module FLogger
|
|
110
113
|
|
111
114
|
begin
|
112
115
|
log_file = File.open_or_create(file, 'a')
|
113
|
-
log_file.puts
|
116
|
+
log_file.puts(@config.format % message)
|
114
117
|
log_file.close
|
115
118
|
rescue Exception => e
|
116
119
|
$stderr.puts e.message
|
data/lib/flogger/version.rb
CHANGED
data/specs/log_spec.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe FLogger::Log do
|
5
|
+
before :all do
|
6
|
+
@log = FLogger::Log.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#new' do
|
10
|
+
it 'returns a new log object' do
|
11
|
+
@log.should be_an_instance_of FLogger::Log
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sets default configurations' do
|
15
|
+
@log.config.debug.should eql 'logs/debug.txt'
|
16
|
+
@log.config.error.should eql 'logs/error.txt'
|
17
|
+
@log.config.notice.should eql 'logs/notice.txt'
|
18
|
+
@log.config.warning.should eql 'logs/warning.txt'
|
19
|
+
@log.config.default.should eql 'logs/application.txt'
|
20
|
+
@log.config.format.should eql "[#{Time.now.asctime}] %s"
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets custom configurations' do
|
24
|
+
log = FLogger::Log.new do |c|
|
25
|
+
c.debug = 'custom debug log'
|
26
|
+
c.error = 'custom error log'
|
27
|
+
c.notice = 'custom notice log'
|
28
|
+
c.warning = 'custom warning log'
|
29
|
+
c.default = 'custom default log'
|
30
|
+
c.format = "#> %s"
|
31
|
+
end
|
32
|
+
|
33
|
+
log.config.debug.should eql 'custom debug log'
|
34
|
+
log.config.error.should eql 'custom error log'
|
35
|
+
log.config.notice.should eql 'custom notice log'
|
36
|
+
log.config.warning.should eql 'custom warning log'
|
37
|
+
log.config.default.should eql 'custom default log'
|
38
|
+
log.config.format.should eql "#> %s"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#puts' do
|
43
|
+
it 'outputs to debug log' do
|
44
|
+
@log.should_receive(:output_to_log).with(@log.config.debug, 'debug message')
|
45
|
+
@log.puts :debug, "debug message"
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'outputs to error log' do
|
49
|
+
@log.should_receive(:output_to_log).with(@log.config.error, 'error message')
|
50
|
+
@log.puts :error, 'error message'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'outputs to notice log' do
|
54
|
+
@log.should_receive(:output_to_log).with(@log.config.notice, 'notice message')
|
55
|
+
@log.puts :notice, 'notice message'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'outputs to warning log' do
|
59
|
+
@log.should_receive(:output_to_log).with(@log.config.warning, 'warning message')
|
60
|
+
@log.puts :warning, 'warning message'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'outputs to default log file' do
|
64
|
+
@log.should_receive(:output_to_log).with(@log.config.default, 'application message')
|
65
|
+
@log.puts 'application message'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#clear' do
|
70
|
+
it 'clears all logs by default' do
|
71
|
+
@log.should_receive(:clear_log_contents).with(@log.config.debug)
|
72
|
+
@log.should_receive(:clear_log_contents).with(@log.config.error)
|
73
|
+
@log.should_receive(:clear_log_contents).with(@log.config.notice)
|
74
|
+
@log.should_receive(:clear_log_contents).with(@log.config.warning)
|
75
|
+
@log.should_receive(:clear_log_contents).with(@log.config.default)
|
76
|
+
@log.clear
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'clears all logs' do
|
80
|
+
@log.should_receive(:clear_log_contents).with(@log.config.debug)
|
81
|
+
@log.should_receive(:clear_log_contents).with(@log.config.error)
|
82
|
+
@log.should_receive(:clear_log_contents).with(@log.config.notice)
|
83
|
+
@log.should_receive(:clear_log_contents).with(@log.config.warning)
|
84
|
+
@log.should_receive(:clear_log_contents).with(@log.config.default)
|
85
|
+
@log.clear :all
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'clears the debug log' do
|
89
|
+
@log.should_receive(:clear_log_contents).with(@log.config.debug)
|
90
|
+
@log.clear :debug
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'clears the error log' do
|
94
|
+
@log.should_receive(:clear_log_contents).with(@log.config.error)
|
95
|
+
@log.clear :error
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'clears the notice log' do
|
99
|
+
@log.should_receive(:clear_log_contents).with(@log.config.notice)
|
100
|
+
@log.clear :notice
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'clears the warning log' do
|
104
|
+
@log.should_receive(:clear_log_contents).with(@log.config.warning)
|
105
|
+
@log.clear :warning
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'clears the default log' do
|
109
|
+
@log.should_receive(:clear_log_contents).with(@log.config.default)
|
110
|
+
@log.clear :default
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
CHANGED
@@ -1,40 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: flogger
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Andre Burdette
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2011-09-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: rspec
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 23
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 6
|
32
|
+
- 0
|
33
|
+
version: 2.6.0
|
22
34
|
type: :development
|
23
|
-
|
24
|
-
version_requirements: *84575300
|
35
|
+
version_requirements: *id001
|
25
36
|
description: Simple Ruby-based logger that can output to one or several log files.
|
26
|
-
email:
|
37
|
+
email:
|
27
38
|
- andre@nerdstack.com
|
28
39
|
executables: []
|
40
|
+
|
29
41
|
extensions: []
|
42
|
+
|
30
43
|
extra_rdoc_files: []
|
31
|
-
|
44
|
+
|
45
|
+
files:
|
32
46
|
- .gitignore
|
33
47
|
- CHANGELOG.rdoc
|
34
48
|
- Gemfile
|
35
49
|
- README.rdoc
|
36
50
|
- Rakefile
|
37
51
|
- examples/clear_logs.rb
|
52
|
+
- examples/custom_format.rb
|
38
53
|
- examples/custom_output.rb
|
39
54
|
- examples/default_output.rb
|
40
55
|
- flogger.gemspec
|
@@ -42,28 +57,42 @@ files:
|
|
42
57
|
- lib/flogger/ext/file.rb
|
43
58
|
- lib/flogger/log.rb
|
44
59
|
- lib/flogger/version.rb
|
60
|
+
- specs/log_spec.rb
|
61
|
+
- specs/spec_helper.rb
|
45
62
|
homepage: https://github.com/aburdette/flogger
|
46
63
|
licenses: []
|
64
|
+
|
47
65
|
post_install_message:
|
48
66
|
rdoc_options: []
|
49
|
-
|
67
|
+
|
68
|
+
require_paths:
|
50
69
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
71
|
none: false
|
53
|
-
requirements:
|
72
|
+
requirements:
|
54
73
|
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 55
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 9
|
79
|
+
- 2
|
56
80
|
version: 1.9.2
|
57
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
82
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
63
90
|
requirements: []
|
91
|
+
|
64
92
|
rubyforge_project: flogger
|
65
93
|
rubygems_version: 1.8.10
|
66
94
|
signing_key:
|
67
95
|
specification_version: 3
|
68
96
|
summary: Simple Ruby-based logger with file output.
|
69
97
|
test_files: []
|
98
|
+
|