logging 1.8.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/History.txt +20 -0
  4. data/README.md +159 -0
  5. data/Rakefile +9 -5
  6. data/examples/appenders.rb +0 -4
  7. data/examples/layouts.rb +1 -8
  8. data/examples/names.rb +4 -4
  9. data/lib/logging.rb +24 -76
  10. data/lib/logging/appender.rb +71 -16
  11. data/lib/logging/appenders.rb +0 -2
  12. data/lib/logging/appenders/buffering.rb +32 -16
  13. data/lib/logging/appenders/file.rb +2 -2
  14. data/lib/logging/appenders/io.rb +1 -1
  15. data/lib/logging/appenders/rolling_file.rb +228 -165
  16. data/lib/logging/appenders/string_io.rb +1 -1
  17. data/lib/logging/appenders/syslog.rb +4 -4
  18. data/lib/logging/color_scheme.rb +20 -3
  19. data/lib/logging/diagnostic_context.rb +142 -17
  20. data/lib/logging/filter.rb +18 -0
  21. data/lib/logging/filters.rb +4 -0
  22. data/lib/logging/filters/level.rb +29 -0
  23. data/lib/logging/layout.rb +2 -2
  24. data/lib/logging/layouts/parseable.rb +5 -2
  25. data/lib/logging/layouts/pattern.rb +309 -168
  26. data/lib/logging/log_event.rb +5 -5
  27. data/lib/logging/logger.rb +55 -68
  28. data/lib/logging/repository.rb +24 -39
  29. data/lib/logging/root_logger.rb +1 -1
  30. data/lib/logging/utils.rb +4 -65
  31. data/lib/logging/version.rb +8 -0
  32. data/lib/rspec/logging_helper.rb +3 -3
  33. data/logging.gemspec +46 -0
  34. data/test/appenders/test_buffered_io.rb +29 -0
  35. data/test/appenders/test_file.rb +2 -2
  36. data/test/appenders/test_rolling_file.rb +62 -1
  37. data/test/layouts/test_color_pattern.rb +1 -1
  38. data/test/layouts/test_json.rb +3 -0
  39. data/test/layouts/test_pattern.rb +6 -2
  40. data/test/layouts/test_yaml.rb +4 -1
  41. data/test/test_appender.rb +56 -0
  42. data/test/test_filter.rb +33 -0
  43. data/test/test_layout.rb +4 -8
  44. data/test/test_log_event.rb +3 -3
  45. data/test/test_logger.rb +81 -57
  46. data/test/test_logging.rb +0 -59
  47. data/test/test_mapped_diagnostic_context.rb +49 -1
  48. data/test/test_nested_diagnostic_context.rb +16 -1
  49. data/test/test_repository.rb +24 -32
  50. data/test/test_utils.rb +14 -50
  51. metadata +35 -53
  52. data/README.rdoc +0 -143
  53. data/data/bad_logging_1.rb +0 -13
  54. data/data/bad_logging_2.rb +0 -21
  55. data/data/logging.rb +0 -42
  56. data/data/logging.yaml +0 -63
  57. data/data/simple_logging.rb +0 -13
  58. data/examples/consolidation.rb +0 -83
  59. data/lib/logging/appenders/email.rb +0 -178
  60. data/lib/logging/appenders/growl.rb +0 -200
  61. data/lib/logging/config/configurator.rb +0 -187
  62. data/lib/logging/config/yaml_configurator.rb +0 -190
  63. data/lib/logging/stats.rb +0 -277
  64. data/test/appenders/test_email.rb +0 -170
  65. data/test/appenders/test_growl.rb +0 -138
  66. data/test/config/test_configurator.rb +0 -69
  67. data/test/config/test_yaml_configurator.rb +0 -39
  68. data/test/test_consolidate.rb +0 -45
  69. data/test/test_stats.rb +0 -273
  70. data/version.txt +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 522785313b2bc22e301dbc6d52078530fddad1e1
