logging 0.9.3 → 0.9.4

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.
@@ -1,3 +1,15 @@
1
+ == 0.9.4 / 2008-10-04
2
+
3
+ 2 minor enhancements
4
+ - Flag to suppress exception backtraces from being logged
5
+ - Cleaning up color codes on Growl output
6
+ 4 bug fixes
7
+ - Child loggers were not being found in some cases
8
+ - RollingFileAppender fails to reopen the log file if
9
+ the log file is deleted.
10
+ - Fixed a copy/paste error in the YAML configurator
11
+ - Bug in the configurator where a nil object was being used
12
+
1
13
  == 0.9.3 / 2008-09-12
2
14
 
3
15
  2 minor enhancement
@@ -1,6 +1,6 @@
1
1
  History.txt
2
2
  Manifest.txt
3
- README.txt
3
+ README.rdoc
4
4
  Rakefile
5
5
  data/bad_logging_1.rb
6
6
  data/bad_logging_2.rb
File without changes
data/Rakefile CHANGED
@@ -12,14 +12,17 @@ PROJ.authors = 'Tim Pease'
12
12
  PROJ.email = 'tim.pease@gmail.com'
13
13
  PROJ.url = 'http://logging.rubyforge.org/'
14
14
  PROJ.rubyforge.name = 'logging'
15
- PROJ.rdoc.dir = 'doc/rdoc'
16
- #PROJ.rdoc.remote_dir = 'rdoc'
17
- PROJ.rdoc.remote_dir = ''
18
15
  PROJ.version = Logging::VERSION
19
- PROJ.release_name = %q{Log-O-Stat}
16
+ PROJ.readme_file = 'README.rdoc'
20
17
 
21
18
  PROJ.exclude << %w[^tags$ ^tasks/archive ^coverage]
22
19
  PROJ.rdoc.exclude << '^data'
20
+ PROJ.rdoc.include << PROJ.readme_file
21
+ PROJ.rdoc.main = PROJ.readme_file
22
+ #PROJ.rdoc.dir = 'doc/rdoc'
23
+ #PROJ.rdoc.remote_dir = 'rdoc'
24
+ PROJ.rdoc.dir = 'doc'
25
+ PROJ.rdoc.remote_dir = ''
23
26
 
24
27
  PROJ.ann.email[:server] = 'smtp.gmail.com'
25
28
  PROJ.ann.email[:port] = 587
@@ -13,7 +13,7 @@ begin require 'fastthread'; rescue LoadError; end
13
13
  module Logging
14
14
 
15
15
  # :stopdoc:
16
- VERSION = '0.9.3'
16
+ VERSION = '0.9.4'
17
17
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
18
18
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
19
19
  WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM
@@ -227,6 +227,31 @@ module Logging
227
227
  module_eval "OBJ_FORMAT = :#{f}", __FILE__, __LINE__
228
228
  end
229
229
 
230
+ # call-seq:
231
+ # Logging.backtrace #=> true or false
232
+ # Logging.backtrace( value ) #=> true or false
233
+ #
234
+ # Without any arguments, returns the global exception backtrace logging
235
+ # value. When set to +true+ backtraces will be written to the logs; when
236
+ # set to +false+ backtraces will be suppressed.
237
+ #
238
+ # When an argument is given the global exception backtrace setting will
239
+ # be changed. Value values are <tt>"on"</tt>, <tt>:on<tt> and +true+ to
240
+ # turn on backtraces and <tt>"off"</tt>, <tt>:off</tt> and +false+ to
241
+ # turn off backtraces.
242
+ #
243
+ def backtrace( b = nil )
244
+ @backtrace = true unless defined? @backtrace
245
+ return @backtrace if b.nil?
246
+
247
+ @backtrace = case b
248
+ when :on, 'on', true; true
249
+ when :off, 'off', false; false
250
+ else
251
+ raise ArgumentError, "backtrace must be true or false"
252
+ end
253
+ end
254
+
230
255
  # Returns the version string for the library.
231
256
  #
232
257
  def version
@@ -331,6 +356,8 @@ module Logging
331
356
  children.sort {|a,b| a.name <=> b.name}.each do |child|
332
357
  ::Logging.show_configuration(io, child, indent)
333
358
  end
359
+
360
+ nil
334
361
  end
335
362
 
336
363
  # :stopdoc:
@@ -9,6 +9,10 @@ module Logging::Appenders
9
9
  #
10
10
  class Growl < ::Logging::Appender
11
11
 
