TwP-logging 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,14 @@
1
+ == 1.2.1 / 2009-08-14
2
+
3
+ 1 bug fix
4
+ - Using a bug-fix version of little-plugger
5
+
6
+ == 1.2.0 / 2009-08-14
7
+
8
+ 2 minor enhancements
9
+ - Added a gem based plugin system
10
+ - LogEvent is now a struct (slightly faster)
11
+
1
12
  == 1.1.4 / 2009-05-28
2
13
 
3
14
  1 minor enhancement
data/Rakefile CHANGED
@@ -39,5 +39,6 @@ PROJ.ann.email[:from] = 'Tim Pease'
39
39
 
40
40
  depend_on 'flexmock'
41
41
  depend_on 'lockfile'
42
+ depend_on 'little-plugger'
42
43
 
43
44
  # EOF
@@ -78,14 +78,14 @@ module Logging::Layouts
78
78
  # Arguments to sprintf keyed to directive letters
79
79
  DIRECTIVE_TABLE = {
80
80
  'logger' => 'event.logger',
81
- 'timestamp' => 'Time.now.strftime(Pattern::ISO8601)',
81
+ 'timestamp' => 'event.time.strftime(Pattern::ISO8601)',
82
82
  'level' => '::Logging::LNAMES[event.level]',
83
83
  'message' => 'format_obj(event.data)',
84
84
  'file' => 'event.file',
85
85
  'line' => 'event.line',
86
86
  'method' => 'event.method',
87
87
  'pid' => 'Process.pid',
88
- 'millis' => 'Integer((Time.now-@created_at)*1000)',
88
+ 'millis' => 'Integer((event.time-@created_at)*1000)',
89
89
  'thread_id' => 'Thread.current.object_id',
90
90
  'thread' => 'Thread.current[:name]'
91
91
  }
@@ -124,14 +124,14 @@ module Logging::Layouts
124
124
  # Arguments to sprintf keyed to directive letters
