flogger 0.2.1 → 0.2.2
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/.gitignore +1 -5
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +8 -7
- data/examples/clear_logs.rb +1 -2
- data/examples/custom_output.rb +7 -3
- data/flogger.gemspec +4 -2
- data/lib/flogger.rb +0 -1
- data/lib/flogger/log.rb +18 -11
- data/lib/flogger/version.rb +1 -1
- data/specs/log_spec.rb +23 -20
- metadata +29 -55
- data/examples/custom_format.rb +0 -22
- data/lib/flogger/ext/file.rb +0 -14
data/.gitignore
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
*0.2.2* September 6, 2011
|
2
|
+
* the old <tt>default</tt> is now renamed to <tt>application</tt>
|
3
|
+
* the new <tt>default</tt> now points to a default log specified on <tt>Log#new</tt>
|
4
|
+
* by default, <tt>Log#clear</tt> clears the log file pointed to by <tt>default</tt>
|
5
|
+
|
1
6
|
*0.2.1* September 3, 2011
|
2
7
|
* method <tt>Log#clear</tt> now clears all logs by default
|
3
8
|
* the output format of log messages can now be customized
|
data/README.rdoc
CHANGED
@@ -18,12 +18,13 @@ Currently, FLogger can output to various predefined logs (and perhaps more in th
|
|
18
18
|
|
19
19
|
@log = FLogger::Log.new do |c|
|
20
20
|
c.debug = 'new/path/to/debug.log'
|
21
|
-
c.
|
21
|
+
c.warning = 'new/path/to/warning.log'
|
22
22
|
end
|
23
23
|
|
24
|
-
By default, FLogger outputs
|
24
|
+
By default, FLogger outputs messages formatted with a preceding date/time to the application log file. To change these defaults, specify a your changes during initialization (Note: <tt>%s</tt> will be replaced with the log message):
|
25
25
|
|
26
26
|
@log = FLogger::Log.new do |c|
|
27
|
+
c.default = :warning
|
27
28
|
c.format = "#> %s"
|
28
29
|
end
|
29
30
|
|
@@ -43,8 +44,8 @@ There are a few more detailed examples in the examples directory. However, below
|
|
43
44
|
|
44
45
|
Currently, there are 4 specific log types, and 1 generic:
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
*debug*:: For general software debug messages - defaults to <tt>logs/debug.txt</tt>
|
48
|
+
*error*:: For application error messages - defaults to <tt>logs/error.txt</tt>
|
49
|
+
*notice*:: For general notification messages - defaults to <tt>logs/notice.txt</tt>
|
50
|
+
*warning*:: For application warning messages - defaults to <tt>logs/warning.txt</tt>
|
51
|
+
*application*:: General purpose application log messages - defaults to <tt>logs/application.txt</tt>
|
data/examples/clear_logs.rb
CHANGED
data/examples/custom_output.rb
CHANGED
@@ -2,11 +2,15 @@ require 'flogger'
|
|
2
2
|
|
3
3
|
class LogFiller
|
4
4
|
def initialize
|
5
|
-
# initialize with custom paths
|
6
5
|
@log = FLogger::Log.new do |c|
|
6
|
+
# initialize with custom paths
|
7
7
|
c.debug = 'custom/log/path/debug.log'
|
8
8
|
c.error = 'custom/log/path/error.log'
|
9
|
-
c.
|
9
|
+
c.warning = 'custom/log/path/warning.log'
|
10
|
+
|
11
|
+
# initialize with custom settings
|
12
|
+
c.default = :warning
|
13
|
+
c.format = "#> %s"
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
@@ -14,7 +18,7 @@ class LogFiller
|
|
14
18
|
100.times do |count|
|
15
19
|
@log.puts :debug, "#{count} - This is logged as a debug message."
|
16
20
|
@log.puts :error, "#{count} - This is logged as an error message."
|
17
|
-
@log.puts "#{count} - This is logged as
|
21
|
+
@log.puts "#{count} - This is logged as a warning message."
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
data/flogger.gemspec
CHANGED
@@ -16,8 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
|
19
20
|
s.require_paths = [ 'lib' ]
|
21
|
+
s.extra_rdoc_files = [ 'README.rdoc', 'CHANGELOG.rdoc' ]
|
20
22
|
|
21
|
-
s.required_ruby_version = '
|
22
|
-
s.add_development_dependency 'rspec', '
|
23
|
+
s.required_ruby_version = '>= 1.9.2'
|
24
|
+
s.add_development_dependency 'rspec', '>= 2.6.0'
|
23
25
|
end
|
data/lib/flogger.rb
CHANGED
data/lib/flogger/log.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
require 'ostruct'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module FLogger
|
4
5
|
class Log
|
5
6
|
attr_reader :config
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
# set default configuration
|
9
9
|
@config = OpenStruct.new(
|
10
|
+
# set default log paths
|
10
11
|
:debug => 'logs/debug.txt',
|
11
12
|
:error => 'logs/error.txt',
|
12
13
|
:notice => 'logs/notice.txt',
|
13
14
|
:warning => 'logs/warning.txt',
|
14
|
-
:
|
15
|
+
:application => 'logs/application.txt',
|
15
16
|
|
16
|
-
# default
|
17
|
+
# set default log output settings
|
18
|
+
:default => :application,
|
17
19
|
:format => "[#{Time.now.asctime}] %s"
|
18
20
|
)
|
19
21
|
|
@@ -53,7 +55,7 @@ module FLogger
|
|
53
55
|
|
54
56
|
# outputs to log file
|
55
57
|
# default: logs/application.txt
|
56
|
-
def puts(type =
|
58
|
+
def puts(type = @config.default, message)
|
57
59
|
return if message.empty?
|
58
60
|
|
59
61
|
case type
|
@@ -69,22 +71,22 @@ module FLogger
|
|
69
71
|
when :warning
|
70
72
|
output_to_log(@config.warning, message)
|
71
73
|
|
72
|
-
when :
|
73
|
-
output_to_log(@config.
|
74
|
+
when :application
|
75
|
+
output_to_log(@config.application, message)
|
74
76
|
|
75
77
|
else
|
76
78
|
$stderr.puts "Log type not supported."
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
|
-
def clear(type =
|
82
|
+
def clear(type = @config.default)
|
81
83
|
case type
|
82
84
|
when :all
|
83
85
|
clear_log_contents @config.debug
|
84
86
|
clear_log_contents @config.error
|
85
87
|
clear_log_contents @config.notice
|
86
88
|
clear_log_contents @config.warning
|
87
|
-
clear_log_contents @config.
|
89
|
+
clear_log_contents @config.application
|
88
90
|
|
89
91
|
when :debug
|
90
92
|
clear_log_contents @config.debug
|
@@ -98,8 +100,8 @@ module FLogger
|
|
98
100
|
when :warning
|
99
101
|
clear_log_contents @config.warning
|
100
102
|
|
101
|
-
when :
|
102
|
-
clear_log_contents @config.
|
103
|
+
when :application
|
104
|
+
clear_log_contents @config.application
|
103
105
|
|
104
106
|
else
|
105
107
|
$stderr.puts "Log type not supported."
|
@@ -112,7 +114,12 @@ module FLogger
|
|
112
114
|
return if message.empty?
|
113
115
|
|
114
116
|
begin
|
115
|
-
|
117
|
+
unless File.exists?(file)
|
118
|
+
path = File.dirname(file)
|
119
|
+
FileUtils.mkdir_p(path)
|
120
|
+
end
|
121
|
+
|
122
|
+
log_file = File.open(file, 'a')
|
116
123
|
log_file.puts(@config.format % message)
|
117
124
|
log_file.close
|
118
125
|
rescue Exception => e
|
data/lib/flogger/version.rb
CHANGED
data/specs/log_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require './specs/spec_helper'
|
3
2
|
|
4
3
|
describe FLogger::Log do
|
5
4
|
before :all do
|
@@ -16,7 +15,8 @@ describe FLogger::Log do
|
|
16
15
|
@log.config.error.should eql 'logs/error.txt'
|
17
16
|
@log.config.notice.should eql 'logs/notice.txt'
|
18
17
|
@log.config.warning.should eql 'logs/warning.txt'
|
19
|
-
@log.config.
|
18
|
+
@log.config.application.should eql 'logs/application.txt'
|
19
|
+
@log.config.default.should eql :application
|
20
20
|
@log.config.format.should eql "[#{Time.now.asctime}] %s"
|
21
21
|
end
|
22
22
|
|
@@ -26,7 +26,8 @@ describe FLogger::Log do
|
|
26
26
|
c.error = 'custom error log'
|
27
27
|
c.notice = 'custom notice log'
|
28
28
|
c.warning = 'custom warning log'
|
29
|
-
c.
|
29
|
+
c.application = 'custom application log'
|
30
|
+
c.default = :warning
|
30
31
|
c.format = "#> %s"
|
31
32
|
end
|
32
33
|
|
@@ -34,7 +35,8 @@ describe FLogger::Log do
|
|
34
35
|
log.config.error.should eql 'custom error log'
|
35
36
|
log.config.notice.should eql 'custom notice log'
|
36
37
|
log.config.warning.should eql 'custom warning log'
|
37
|
-
log.config.
|
38
|
+
log.config.application.should eql 'custom application log'
|
39
|
+
log.config.default.should eql :warning
|
38
40
|
log.config.format.should eql "#> %s"
|
39
41
|
end
|
40
42
|
end
|
@@ -60,28 +62,24 @@ describe FLogger::Log do
|
|
60
62
|
@log.puts :warning, 'warning message'
|
61
63
|
end
|
62
64
|
|
65
|
+
it 'outputs to application log file' do
|
66
|
+
@log.should_receive(:output_to_log).with(@log.config.application, 'application message')
|
67
|
+
@log.puts :application, 'application message'
|
68
|
+
end
|
69
|
+
|
63
70
|
it 'outputs to default log file' do
|
64
|
-
@log.should_receive(:output_to_log).with(@log.config.
|
65
|
-
@log.puts '
|
71
|
+
@log.should_receive(:output_to_log).with(@log.config.application, 'default message')
|
72
|
+
@log.puts 'default message'
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
69
76
|
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
77
|
it 'clears all logs' do
|
80
78
|
@log.should_receive(:clear_log_contents).with(@log.config.debug)
|
81
79
|
@log.should_receive(:clear_log_contents).with(@log.config.error)
|
82
80
|
@log.should_receive(:clear_log_contents).with(@log.config.notice)
|
83
81
|
@log.should_receive(:clear_log_contents).with(@log.config.warning)
|
84
|
-
@log.should_receive(:clear_log_contents).with(@log.config.
|
82
|
+
@log.should_receive(:clear_log_contents).with(@log.config.application)
|
85
83
|
@log.clear :all
|
86
84
|
end
|
87
85
|
|
@@ -105,9 +103,14 @@ describe FLogger::Log do
|
|
105
103
|
@log.clear :warning
|
106
104
|
end
|
107
105
|
|
108
|
-
it 'clears the
|
109
|
-
@log.should_receive(:clear_log_contents).with(@log.config.
|
110
|
-
@log.clear :
|
106
|
+
it 'clears the application log' do
|
107
|
+
@log.should_receive(:clear_log_contents).with(@log.config.application)
|
108
|
+
@log.clear :application
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'clears the default log with no parameter' do
|
112
|
+
@log.should_receive(:clear_log_contents).with(@log.config.application)
|
113
|
+
@log.clear
|
111
114
|
end
|
112
115
|
end
|
113
116
|
end
|
metadata
CHANGED
@@ -1,98 +1,72 @@
|
|
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
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 1
|
10
|
-
version: 0.2.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Andre Burdette
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-09-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: rspec
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &11152440 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 23
|
29
|
-
segments:
|
30
|
-
- 2
|
31
|
-
- 6
|
32
|
-
- 0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 2.6.0
|
34
22
|
type: :development
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *11152440
|
36
25
|
description: Simple Ruby-based logger that can output to one or several log files.
|
37
|
-
email:
|
26
|
+
email:
|
38
27
|
- andre@nerdstack.com
|
39
28
|
executables: []
|
40
|
-
|
41
29
|
extensions: []
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
files:
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.rdoc
|
32
|
+
- CHANGELOG.rdoc
|
33
|
+
files:
|
46
34
|
- .gitignore
|
47
35
|
- CHANGELOG.rdoc
|
48
36
|
- Gemfile
|
49
37
|
- README.rdoc
|
50
38
|
- Rakefile
|
51
39
|
- examples/clear_logs.rb
|
52
|
-
- examples/custom_format.rb
|
53
40
|
- examples/custom_output.rb
|
54
41
|
- examples/default_output.rb
|
55
42
|
- flogger.gemspec
|
56
43
|
- lib/flogger.rb
|
57
|
-
- lib/flogger/ext/file.rb
|
58
44
|
- lib/flogger/log.rb
|
59
45
|
- lib/flogger/version.rb
|
60
46
|
- specs/log_spec.rb
|
61
47
|
- specs/spec_helper.rb
|
62
48
|
homepage: https://github.com/aburdette/flogger
|
63
49
|
licenses: []
|
64
|
-
|
65
50
|
post_install_message:
|
66
51
|
rdoc_options: []
|
67
|
-
|
68
|
-
require_paths:
|
52
|
+
require_paths:
|
69
53
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
55
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 55
|
76
|
-
segments:
|
77
|
-
- 1
|
78
|
-
- 9
|
79
|
-
- 2
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
80
59
|
version: 1.9.2
|
81
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
61
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
|
87
|
-
segments:
|
88
|
-
- 0
|
89
|
-
version: "0"
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
90
66
|
requirements: []
|
91
|
-
|
92
67
|
rubyforge_project: flogger
|
93
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.6
|
94
69
|
signing_key:
|
95
70
|
specification_version: 3
|
96
71
|
summary: Simple Ruby-based logger with file output.
|
97
72
|
test_files: []
|
98
|
-
|
data/examples/custom_format.rb
DELETED
@@ -1,22 +0,0 @@
|
|
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/lib/flogger/ext/file.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
class File
|
4
|
-
# create a file if it doesn't already exist
|
5
|
-
def self.open_or_create(file, access)
|
6
|
-
begin
|
7
|
-
path = File.dirname(file)
|
8
|
-
FileUtils.mkdir_p(path) unless File.exists?(file)
|
9
|
-
File.open(file, access)
|
10
|
-
rescue Exception => e
|
11
|
-
$stderr.puts e.message
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|