4
- data.tar.gz: 8a9288e2d318ecd89ce38fa06c53326c94d5c9f7
3
+ metadata.gz: 2d4abf77abb948de12d0e860a18be03b9b2314bd
4
+ data.tar.gz: f3bb7dc5daf79b192d56de6d2a96d217bebbe24b
5
5
  SHA512:
6
- metadata.gz: 04615c41d0c1853d45a7d0751f5ee2d3b1b23b98e04b5931e001930f6ee247e2d355d691e3878658cc3a11126c823e058374d383fac3611923b89c05f9819e29
7
- data.tar.gz: 23125228da4ac0c67bfee7a055deec67fa465c4f1ccabbf41614c897cadcc5ad3dc8bb4292f889a9c38c16889038c7acdf79ba0fa1db8a5124234baeea49a2da
6
+ metadata.gz: 31e6820636ea493830b4b880c112aa57a53fc4e283da0682b5dfbdb373d3040017889153e50f625525eb6e0e7e4d7e2752fd6fd60c8acbc909d249762b2fd879
7
+ data.tar.gz: c55a5532bcc8e6c8543f231484a11cb9f65a747afe231f58709fc13274962e6318a05a3e76d09b12c1793bc346cd87eca759e0eefa2185af1ea38d2caf554ab9
@@ -6,8 +6,8 @@ install: "rake gem:install_dependencies"
6
6
  script: "rake"
7
7
 
8
8
  rvm:
9
- - 1.8.7
10
- - 1.9.2
11
9
  - 1.9.3
12
- - jruby
10
+ - 2.0.0
11
+ - 2.1.5
12
+ - 2.2.1
13
13
 
@@ -1,3 +1,23 @@
1
+ == 2.0.0 / 2015-03-28
2
+
3
+ Enhancements
4
+ - added event filtering via the Filter framework
5
+ - improvements to buffered logging
6
+ - code readability improvements around meta-programming
7
+
8
+ Bug Fixes
9
+ - fixed an `already initialized error`
10
+ - avoid unnecessary mutex-ing in logger lookup
11
+
12
+ Deprecations
13
+ - dropped Ruby 1.8 support
14
+ - removed logger consolidation
15
+ - removed YAML style configuration
16
+ - removed the Logging::Stats module
17
+ - removed the Hash#getopt method
18
+ - removed the Growl appender
19
+ - moved the Email appender to the logging-email plugin gem
20
+
1
21
  == 1.8.2 / 2014-01-29
2
22
 
3
23
  Bug Fixes