125
125
  DIRECTIVE_TABLE = {
126
126
  'c' => 'event.logger'.freeze,
127
- 'd' => 'format_date'.freeze,
127
+ 'd' => 'format_date(event.time)'.freeze,
128
128
  'F' => 'event.file'.freeze,
129
129
  'l' => '::Logging::LNAMES[event.level]'.freeze,
130
130
  'L' => 'event.line'.freeze,
131
131
  'm' => 'format_obj(event.data)'.freeze,
132
132
  'M' => 'event.method'.freeze,
133
133
  'p' => 'Process.pid'.freeze,
134
- 'r' => 'Integer((Time.now-@created_at)*1000).to_s'.freeze,
134
+ 'r' => 'Integer((event.time-@created_at)*1000).to_s'.freeze,
135
135
  't' => 'Thread.current.object_id.to_s'.freeze,
136
136
  'T' => 'Thread.current[:name]'.freeze,
137
137
  '%' => :placeholder
@@ -158,19 +158,18 @@ module Logging::Layouts
158
158
  #
159
159
  def self.create_date_format_methods( pf )
160
160
  code = "undef :format_date if method_defined? :format_date\n"
161
- code << "def format_date\n"
161
+ code << "def format_date( time )\n"
162
162
  if pf.date_method.nil?
163
163
  if pf.date_pattern =~ %r/%s/
164
164
  code << <<-CODE
165
- now = Time.now
166
- dp = '#{pf.date_pattern}'.gsub('%s','%06d' % now.usec)
167
- now.strftime dp
165
+ dp = '#{pf.date_pattern}'.gsub('%s','%06d' % time.usec)
166
+ time.strftime dp
168
167
  CODE
169
168
  else
170
- code << "Time.now.strftime '#{pf.date_pattern}'\n"
169
+ code << "time.strftime '#{pf.date_pattern}'\n"
171
170
  end
172
171
  else
173
- code << "Time.now.#{pf.date_method}\n"
172
+ code << "time.#{pf.date_method}\n"
174
173
  end
175
174
  code << "end\n"
176
175
  ::Logging.log_internal(0) {code}
@@ -3,8 +3,7 @@ module Logging
3
3
 
4
4
  # This class defines a logging event.
5
5
  #
6
- class LogEvent
7
-
6
+ LogEvent = Struct.new( :logger, :level, :data, :time, :file, :line, :method ) {
8
7
  # :stopdoc:
9
8
 
10
9
  # Regular expression used to parse out caller information
@@ -13,8 +12,8 @@ module Logging
13
12
  # * $2 == line number
14
13
  # * $3 == method name (might be nil)
15
14
  CALLER_RGXP = %r/([\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
16
-
17
- CALLER_INDEX = RUBY_PLATFORM[%r/^java/i] ? 1 : 2
15
+ CALLER_INDEX = 2
16
+ #CALLER_INDEX = RUBY_PLATFORM[%r/^java/i] ? 1 : 2
18
17
  # :startdoc:
19
18
 
20
19
  # call-seq:
@@ -26,26 +25,21 @@ module Logging
26
25
  # invoked to get the execution trace of the logging method.
27
26
  #
28
27
  def initialize( logger, level, data, trace )
29
- @logger = logger
30
- @level = level
31
- @data = data
32
- @file = @line = @method = ''
28
+ f = l = m = ''
33
29
 
34
30
  if trace
35
- t = Kernel.caller[CALLER_INDEX]
36
- return if t.nil?
31
+ stack = Kernel.caller[CALLER_INDEX]
32
+ return if stack.nil?
37
33
 
38
- m = CALLER_RGXP.match(t)
39
- @file = m[1]
40
- @line = Integer(m[2])
41
- @method = m[3] unless m[3].nil?
34
+ match = CALLER_RGXP.match(stack)
35
+ f = match[1]
36
+ l = Integer(match[2])
37
+ m = match[3] unless match[3].nil?
42
38
  end
43
- end
44
39
 
45
- attr_accessor :logger, :level, :data
46
- attr_reader :file, :line, :method
47
-
48
- end # class LogEvent
40
+ super(logger, level, data, Time.now, f, l, m)
41
+ end
42
+ }
49
43
  end # module Logging
50
44
 
51
45
  # EOF
data/lib/logging/utils.rb CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ require 'thread'
3
+
2
4
  # --------------------------------------------------------------------------
3
5
  class Hash
4
6
 
data/lib/logging.rb CHANGED
@@ -9,24 +9,25 @@ require File.expand_path(
9
9
  require 'yaml'
10
10
  require 'stringio'
11
11
  require 'thread'
12
+ require 'little-plugger'
12
13
 
13
14
  HAVE_LOCKFILE = require? 'lockfile'
14
15
  HAVE_SYSLOG = require? 'syslog'
15
16
  require? 'fastthread'
16
17
 
17
18
 
18
- # TODO: Windows Log Service appender
19
-
20
19
  #
21
20
  #
22
21
  module Logging
22
+ extend LittlePlugger
23
23
 
24
24
  # :stopdoc:
25
- VERSION = '1.1.4'
25
+ VERSION = '1.2.1'
26
26
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
27
27
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
28
28
  LEVELS = {}
29
29
  LNAMES = []
30
+ module Plugins; end
30
31
  # :startdoc:
31
32
 
32
33
  class << self
@@ -282,6 +283,8 @@ module Logging
282
283
  longest = 'off' if longest.length < 3
283
284
  module_eval "MAX_LEVEL_LENGTH = #{longest.length}", __FILE__, __LINE__
284
285
 
286
+ initialize_plugins
287
+
285
288
  levels.keys
286
289
  end
287
290
 
@@ -68,9 +68,9 @@ module TestLayouts
68
68
  def test_items_all
69
69
  event = Logging::LogEvent.new('TestLogger', @levels['info'],
70
70
  'log message', false)
71
- event.instance_variable_set :@file, 'test_file.rb'
72
- event.instance_variable_set :@line, 123
73
- event.instance_variable_set :@method, 'method_name'
71
+ event.file = 'test_file.rb'
72
+ event.line = 123
73
+ event.method = 'method_name'
74
74
 
75
75
  @layout.items = %w[logger]
76
76
  assert_equal %Q[{"logger":"TestLogger"}\n], @layout.format(event)
@@ -22,15 +22,15 @@ module TestLayouts
22
22
  def test_date_method_eq
23
23
  @layout.date_method = :to_f
24
24
  assert_equal :to_f, @layout.date_method
25
- assert_instance_of Float, @layout.format_date
25
+ assert_instance_of Float, @layout.format_date(Time.now)
26
26
 
27
27
  @layout.date_method = 'usec'
28
28
  assert_equal 'usec', @layout.date_method
29
- assert_instance_of Fixnum, @layout.format_date
29
+ assert_instance_of Fixnum, @layout.format_date(Time.now)
30
30
 
31
31
  @layout.date_method = :to_s
32
32
  assert_equal :to_s, @layout.date_method
33
- assert_instance_of String, @layout.format_date
33
+ assert_instance_of String, @layout.format_date(Time.now)
34
34
 
35
35
  # now, even if we have defined a date_pattern, the date_method should
36
36
  # supersede the date_pattern
@@ -38,7 +38,7 @@ module TestLayouts
38
38
 
39
39
  @layout.date_method = 'usec'
40
40
  assert_equal 'usec', @layout.date_method
41
- assert_instance_of Fixnum, @layout.format_date
41
+ assert_instance_of Fixnum, @layout.format_date(Time.now)
42
42
  end
43
43
 
44
44
  def test_date_pattern
@@ -48,11 +48,11 @@ module TestLayouts
48
48
  def test_date_pattern_eq
49
49
  @layout.date_pattern = '%Y'
50
50
  assert_equal '%Y', @layout.date_pattern
51
- assert_match %r/\A\d{4}\z/, @layout.format_date
51
+ assert_match %r/\A\d{4}\z/, @layout.format_date(Time.now)
52
52
 
53
53
  @layout.date_pattern = '%H:%M'
54
54
  assert_equal '%H:%M', @layout.date_pattern
55
- assert_match %r/\A\d{2}:\d{2}\z/, @layout.format_date
55
+ assert_match %r/\A\d{2}:\d{2}\z/, @layout.format_date(Time.now)
56
56
  end
57
57
 
58
58
  def test_format
@@ -84,7 +84,7 @@ module TestLayouts
84
84
 
85
85
  def test_format_date
86
86
  rgxp = Regexp.new @date_fmt
87
- assert_match rgxp, @layout.format_date
87
+ assert_match rgxp, @layout.format_date(Time.now)
88
88
  end
89
89
 
90
90
  def test_pattern
@@ -103,9 +103,9 @@ module TestLayouts
103
103
  def test_pattern_all
104
104
  event = Logging::LogEvent.new('TestLogger', @levels['info'],
105
105
  'log message', false)
106
- event.instance_variable_set :@file, 'test_file.rb'
107
- event.instance_variable_set :@line, '123'
108
- event.instance_variable_set :@method, 'method_name'
106
+ event.file = 'test_file.rb'
107
+ event.line = '123'
108
+ event.method = 'method_name'
109
109
 
110
110
  @layout.pattern = '%c'
111
111
  assert_equal 'TestLogger', @layout.format(event)
@@ -66,9 +66,9 @@ module TestLayouts
66
66
  def test_items_all
67
67
  event = Logging::LogEvent.new('TestLogger', @levels['info'],
68
68
  'log message', false)
69
- event.instance_variable_set :@file, 'test_file.rb'
70
- event.instance_variable_set :@line, 123
71
- event.instance_variable_set :@method, 'method_name'
69
+ event.file = 'test_file.rb'
70
+ event.line = 123
71
+ event.method = 'method_name'
72
72
 
73
73
  @layout.items = %w[logger]
74
74
  assert_equal %Q[--- \nlogger: TestLogger\n], @layout.format(event)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TwP-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
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: 2009-05-28 00:00:00 -07:00
12
+ date: 2009-08-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.4.3
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: little-plugger
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.1
44
+ version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: bones
37
47
  type: :development
@@ -121,8 +131,9 @@ files:
121
131
  - test/test_root_logger.rb
122
132
  - test/test_stats.rb
123
133
  - test/test_utils.rb
124
- has_rdoc: true
134
+ has_rdoc: false
125
135
  homepage: http://logging.rubyforge.org/
136
+ licenses:
126
137
  post_install_message:
127
138
  rdoc_options:
128
139
  - --main
@@ -144,9 +155,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
155
  requirements: []
145
156
 
146
157
  rubyforge_project: logging
147
- rubygems_version: 1.2.0
158
+ rubygems_version: 1.3.5
148
159
  signing_key:
149
- specification_version: 2
160
+ specification_version: 3
150
161
  summary: A flexible and extendable logging library for Ruby
151
162
  test_files:
152
163
  - test/appenders/test_buffered_io.rb