12
+ # :stopdoc:
13
+ ColoredRegexp = %r/\e\[([34][0-7]|[0-9])m/
14
+ # :startdoc:
15
+
12
16
  # call-seq:
13
17
  # Growl.new( name, opts = {} )
14
18
  #
@@ -84,13 +88,13 @@ module Logging::Appenders
84
88
  end
85
89
  return if message.empty?
86
90
 
91
+ message = message.gsub(ColoredRegexp, '')
87
92
  if @title_sep
88
93
  title, message = message.split(@title_sep)
89
94
  title, message = '', title if message.nil?
90
- title.strip!
91
95
  end
92
96
 
93
- growl(title, message, priority)
97
+ growl(title.strip, message.strip, priority)
94
98
  self
95
99
  end
96
100
 
@@ -270,11 +270,13 @@ module Logging::Appenders
270
270
  def check_logfile
271
271
  retry_cnt ||= 0
272
272
 
273
- @stat = ::File.stat(@fn)
274
- return unless @lockfile
275
- return if @inode == @stat.ino
273
+ if ::File.exist?(@fn) then
274
+ @stat = ::File.stat(@fn)
275
+ return unless @lockfile
276
+ return if @inode == @stat.ino
276
277
 
277
- @io.close rescue nil
278
+ @io.close rescue nil
279
+ end
278
280
  open_logfile
279
281
  rescue SystemCallError
280
282
  raise if retry_cnt > 3
@@ -29,6 +29,7 @@ module Logging::Config
29
29
  dsl.__instance_eval(&block)
30
30
 
31
31
  pre_config dsl.__pre_config
32
+ ::Logging::Logger[:root] # ensures the log levels are defined
32
33
  appenders dsl.__appenders
33
34
  loggers dsl.__loggers
34
35
  end
@@ -52,6 +53,10 @@ module Logging::Config
52
53
  # format as
53
54
  format = config[:format_as]
54
55
  ::Logging.format_as(format) unless format.nil?
56
+
57
+ # backtrace
58
+ value = config[:backtrace]
59
+ ::Logging.backtrace(value) unless value.nil?
55
60
  end
56
61
 
57
62
  # call-seq:
@@ -157,17 +162,20 @@ module Logging::Config
157
162
  class TopLevelDSL < DSL
158
163
  undef_method :method_missing
159
164
 
165
+ def initialize
166
+ @loggers = []
167
+ @appenders = []
168
+ end
169
+
160
170
  def pre_config( &block )
161
171
  __store(:preconfig, DSL.process(&block))
162
172
  end
163
173
 
164
174
  def logger( name, &block )
165
- @loggers ||= []
166
175
  @loggers << [name, DSL.process(&block)]
167
176
  end
168
177
 
169
178
  def appender( name, &block )
170
- @appenders ||= []
171
179
  @appenders << [name, DSL.process(&block)]
172
180
  end
173
181
 
@@ -71,6 +71,7 @@ module Config
71
71
  #
72
72
  def load
73
73
  pre_config @config['pre_config']
74
+ ::Logging::Logger[:root] # ensures the log levels are defined
74
75
  appenders @config['appenders']
75
76
  loggers @config['loggers']
76
77
  end
@@ -94,6 +95,10 @@ module Config
94
95
  format = config['format_as']
95
96
  ::Logging.format_as(format) unless format.nil?
96
97
 
98
+ # backtrace
99
+ value = config['backtrace']
100
+ ::Logging.backtrace(value) unless value.nil?
101
+
97
102
  # grab the root logger and set the logging level
98
103
  root = ::Logging::Logger.root
99
104
  if config.has_key?('root')
@@ -156,7 +161,7 @@ module Config
156
161
  raise Error, 'Appender type not given' if type.nil?
157
162
 
158
163
  name = config.delete('name')
159
- raise Error, 'Appender name not given' if type.nil?
164
+ raise Error, 'Appender name not given' if name.nil?
160
165
 
161
166
  config['layout'] = layout(config.delete('layout'))
162
167
 
@@ -39,6 +39,14 @@ class Layout
39
39
  @obj_format = case f
40
40
  when :inspect, :yaml; f
41
41
  else :string end
42
+
43
+ b = opts.getopt(:backtrace, ::Logging.backtrace)
44
+ @backtrace = case b
45
+ when :on, 'on', true; true
46
+ when :off, 'off', false; false
47
+ else
48
+ raise ArgumentError, "backtrace must be true or false"
49
+ end
42
50
  end
43
51
 
44
52
  # call-seq:
@@ -79,7 +87,7 @@ class Layout
79
87
  when String; obj
80
88
  when Exception
81
89
  str = "<#{obj.class.name}> #{obj.message}"
82
- unless obj.backtrace.nil?
90
+ if @backtrace && !obj.backtrace.nil?
83
91
  str << "\n\t" << obj.backtrace.join("\n\t")
84
92
  end
85
93
  str
@@ -53,6 +53,7 @@ module Logging
53
53
  if logger.nil?
54
54
  logger = super(name, *args)
55
55
  repo[name] = logger
56
+ repo.children(name).each {|c| c.__send__(:parent=, logger)}
56
57
  end
57
58
  logger
58
59
  end
@@ -142,7 +143,6 @@ module Logging
142
143
 
143
144
  repo = ::Logging::Repository.instance
144
145
  _setup(name, :parent => repo.parent(name))
145
- repo.children(name).each {|c| c.parent = self}
146
146
  end
147
147
 
148
148
  # call-seq:
@@ -107,17 +107,9 @@ module Logging
107
107
  # of B is A. Parents are determined by namespace.
108
108
  #
109
109
  def parent( key )
110
- return if 'root' == key.to_s
111
-
112
- key = to_key(key)
113
- a = key.split PATH_DELIMITER
114
-
115
- p = @h[:root]
116
- while a.slice!(-1) and !a.empty?
117
- k = a.join PATH_DELIMITER
118
- if @h.has_key? k then p = @h[k]; break end
119
- end
120
- p
110
+ name = _parent_name(to_key(key))
111
+ return if name.nil?
112
+ @h[name]
121
113
  end
122
114
 
123
115
  # call-seq:
@@ -128,31 +120,15 @@ module Logging
128
120
  # +Repository#[]+. Children are returned regardless of the
129
121
  # existence of the logger referenced by _key_.
130
122
  #
131
- def children( key )
132
- # need to handle the root logger as a special case
133
- if 'root' == key.to_s
134
- ary = []
135
- @h.each_pair do |key,logger|
136
- key = key.to_s
137
- next if key == 'root'
138
- next if key.index(PATH_DELIMITER)
139
- ary << logger
140
- end
141
- return ary.sort
142
- end
123
+ def children( parent )
124
+ ary = []
125
+ parent = to_key(parent)
143
126
 
144
- key = to_key(key)
145
- depth = key.split(PATH_DELIMITER).length
146
- rgxp = Regexp.new "^#{key}#{PATH_DELIMITER}"
147
-
148
- a = @h.keys.map do |k|
149
- if k =~ rgxp
150
- l = @h[k]
151
- d = l.parent.name.split(PATH_DELIMITER).length
152
- if d <= depth then l else nil end
153
- end
154
- end
155
- a.compact.sort
127
+ @h.each_pair do |child,logger|
128
+ next if :root == child
129
+ ary << logger if parent == _parent_name(child)
130
+ end
131
+ return ary.sort
156
132
  end
157
133
 
158
134
  # call-seq:
@@ -175,6 +151,21 @@ module Logging
175
151
  end
176
152
  end
177
153
 
154
+ # Returns the name of the parent for the logger identified by the given
155
+ # _key_. If the _key_ is for the root logger, then +nil+ is returned.
156
+ #
157
+ def _parent_name( key )
158
+ return if :root == key
159
+
160
+ a = key.split PATH_DELIMITER
161
+ p = :root
162
+ while a.slice!(-1) and !a.empty?
163
+ k = a.join PATH_DELIMITER
164
+ if @h.has_key? k then p = k; break end
165
+ end
166
+ p
167
+ end
168
+
178
169
  end # class Repository
179
170
  end # module Logging
180
171
 
@@ -171,6 +171,27 @@ module TestAppenders
171
171
  cleanup
172
172
  end
173
173
 
174
+ def test_file_removed
175
+ assert_equal [], Dir.glob(@glob)
176
+
177
+ ap = ::Logging::Appenders::RollingFile.new(NAME,
178
+ :filename => @fn, :size => 100)
179
+
180
+ ap << 'X' * 100; ap.flush
181
+ assert_equal 1, Dir.glob(@glob).length
182
+ assert_equal 100, File.size(@fn)
183
+
184
+ # Now remove @fn and make sure that the log file is written to
185
+ # again
186
+ File.unlink(@fn)
187
+ assert_equal 0, Dir.glob(@glob).length
188
+
189
+ ap << 'X' * 50; ap.flush
190
+ assert_equal 1, Dir.glob(@glob).length
191
+ assert_equal 50, File.size(@fn)
192
+
193
+ end
194
+
174
195
  private
175
196
  def cleanup
176
197
  unless ::Logging::Appender[NAME].nil?
@@ -53,6 +53,8 @@ module LoggingTestCase
53
53
 
54
54
  def teardown
55
55
  super
56
+ ::Logging.backtrace
57
+ ::Logging.__send__(:remove_instance_variable, :@backtrace)
56
58
  h = ::Logging::Appender.instance_variable_get(:@appenders)
57
59
  h.each_value {|a| a.close(false) unless a.nil? || a.closed?}
58
60
  h.clear
@@ -78,6 +78,29 @@ module TestLogging
78
78
  assert_equal "<Array> \n--- \n- one\n- two\n- three\n- four\n", r
79
79
  end
80
80
 
81
+ def test_format_obj_without_backtrace
82
+ @layout = ::Logging::Layout.new :backtrace => 'off'
83
+
84
+ obj = Exception.new 'some exception'
85
+ obj.set_backtrace %w( this is the backtrace )
86
+ r = @layout.send :format_obj, obj
87
+ obj = "<Exception> some exception"
88
+ assert_equal obj, r
89
+
90
+ ::Logging.backtrace :off
91
+ @layout = ::Logging::Layout.new
92
+
93
+ obj = ArgumentError.new 'wrong type of argument'
94
+ obj.set_backtrace %w( this is the backtrace )
95
+ r = @layout.send :format_obj, obj
96
+ obj = "<ArgumentError> wrong type of argument"
97
+ assert_equal obj, r
98
+ end
99
+
100
+ def test_initializer
101
+ assert_raise(ArgumentError) {::Logging::Layout.new :backtrace => 'foo'}
102
+ end
103
+
81
104
  end # class TestLayout
82
105
  end # module TestLogging
83
106
 
@@ -15,6 +15,30 @@ module TestLogging
15
15
  @glob = File.join(TMP, '*.log')
16
16
  end
17
17
 
18
+ def test_backtrace
19
+ assert_equal true, ::Logging.backtrace
20
+
21
+ assert_equal false, ::Logging.backtrace('off')
22
+ assert_equal false, ::Logging.backtrace
23
+
24
+ assert_equal true, ::Logging.backtrace('on')
25
+ assert_equal true, ::Logging.backtrace
26
+
27
+ assert_equal false, ::Logging.backtrace(:off)
28
+ assert_equal false, ::Logging.backtrace
29
+
30
+ assert_equal true, ::Logging.backtrace(:on)
31
+ assert_equal true, ::Logging.backtrace
32
+
33
+ assert_equal false, ::Logging.backtrace(false)
34
+ assert_equal false, ::Logging.backtrace
35
+
36
+ assert_equal true, ::Logging.backtrace(true)
37
+ assert_equal true, ::Logging.backtrace
38
+
39
+ assert_raise(ArgumentError) {::Logging.backtrace 'foo'}
40
+ end
41
+
18
42
  def test_configure
19
43
  assert_raise(ArgumentError) {::Logging.configure 'blah.txt'}
20
44
 
@@ -92,7 +92,7 @@ module TestLogging
92
92
 
93
93
  assert_equal [@repo['A::B']], @repo.children('A')
94
94
  assert_equal a, @repo.children('A::B')
95
- assert_equal a, @repo.children('A::B::C')
95
+ assert_equal [], @repo.children('A::B::C')
96
96
 
97
97
  ::Logging::Logger.new('A::B::C')
98
98
 
@@ -220,7 +220,7 @@ module TestStats
220
220
 
221
221
  sampler = @stats['foo']
222
222
  assert_equal 1, sampler.num
223
- assert_in_delta 0.05, sampler.sum, 1e-3
223
+ assert_in_delta 0.05, sampler.sum, 1e-2
224
224
 
225
225
  @tracker.time('foo') {sleep 0.05}
226
226
  assert_equal 2, sampler.num
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-13 00:00:00 -06:00
12
+ date: 2008-10-07 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,11 +40,11 @@ extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
42
  - History.txt
43
- - README.txt
43
+ - README.rdoc
44
44
  files:
45
45
  - History.txt
46
46
  - Manifest.txt
47
- - README.txt
47
+ - README.rdoc
48
48
  - Rakefile
49
49
  - data/bad_logging_1.rb
50
50
  - data/bad_logging_2.rb
@@ -109,7 +109,7 @@ homepage: http://logging.rubyforge.org/
109
109
  post_install_message:
110
110
  rdoc_options:
111
111
  - --main
112
- - README.txt
112
+ - README.rdoc
113
113
  require_paths:
114
114
  - lib
115
115
  required_ruby_version: !ruby/object:Gem::Requirement