@@ -0,0 +1,159 @@
1
+ ## Logging
2
+ by Tim Pease [![](https://secure.travis-ci.org/TwP/logging.png)](https://travis-ci.org/TwP/logging)
3
+
4
+ * [Homepage](http://rubygems.org/gems/logging)
5
+ * [Github Project](https://github.com/TwP/logging)
6
+
7
+ ### Description
8
+
9
+ Logging is a flexible logging library for use in Ruby programs based on the
10
+ design of Java's log4j library. It features a hierarchical logging system,
11
+ custom level names, multiple output destinations per log event, custom
12
+ formatting, and more.
13
+
14
+ ### Installation
15
+
16
+ ```
17
+ gem install logging
18
+ ```
19
+
20
+ ### Examples
21
+
22
+ This example configures a logger to output messages in a format similar to the
23
+ core ruby Logger class. Only log messages that are warnings or higher will be
24
+ logged.
25
+
26
+ ```ruby
27
+ require 'logging'
28
+
29
+ logger = Logging.logger(STDOUT)
30
+ logger.level = :warn
31
+
32
+ logger.debug "this debug message will not be output by the logger"
33
+ logger.warn "this is your last warning"
34
+ ```
35
+
36
+ In this example, a single logger is created that will append to STDOUT and to a
37
+ file. Only log messages that are informational or higher will be logged.
38
+
39
+ ```ruby
40
+ require 'logging'
41
+
42
+ logger = Logging.logger['example_logger']
43
+ logger.level = :info
44
+
45
+ logger.add_appenders \
46
+ Logging.appenders.stdout,
47
+ Logging.appenders.file('example.log')
48
+
49
+ logger.debug "this debug message will not be output by the logger"
50
+ logger.info "just some friendly advice"
51
+ ```
52
+
53
+ The Logging library was created to allow each class in a program to have its
54
+ own configurable logger. The logging level for a particular class can be
55
+ changed independently of all other loggers in the system. This example shows
56
+ the recommended way of accomplishing this.
57
+
58
+ ```ruby
59
+ require 'logging'
60
+
61
+ Logging.logger['FirstClass'].level = :warn
62
+ Logging.logger['SecondClass'].level = :debug
63
+
64
+ class FirstClass
65
+ def initialize
66
+ @logger = Logging.logger[self]
67
+ end
68
+
69
+ def some_method
70
+ @logger.debug "some method was called on #{self.inspect}"
71
+ end
72
+ end
73
+
74
+ class SecondClass
75
+ def initialize
76
+ @logger = Logging.logger[self]
77
+ end
78
+
79
+ def another_method
80
+ @logger.debug "another method was called on #{self.inspect}"
81
+ end
82
+ end
83
+ ```
84
+
85
+ There are many more examples in the [examples folder](https://github.com/TwP/logging/tree/master/examples)
86
+ of the logging package. The recommended reading order is the following:
87
+
88
+ * [simple.rb](https://github.com/TwP/logging/blob/master/examples/simple.rb)
89
+ * [rspec_integration.rb](https://github.com/TwP/logging/blob/master/examples/rspec_integration.rb)
90
+ * [loggers.rb](https://github.com/TwP/logging/blob/master/examples/loggers.rb)
91
+ * [classes.rb](https://github.com/TwP/logging/blob/master/examples/classes.rb)
92
+ * [hierarchies.rb](https://github.com/TwP/logging/blob/master/examples/hierarchies.rb)
93
+ * [names.rb](https://github.com/TwP/logging/blob/master/examples/names.rb)
94
+ * [lazy.rb](https://github.com/TwP/logging/blob/master/examples/lazy.rb)
95
+ * [appenders.rb](https://github.com/TwP/logging/blob/master/examples/appenders.rb)
96
+ * [layouts.rb](https://github.com/TwP/logging/blob/master/examples/layouts.rb)
97
+ * [formatting.rb](https://github.com/TwP/logging/blob/master/examples/formatting.rb)
98
+ * [colorization.rb](https://github.com/TwP/logging/blob/master/examples/colorization.rb)
99
+ * [consolidation.rb](https://github.com/TwP/logging/blob/master/examples/consolidation.rb)
100
+ * [fork.rb](https://github.com/TwP/logging/blob/master/examples/fork.rb)
101
+ * [mdc.rb](https://github.com/TwP/logging/blob/master/examples/mdc.rb)
102
+
103
+ ### Extending
104
+
105
+ The Logging framework is extensible via the [little-plugger](https://github.com/twp/little-plugger)
106
+ gem based plugin system. New appenders or formatters can be released as ruby
107
+ gems. When installed locally, the Logging framework will automatically detect
108
+ these gems as plugins and make them available for use.
109
+
110
+ The [logging-email](https://github.com/twp/logging-email) plugin is a good
111
+ example to follow. It includes a [`lib/logging/plugins/email.rb`](https://github.com/twp/logging-email/tree/master/lib/logging/plugins/email.rb)
112
+ file which is detected by the plugin framework. This file declares a
113
+ `Logging::Plugins::Email.initialize_email` method that is called when the plugin
114
+ is loaded.
115
+
116
+ The three steps for creating a plugin are:
117
+
118
+ * create a new Ruby gem: `logging-<name>`
119
+ * include a plugin file: `lib/logging/plugins/<name>.rb`
120
+ * definie a plugin initializer: `Logging::Plugins::<Name>.initialize_<name>`
121
+
122
+ ### Development
123
+
124
+ The Logging source code relies on the Mr Bones project for default rake tasks.
125
+ You will need to install the Mr Bones gem if you want to build or test the
126
+ logging gem. Conveniently there is a bootstrap script that you can run to setup
127
+ your development environment.
128
+
129
+ ```
130
+ script/bootstrap
131
+ ```
132
+
133
+ This will install the Mr Bones gem and the required Ruby gems for development.
134
+ After this is done you can rake `rake -T` to see the available rake tasks.
135
+
136
+ ### License
137
+
138
+ The MIT License
139
+
140
+ Copyright (c) 2015 Tim Pease
141
+
142
+ Permission is hereby granted, free of charge, to any person obtaining
143
+ a copy of this software and associated documentation files (the
144
+ 'Software'), to deal in the Software without restriction, including
145
+ without limitation the rights to use, copy, modify, merge, publish,
146
+ distribute, sublicense, and/or sell copies of the Software, and to
147
+ permit persons to whom the Software is furnished to do so, subject to
148
+ the following conditions:
149
+
150
+ The above copyright notice and this permission notice shall be
151
+ included in all copies or substantial portions of the Software.
152
+
153
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
154
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
155
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
156
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
157
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
158
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
159
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
-
2
1
  begin
3
2
  require 'bones'
4
3
  rescue LoadError
5
4
  abort '### please install the "bones" gem ###'
6
5
  end
7
6
 
7
+ lib = File.expand_path('../lib', __FILE__)
8
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ require 'logging/version'
10
+
8
11
  task :default => 'test:run'
9
12
  task 'gem:release' => 'test:run'
10
13
 
@@ -14,6 +17,7 @@ Bones {
14
17
  authors 'Tim Pease'
15
18
  email 'tim.pease@gmail.com'
16
19
  url 'http://rubygems.org/gems/logging'
20
+ version Logging::VERSION
17
21
 
18
22
  rdoc.exclude << '^data'
19
23
  rdoc.include << '^examples/.*\.rb'
@@ -21,11 +25,11 @@ Bones {
21
25
 
22
26
  use_gmail
23
27
 
24
- depend_on 'little-plugger'
25
- depend_on 'multi_json'
28
+ depend_on 'little-plugger', '~> 1.1'
29
+ depend_on 'multi_json', '~> 1.10'
26
30
 
27
- depend_on 'flexmock', '~> 1.0', :development => true
28
- depend_on 'bones-git', :development => true
31
+ depend_on 'flexmock', '~> 1.0', :development => true
32
+ depend_on 'bones-git', '~> 1.3', :development => true
29
33
  #depend_on 'bones-rcov', :development => true
30
34
  }
31
35
 
@@ -8,9 +8,7 @@
8
8
  # description of each. Please refer to the documentation for specific
9
9
  # configuration options available for each.
10
10
  #
11
- # Email generates e-mail messages
12
11
  # File writes to a regular file
13
- # Growl outputs growl notifications (Mac OS X only)
14
12
  # IO generic IO appender
15
13
  # RollingFile writes to a file and rolls based on size or age
16
14
  # Stdout appends to STDOUT
@@ -20,9 +18,7 @@
20
18
  #
21
19
  # And you can access these appenders:
22
20
  #
23
- # Logging.appenders.email
24
21
  # Logging.appenders.file
25
- # Logging.appenders.growl
26
22
  # Logging.appenders.io
27
23
  # Logging.appenders.rolling_file
28
24
  # Logging.appenders.stdout
@@ -28,15 +28,8 @@
28
28
  :layout => Logging.layouts.json
29
29
  )
30
30
 
31
- # send growl notifications for errors and fatals using a nice pattern
32
- Logging.appenders.growl(
33
- 'growl',
34
- :level => :error,
35
- :layout => Logging.layouts.pattern(:pattern => '[%d] %-5l: %m\n')
36
- )
37
-
38
31
  log = Logging.logger['Foo::Bar']
39
- log.add_appenders 'stdout', 'development.log', 'growl'
32
+ log.add_appenders 'stdout', 'development.log'
40
33
  log.level = :debug
41
34
 
42
35
  log.debug "a very nice little debug message"
@@ -22,15 +22,15 @@
22
22
  require 'logging'
23
23
 
24
24
  Logging.appenders.file('Debug File', :filename => 'debug.log')
25
- Logging.appenders.growl('Growl Notifier', :level => :error)
25
+ Logging.appenders.stderr('Standard Error', :level => :error)
26
26
 
27
27
  # configure the root logger
28
28
  Logging.logger.root.appenders = 'Debug File'
29
29
  Logging.logger.root.level = :debug
30
30
 
31
- # add the growl notifier to the Critical logger (it will use it's own
32
- # appender and the root logger's appender, too)
33
- Logging.logger['Critical'].appenders = 'Growl Notifier'
31
+ # add the Standard Error appender to the Critical logger (it will use it's
32
+ # own appender and the root logger's appender, too)
33
+ Logging.logger['Critical'].appenders = 'Standard Error'
34
34
 
35
35
  # if you'll notice above, assigning appenders using just the name is valid
36
36
  # the logger is smart enough to figure out it was given a string and then
@@ -1,8 +1,3 @@
1
-
2
- # Equivalent to a header guard in C/C++
3
- # Used to prevent the class/module from being loaded more than once
4
- unless defined? Logging
5
-
6
1
  require File.expand_path('../logging/utils', __FILE__)
7
2
 
8
3
  require 'yaml'
@@ -11,7 +6,12 @@ require 'fileutils'
11
6
  require 'little-plugger'
12
7
  require 'multi_json'
13
8
 
14
- HAVE_SYSLOG = require? 'syslog'
9
+ begin
10
+ require 'syslog'
11
+ HAVE_SYSLOG = true
12
+ rescue LoadError
13
+ HAVE_SYSLOG = false
14
+ end
15
15
 
16
16
  #
17
17
  #
@@ -28,28 +28,6 @@ module Logging
28
28
 
29
29
  class << self
30
30
 
31
- # call-seq:
32
- # Logging.configure( filename )
33
- # Logging.configure { block }
34
- #
35
- # Configures the Logging framework using the configuration information
36
- # found in the given file. The file extension should be either '.yaml'
37
- # or '.yml' (XML configuration is not yet supported).
38
- #
39
- def configure( *args, &block )
40
- if block
41
- return ::Logging::Config::Configurator.process(&block)
42
- end
43
-
44
- filename = args.shift
45
- raise ArgumentError, 'a filename was not given' if filename.nil?
46
-
47
- case File.extname(filename)
48
- when '.yaml', '.yml'
49
- ::Logging::Config::YamlConfigurator.load(filename, *args)
50
- else raise ArgumentError, 'unknown configuration file format' end
51
- end
52
-
53
31
  # call-seq:
54
32
  # Logging.logger( device, age = 7, size = 1048576 )
55
33
  # Logging.logger( device, age = 'weekly' )
@@ -185,34 +163,6 @@ module Logging
185
163
  self
186
164
  end
187
165
 
188
- # call-seq:
189
- # Logging.consolidate( 'First::Name', 'Second::Name', ... )
190
- #
191
- # Consolidate all loggers under the given namespace. All child loggers
192
- # in the namespace will use the "consolidated" namespace logger instead
193
- # of creating a new logger for each class or module.
194
- #
195
- # If the "root" logger name is passed to this method then all loggers
196
- # will consolidate to the root logger. In other words, only the root
197
- # logger will be created, and it will be used by all classes and modules
198
- # in the application.
199
- #
200
- # ==== Example
201
- #
202
- # Logging.consolidate( 'Foo' )
203
- #
204
- # foo = Logging.logger['Foo']
205
- # bar = Logging.logger['Foo::Bar']
206
- # baz = Logging.logger['Baz']
207
- #
208
- # foo.object_id == bar.object_id #=> true
209
- # foo.object_id == baz.object_id #=> false
210
- #
211
- def consolidate( *args )
212
- ::Logging::Repository.instance.add_master(*args)
213
- self
214
- end
215
-
216
166
  # call-seq:
217
167
  # include Logging.globally
218
168
  # include Logging.globally( :logger )
@@ -361,12 +311,6 @@ module Logging
361
311
  end
362
312
  end
363
313
 
364
- # Returns the version string for the library.
365
- #
366
- def version
367
- @version ||= File.read(path('version.txt')).strip
368
- end
369
-
370
314
  # Returns the library path for the module. If any arguments are given,
371
315
  # they will be joined to the end of the library path using
372
316
  # <tt>File.join</tt>.
@@ -434,11 +378,11 @@ module Logging
434
378
  # that the logger will *not* pass log events up to the
435
379
  # parent logger
436
380
  #
437
- # 4) trace - a "+T" shows that the logger will include trace
438
- # information in generated log events (this includes
439
- # filename and line number of the log message; "-T"
440
- # shows that the logger does not include trace
441
- # information in the log events)
381
+ # 4) tracing - a "+T" shows that the logger will include caller
382
+ # tracing information in generated log events (this
383
+ # includes filename and line number of the log
384
+ # message); "-T" shows that the logger does not include
385
+ # caller tracing information in the log events
442
386
  #
443
387
  # If a logger has appenders then they are listed, one per line,
444
388
  # immediately below the logger. Appender lines are pre-pended with a
@@ -463,7 +407,7 @@ module Logging
463
407
  def show_configuration( io = STDOUT, logger = 'root', indent = 0 )
464
408
  logger = ::Logging::Logger[logger] unless ::Logging::Logger === logger
465
409
 
466
- logger._dump_configuration(io, indent)
410
+ io << logger._dump_configuration(indent)
467
411
 
468
412
  indent += 2
469
413
  children = ::Logging::Repository.instance.children(logger.name)
@@ -471,7 +415,7 @@ module Logging
471
415
  ::Logging.show_configuration(io, child, indent)
472
416
  end
473
417
 
474
- self
418
+ io
475
419
  end
476
420
 
477
421
  # :stopdoc:
@@ -497,6 +441,14 @@ module Logging
497
441
  ::Logging::Logger[::Logging].__send__(levelify(LNAMES[level]), &block)
498
442
  end
499
443
 
444
+ # Internal logging method for handling exceptions. If the
445
+ # `Thread#abort_on_exception` flag is set then the
446
+ # exception will be raised again.
447
+ def log_internal_error( err )
448
+ log_internal(-2) { err }
449
+ raise err if Thread.abort_on_exception
450
+ end
451
+
500
452
  # Close all appenders
501
453
  def shutdown( *args )
502
454
  return unless initialized?
@@ -526,22 +478,21 @@ module Logging
526
478
  # :startdoc:
527
479
  end
528
480
 
481
+ require libpath('logging/version')
529
482
  require libpath('logging/appender')
530
483
  require libpath('logging/layout')
484
+ require libpath('logging/filter')
531
485
  require libpath('logging/log_event')
532
486
  require libpath('logging/logger')
533
487
  require libpath('logging/repository')
534
488
  require libpath('logging/root_logger')
535
- require libpath('logging/stats')
536
489
  require libpath('logging/color_scheme')
537
490
  require libpath('logging/appenders')
538
491
  require libpath('logging/layouts')
492
+ require libpath('logging/filters')
539
493
  require libpath('logging/proxy')
540
494
  require libpath('logging/diagnostic_context')
541
495
 
542
- require libpath('logging/config/configurator')
543
- require libpath('logging/config/yaml_configurator')
544
-
545
496
  require libpath('logging/rails_compat')
546
497
  end # module Logging
547
498
 
@@ -554,6 +505,3 @@ end # module Logging
554
505
  # application. This is required when daemonizing.
555
506
  #
556
507
  ObjectSpace.define_finalizer self, Logging.method(:shutdown)
557
-
558
- end # unless defined?
559
-