logging 1.8.0 → 1.8.1

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,9 @@
1
+ == 1.8.1 / 2013-01-02
2
+
3
+ Bug Fixes
4
+ - Diagnostic context thread inheritance [issue #56]
5
+ - Fixing trace reporting in JRuby 1.7
6
+
1
7
  == 1.8.0 / 2012-09-13
2
8
 
3
9
  Enhancements
@@ -79,10 +79,12 @@ There are many more examples in the "examples" folder of the logging
79
79
  package. The recommended reading order is the following:
80
80
 
81
81
  * {simple.rb}[https://github.com/TwP/logging/blob/master/examples/simple.rb]
82
+ * {rspec_integration.rb}[https://github.com/TwP/logging/blob/master/examples/rspec_integration.rb]
82
83
  * {loggers.rb}[https://github.com/TwP/logging/blob/master/examples/loggers.rb]
83
84
  * {classes.rb}[https://github.com/TwP/logging/blob/master/examples/classes.rb]
84
85
  * {hierarchies.rb}[https://github.com/TwP/logging/blob/master/examples/hierarchies.rb]
85
86
  * {names.rb}[https://github.com/TwP/logging/blob/master/examples/names.rb]
87
+ * {lazy.rb}[https://github.com/TwP/logging/blob/master/examples/lazy.rb]
86
88
  * {appenders.rb}[https://github.com/TwP/logging/blob/master/examples/appenders.rb]
87
89
  * {layouts.rb}[https://github.com/TwP/logging/blob/master/examples/layouts.rb]
88
90
  * {formatting.rb}[https://github.com/TwP/logging/blob/master/examples/formatting.rb]
@@ -0,0 +1,53 @@
1
+ # :stopdoc:
2
+ #
3
+ # It's useful to define custom log levels that denote success, or otherwise
4
+ # meaningful events that happen to not be negative (more than 50% of the
5
+ # levels are given to warn, error, fail - quite a pessimistic view of one's
6
+ # application's chances of success, no? ;-) )
7
+ #
8
+ # Here, we define two new levels, 'happy' and 'success' and make them soothing
9
+ # colours.
10
+ #
11
+
12
+ require 'logging'
13
+
14
+ # https://github.com/TwP/logging/blob/master/lib/logging.rb#L250-285
15
+ # The levels run from lowest level to highest level.
16
+
17
+ Logging.init :debug, :info, :happy, :warn, :success, :error, :fatal
18
+
19
+ Logging.color_scheme( 'soothing_ish',
20
+ :levels => {
21
+ :info => :cyan,
22
+ :happy => :green,
23
+ :warn => :yellow,
24
+ :success => [:blue],
25
+ :error => :red,
26
+ :fatal => [:white, :on_red]
27
+ },
28
+ :date => :cyan,
29
+ :logger => :cyan,
30
+ :message => :orange
31
+ )
32
+
33
+ Logging.appenders.stdout(
34
+ 'stdout',
35
+ :layout => Logging.layouts.pattern(
36
+ :pattern => '[%d] %-7l %c: %m\n',
37
+ :color_scheme => 'soothing_ish'
38
+ )
39
+ )
40
+
41
+ log = Logging.logger['Soothing::Colors']
42
+ log.add_appenders 'stdout'
43
+ log.level = :debug
44
+
45
+ log.debug 'a very nice little debug message'
46
+ log.info 'things are operating nominally'
47
+ log.happy 'What a beautiful day'
48
+ log.warn 'this is your last warning'
49
+ log.success 'I am INWEENCIBLE!!'
50
+ log.error StandardError.new('something went horribly wrong')
51
+ log.fatal 'I Die!'
52
+
53
+ # :startdoc:
@@ -0,0 +1,45 @@
1
+ # :stopdoc:
2
+ #
3
+ # It happens sometimes that it is very expensive to construct a logging
4
+ # message; for example, if a large object structure has to be traversed
5
+ # during executing of an `object.to_s` method. It would be convenient to
6
+ # delay creation of the message until the log event actually takes place.
7
+ #
8
+ # For example, with a logger configured only to show WARN messages and higher,
9
+ # creating the log message for an INFO message would be wasteful. The INFO log
10
+ # event would never be generated in this case.
11
+ #
12
+ # Log message creation can be performed lazily by wrapping the expensive
13
+ # message generation code in a block and passing that to the logging method.
14
+
15
+ require 'logging'
16
+
17
+ Logging.logger.root.appenders = Logging.appenders.stdout
18
+ Logging.logger.root.level = :info
19
+
20
+ # We use this dummy method in order to see if the method gets called, but in practice,
21
+ # this method might do complicated string operations to construct a log message.
22
+ def expensive_method
23
+ puts "Called!"
24
+ "Expensive message"
25
+ end
26
+
27
+ log = Logging.logger['Lazy']
28
+
29
+ # If you log this message the usual way, expensive_method gets called before
30
+ # debug, hence the Logging framework has no chance to stop it from being executed
31
+ # immediately.
32
+ log.info("Normal")
33
+ log.debug(expensive_method)
34
+
35
+ # If we put the message into a block, then the block is not executed, if
36
+ # the message is not needed with the current log level.
37
+ log.info("Block unused")
38
+ log.debug { expensive_method }
39
+
40
+ # If the log message is needed with the current log level, then the block is of
41
+ # course executed and the log message appears as expected.
42
+ log.info("Block used")
43
+ log.warn { expensive_method }
44
+
45
+ # :startdoc:
@@ -0,0 +1,38 @@
1
+ # :stopdoc:
2
+ #
3
+ # One useful feature of log messages in your code is that they provide a
4
+ # convenient instrumentation point for testing. Through log messages you can
5
+ # confirm that internal methods were called or that certain code paths were
6
+ # executed. This example demonstrates how to capture log output during testing
7
+ # for later analysis.
8
+ #
9
+ # The Logging framework provides an RSpec helper that will direct log output
10
+ # to a StringIO appender. Log lines can be read from this IO destination
11
+ # during tests.
12
+ #
13
+
14
+ require 'rspec'
15
+ require 'logging'
16
+ require 'rspec/logging_helper'
17
+
18
+ # Configure RSpec to capture log messages for each test. The output from the
19
+ # logs will be stored in the @log_output variable. It is a StringIO instance.
20
+ RSpec.configure do |config|
21
+ include RSpec::LoggingHelper
22
+ config.capture_log_messages
23
+ end
24
+
25
+ # Now within your specs you can check that various log events were generated.
26
+ describe 'SuperLogger' do
27
+ it 'should be able to read a log message' do
28
+ logger = Logging.logger['SuperLogger']
29
+
30
+ logger.debug 'foo bar'
31
+ logger.warn 'just a little warning'
32
+
33
+ @log_output.readline.should be == 'DEBUG SuperLogger: foo bar'
34
+ @log_output.readline.should be == 'WARN SuperLogger: just a little warning'
35
+ end
36
+ end
37
+
38
+ # :startdoc:
@@ -307,17 +307,17 @@ class Thread
307
307
  # then they cannot be garbage collected until the child thread exits.
308
308
  #
309
309
  def create_with_logging_context( m, *a, &b )
310
- p_mdc, p_ndc = nil
310
+ mdc, ndc = nil
311
311
 
312
312
  if Thread.current[Logging::MappedDiagnosticContext::NAME]
313
- p_mdc = Thread.current[Logging::MappedDiagnosticContext::NAME].dup
313
+ mdc = Thread.current[Logging::MappedDiagnosticContext::NAME].dup
314
314
  end
315
315
 
316
316
  if Thread.current[Logging::NestedDiagnosticContext::NAME]
317
- p_ndc = Thread.current[Logging::NestedDiagnosticContext::NAME].dup
317
+ ndc = Thread.current[Logging::NestedDiagnosticContext::NAME].dup
318
318
  end
319
319
 
320
- self.send(m, p_mdc, p_ndc, *a) { |mdc, ndc, *args|
320
+ self.send(m, *a) { |*args|
321
321
  Logging::MappedDiagnosticContext.inherit(mdc)
322
322
  Logging::NestedDiagnosticContext.inherit(ndc)
323
323
  b.call(*args)
@@ -13,7 +13,7 @@ module Logging
13
13
  # * $3 == method name (might be nil)
14
14
  CALLER_RGXP = %r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
15
15
  #CALLER_INDEX = 2
16
- CALLER_INDEX = ((defined? JRUBY_VERSION and JRUBY_VERSION[%r/^1.6/]) or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2
16
+ CALLER_INDEX = ((defined? JRUBY_VERSION and JRUBY_VERSION > '1.6') or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 1 : 2
17
17
  # :startdoc:
18
18
 
19
19
  # call-seq:
@@ -98,7 +98,7 @@ module TestLayouts
98
98
  assert_match %r/\A--- ?\nthread_id: -?\d+\n\z/, @layout.format(event)
99
99
 
100
100
  @layout.items = %w[thread]
101
- assert_match %r/\A--- ?\nthread: \n/, @layout.format(event)
101
+ assert_match %r/\A--- ?\nthread: ?\n/, @layout.format(event)
102
102
  Thread.current[:name] = "Main"
103
103
  assert_match %r/\A--- ?\nthread: Main\n/, @layout.format(event)
104
104
 
@@ -1 +1 @@
1
- 1.8.0
1
+ 1.8.1
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: 1.8.0
4
+ version: 1.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: little-plugger
@@ -120,13 +120,16 @@ files:
120
120
  - examples/classes.rb
121
121
  - examples/colorization.rb
122
122
  - examples/consolidation.rb
123
+ - examples/custom_log_levels.rb
123
124
  - examples/fork.rb
124
125
  - examples/formatting.rb
125
126
  - examples/hierarchies.rb
126
127
  - examples/layouts.rb
128
+ - examples/lazy.rb
127
129
  - examples/loggers.rb
128
130
  - examples/mdc.rb
129
131
  - examples/names.rb
132
+ - examples/rspec_integration.rb
130
133
  - examples/simple.rb
131
134
  - lib/logging.rb
132
135
  - lib/logging/appender.rb