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 CHANGED
@@ -1,11 +1,7 @@
1
1
  *~
2
- .DS_Store
3
- Thumbs.db
4
-
5
2
  *.gem
3
+ .rvmrc
6
4
  .bundle
7
5
  Gemfile.lock
8
-
9
- db/*
10
6
  pkg/*
11
7
  logs/*
@@ -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
@@ -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.default = 'new/path/to/default.log'
21
+ c.warning = 'new/path/to/warning.log'
22
22
  end
23
23
 
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):
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
- <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>
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>
@@ -18,9 +18,8 @@ class LogFiller
18
18
  # clear specific logs
19
19
  @log.clear :debug
20
20
  @log.clear :error
21
- @log.clear :default
22
21
 
23
- # or clear all logs
22
+ # clear default log
24
23
  @log.clear
25
24
  end
26
25
  end
@@ -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.default = 'custom/log/path/application.log'
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 an application message."
21
+ @log.puts "#{count} - This is logged as a warning message."
18
22
  end
19
23
  end
20
24
  end
@@ -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 = '~> 1.9.2'
22
- s.add_development_dependency 'rspec', '~> 2.6.0'
23
+ s.required_ruby_version = '>= 1.9.2'
24
+ s.add_development_dependency 'rspec', '>= 2.6.0'
23
25
  end
@@ -2,7 +2,6 @@ require 'flogger/log'
2
2
 
3
3
  module FLogger
4
4
  autoload :VERSION, 'flogger/version'
5
- autoload :File, 'flogger/ext/file'
6
5
 
7
6
  # output a deprecation error message
8
7
  def self.output_deprecation(version, method)
@@ -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
- :default => 'logs/application.txt',
15
+ :application => 'logs/application.txt',
15
16
 
16
- # default format for log output
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 = :default, message)
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 :default
73
- output_to_log(@config.default, message)
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 = :all)
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.default
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 :default
102
- clear_log_contents @config.default
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
- log_file = File.open_or_create(file, 'a')
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
@@ -1,3 +1,3 @@
1
1
  module FLogger
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -1,5 +1,4 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
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.default.should eql 'logs/application.txt'
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.default = 'custom default log'
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.default.should eql 'custom default log'
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.default, 'application message')
65
- @log.puts 'application message'
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.default)
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 default log' do
109
- @log.should_receive(:clear_log_contents).with(@log.config.default)
110
- @log.clear :default
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
- hash: 21
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
- date: 2011-09-03 00:00:00 Z
19
- dependencies:
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
- prerelease: false
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
- version_requirements: *id001
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
- extra_rdoc_files: []
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
- hash: 3
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.10
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
-
@@ -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
@@ -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