TwP-logging 0.9.8 → 0.9.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,10 +9,10 @@ module TestLayouts
9
9
 
10
10
  def setup
11
11
  super
12
- ::Logging.init
13
- @layout = ::Logging::Layouts::Pattern.new
14
- @levels = ::Logging::LEVELS
12
+ @layout = Logging.layouts.pattern({})
13
+ @levels = Logging::LEVELS
15
14
  @date_fmt = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
15
+ Thread.current[:name] = nil
16
16
  end
17
17
 
18
18
  def test_date_method
@@ -58,8 +58,8 @@ module TestLayouts
58
58
  def test_format
59
59
  fmt = '\[' + @date_fmt + '\] %s -- %s : %s\n'
60
60
 
61
- event = ::Logging::LogEvent.new('ArrayLogger', @levels['info'],
62
- 'log message', false)
61
+ event = Logging::LogEvent.new('ArrayLogger', @levels['info'],
62
+ 'log message', false)
63
63
  rgxp = Regexp.new(sprintf(fmt, 'INFO ', 'ArrayLogger', 'log message'))
64
64
  assert_match rgxp, @layout.format(event)
65
65
 
@@ -92,8 +92,8 @@ module TestLayouts
92
92
  end
93
93
 
94
94
  def test_pattern_eq
95
- event = ::Logging::LogEvent.new('TestLogger', @levels['info'],
96
- ['log message'], false)
95
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
96
+ ['log message'], false)
97
97
 
98
98
  @layout.pattern = '%d'
99
99
  assert_equal '%d', @layout.pattern
@@ -101,8 +101,8 @@ module TestLayouts
101
101
  end
102
102
 
103
103
  def test_pattern_all
104
- event = ::Logging::LogEvent.new('TestLogger', @levels['info'],
105
- 'log message', false)
104
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
105
+ 'log message', false)
106
106
  event.instance_variable_set :@file, 'test_file.rb'
107
107
  event.instance_variable_set :@line, '123'
108
108
  event.instance_variable_set :@method, 'method_name'
@@ -0,0 +1,121 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[.. setup])
3
+
4
+ module TestLogging
5
+ module TestLayouts
6
+
7
+ class TestYaml < Test::Unit::TestCase
8
+ include LoggingTestCase
9
+
10
+ def setup
11
+ super
12
+ @layout = Logging.layouts.yaml({})
13
+ @levels = Logging::LEVELS
14
+ @date_fmt = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'
15
+ Thread.current[:name] = nil
16
+ end
17
+
18
+ def test_format
19
+ h = {
20
+ 'level' => 'INFO',
21
+ 'logger' => 'ArrayLogger',
22
+ 'message' => 'log message'
23
+ }
24
+
25
+ event = Logging::LogEvent.new('ArrayLogger', @levels['info'],
26
+ 'log message', false)
27
+ assert_yaml_match h, @layout.format(event)
28
+
29
+ event.data = [1, 2, 3, 4]
30
+ h['message'] = "<Array> #{[1,2,3,4]}"
31
+ assert_yaml_match h, @layout.format(event)
32
+
33
+ event.level = @levels['debug']
34
+ event.data = 'and another message'
35
+ h['level'] = 'DEBUG'
36
+ h['message'] = 'and another message'
37
+ assert_yaml_match h, @layout.format(event)
38
+
39
+ event.logger = 'Test'
40
+ event.level = @levels['fatal']
41
+ event.data = Exception.new
42
+ h['level'] = 'FATAL'
43
+ h['logger'] = 'Test'
44
+ h['message'] = '<Exception> Exception'
45
+ assert_yaml_match h, @layout.format(event)
46
+ end
47
+
48
+ def test_items
49
+ assert_equal %w[timestamp level logger message], @layout.items
50
+ end
51
+
52
+ def test_items_eq
53
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
54
+ ['log message'], false)
55
+
56
+ @layout.items = %w[timestamp]
57
+ assert_equal %w[timestamp], @layout.items
58
+ assert_match %r/--- \ntimestamp: #@date_fmt\n/, @layout.format(event)
59
+
60
+ # 'foo' is not a recognized item
61
+ assert_raise(ArgumentError) {
62
+ @layout.items = %w[timestamp logger foo]
63
+ }
64
+ end
65
+
66
+ def test_items_all
67
+ event = Logging::LogEvent.new('TestLogger', @levels['info'],
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'
72
+
73
+ @layout.items = %w[logger]
74
+ assert_equal %Q[--- \nlogger: TestLogger\n], @layout.format(event)
75
+
76
+ @layout.items = %w[file]
77
+ assert_equal %Q[--- \nfile: test_file.rb\n], @layout.format(event)
78
+
79
+ @layout.items = %w[level]
80
+ assert_equal %Q[--- \nlevel: INFO\n], @layout.format(event)
81
+
82
+ @layout.items = %w[line]
83
+ assert_equal %Q[--- \nline: 123\n], @layout.format(event)
84
+
85
+ @layout.items = %w[message]
86
+ assert_equal %Q[--- \nmessage: log message\n], @layout.format(event)
87
+
88
+ @layout.items = %w[method]
89
+ assert_equal %Q[--- \nmethod: method_name\n], @layout.format(event)
90
+
91
+ @layout.items = %w[pid]
92
+ assert_match %r/\A--- \npid: \d+\n\z/, @layout.format(event)
93
+
94
+ @layout.items = %w[millis]
95
+ assert_match %r/\A--- \nmillis: \d+\n\z/, @layout.format(event)
96
+
97
+ @layout.items = %w[thread_id]
98
+ assert_match %r/\A--- \nthread_id: -?\d+\n\z/, @layout.format(event)
99
+
100
+ @layout.items = %w[thread]
101
+ assert_equal %Q[--- \nthread: \n], @layout.format(event)
102
+ Thread.current[:name] = "Main"
103
+ assert_equal %Q[--- \nthread: Main\n], @layout.format(event)
104
+ end
105
+
106
+ private
107
+
108
+ def assert_yaml_match( expected, actual )
109
+ actual = YAML.load(actual)
110
+
111
+ assert_match %r/#@date_fmt/o, actual['timestamp']
112
+ assert_equal expected['level'], actual['level']
113
+ assert_equal expected['logger'], actual['logger']
114
+ assert_equal expected['message'], actual['message']
115
+ end
116
+
117
+ end # class TestYaml
118
+ end # module TestLayouts
119
+ end # module TestLogging
120
+
121
+ # EOF
data/test/setup.rb CHANGED
@@ -59,7 +59,7 @@ module LoggingTestCase
59
59
  super
60
60
  ::Logging.backtrace
61
61
  ::Logging.__send__(:remove_instance_variable, :@backtrace)
62
- h = ::Logging::Appender.instance_variable_get(:@appenders)
62
+ h = ::Logging::Appenders.instance_variable_get(:@appenders)
63
63
  h.each_value {|a| a.close(false) unless a.nil? || a.closed?}
64
64
  h.clear
65
65
  FileUtils.rm_rf TMP
@@ -40,20 +40,6 @@ module TestLogging
40
40
  assert_raise(RuntimeError) {@appender.append @event}
41
41
  end
42
42
 
43
- def test_class_stderr
44
- stderr = ::Logging::Appender.stderr
45
- assert_instance_of ::Logging::Appenders::Stderr, stderr
46
- assert_equal 'stderr', stderr.name
47
- assert_same stderr, ::Logging::Appender.stderr
48
- end
49
-
50
- def test_class_stdout
51
- stdout = ::Logging::Appender.stdout
52
- assert_instance_of ::Logging::Appenders::Stdout, stdout
53
- assert_equal 'stdout', stdout.name
54
- assert_same stdout, ::Logging::Appender.stdout
55
- end
56
-
57
43
  def test_close
58
44
  assert_equal false, @appender.closed?
59
45
 
@@ -48,7 +48,7 @@ module TestLogging
48
48
 
49
49
  @logger.trace = true
50
50
  @logger.error 'error message'
51
- assert_match %r/\d+/, @appender.event.line
51
+ assert_equal 50, @appender.event.line
52
52
  end
53
53
 
54
54
  def test_logger
data/test/test_logging.rb CHANGED
@@ -50,11 +50,11 @@ module TestLogging
50
50
  assert_equal 3, ::Logging::Logger.root.level
51
51
 
52
52
  # verify the appenders
53
- h = ::Logging::Appender.instance_variable_get :@appenders
53
+ h = ::Logging::Appenders.instance_variable_get :@appenders
54
54
  assert_equal ['logfile', 'stderr'], h.keys.sort
55
55
 
56
56
  # start with the File appender
57
- logfile = ::Logging::Appender['logfile']
57
+ logfile = ::Logging::Appenders['logfile']
58
58
  assert_instance_of ::Logging::Appenders::File, logfile
59
59
  assert_equal 0, logfile.level
60
60
  assert_equal 'tmp/temp.log', logfile.instance_variable_get(:@fn)
@@ -66,7 +66,7 @@ module TestLogging
66
66
  assert_nil layout.date_pattern
67
67
 
68
68
  # and now the Stderr appender
69
- stderr = ::Logging::Appender['stderr']
69
+ stderr = ::Logging::Appenders['stderr']
70
70
  assert_instance_of ::Logging::Appenders::Stderr, stderr
71
71
  assert_equal 0, stderr.level
72
72
 
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: 0.9.8
4
+ version: 0.9.8.1
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-04-11 00:00:00 -07:00
12
+ date: 2009-04-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,7 @@ files:
62
62
  - data/simple_logging.rb
63
63
  - lib/logging.rb
64
64
  - lib/logging/appender.rb
65
+ - lib/logging/appenders.rb
65
66
  - lib/logging/appenders/buffering.rb
66
67
  - lib/logging/appenders/console.rb
67
68
  - lib/logging/appenders/email.rb
@@ -74,7 +75,9 @@ files:
74
75
  - lib/logging/config/configurator.rb
75
76
  - lib/logging/config/yaml_configurator.rb
76
77
  - lib/logging/layout.rb
78
+ - lib/logging/layouts.rb
77
79
  - lib/logging/layouts/basic.rb
80
+ - lib/logging/layouts/parseable.rb
78
81
  - lib/logging/layouts/pattern.rb
79
82
  - lib/logging/log_event.rb
80
83
  - lib/logging/logger.rb
@@ -82,7 +85,7 @@ files:
82
85
  - lib/logging/root_logger.rb
83
86
  - lib/logging/stats.rb
84
87
  - lib/logging/utils.rb
85
- - logging.gemspec
88
+ - lib/spec/logging_helper.rb
86
89
  - test/appenders/test_buffered_io.rb
87
90
  - test/appenders/test_console.rb
88
91
  - test/appenders/test_email.rb
@@ -95,7 +98,9 @@ files:
95
98
  - test/config/test_configurator.rb
96
99
  - test/config/test_yaml_configurator.rb
97
100
  - test/layouts/test_basic.rb
101
+ - test/layouts/test_json.rb
98
102
  - test/layouts/test_pattern.rb
103
+ - test/layouts/test_yaml.rb
99
104
  - test/setup.rb
100
105
  - test/test_appender.rb
101
106
  - test/test_layout.rb
@@ -145,7 +150,9 @@ test_files:
145
150
  - test/config/test_configurator.rb
146
151
  - test/config/test_yaml_configurator.rb
147
152
  - test/layouts/test_basic.rb
153
+ - test/layouts/test_json.rb
148
154
  - test/layouts/test_pattern.rb
155
+ - test/layouts/test_yaml.rb
149
156
  - test/test_appender.rb
150
157
  - test/test_layout.rb
151
158
  - test/test_log_event.rb
data/logging.gemspec DELETED
@@ -1,41 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{logging}
5
- s.version = "0.9.8"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Tim Pease"]
9
- s.date = %q{2009-04-11}
10
- s.description = %q{Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.}
11
- s.email = %q{tim.pease@gmail.com}
12
- s.extra_rdoc_files = ["History.txt", "README.rdoc"]
13
- s.files = ["History.txt", "README.rdoc", "Rakefile", "data/bad_logging_1.rb", "data/bad_logging_2.rb", "data/logging.rb", "data/logging.yaml", "data/simple_logging.rb", "lib/logging.rb", "lib/logging/appender.rb", "lib/logging/appenders/buffering.rb", "lib/logging/appenders/console.rb", "lib/logging/appenders/email.rb", "lib/logging/appenders/file.rb", "lib/logging/appenders/growl.rb", "lib/logging/appenders/io.rb", "lib/logging/appenders/rolling_file.rb", "lib/logging/appenders/string_io.rb", "lib/logging/appenders/syslog.rb", "lib/logging/config/configurator.rb", "lib/logging/config/yaml_configurator.rb", "lib/logging/layout.rb", "lib/logging/layouts/basic.rb", "lib/logging/layouts/pattern.rb", "lib/logging/log_event.rb", "lib/logging/logger.rb", "lib/logging/repository.rb", "lib/logging/root_logger.rb", "lib/logging/stats.rb", "lib/logging/utils.rb", "logging.gemspec", "test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_email.rb", "test/appenders/test_file.rb", "test/appenders/test_growl.rb", "test/appenders/test_io.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_syslog.rb", "test/benchmark.rb", "test/config/test_configurator.rb", "test/config/test_yaml_configurator.rb", "test/layouts/test_basic.rb", "test/layouts/test_pattern.rb", "test/setup.rb", "test/test_appender.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_stats.rb", "test/test_utils.rb"]
14
- s.has_rdoc = true
15
- s.homepage = %q{http://logging.rubyforge.org/}
16
- s.rdoc_options = ["--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{logging}
19
- s.rubygems_version = %q{1.3.1}
20
- s.summary = %q{A flexible and extendable logging library for Ruby}
21
- s.test_files = ["test/appenders/test_buffered_io.rb", "test/appenders/test_console.rb", "test/appenders/test_email.rb", "test/appenders/test_file.rb", "test/appenders/test_growl.rb", "test/appenders/test_io.rb", "test/appenders/test_rolling_file.rb", "test/appenders/test_syslog.rb", "test/config/test_configurator.rb", "test/config/test_yaml_configurator.rb", "test/layouts/test_basic.rb", "test/layouts/test_pattern.rb", "test/test_appender.rb", "test/test_layout.rb", "test/test_log_event.rb", "test/test_logger.rb", "test/test_logging.rb", "test/test_repository.rb", "test/test_root_logger.rb", "test/test_stats.rb", "test/test_utils.rb"]
22
-
23
- if s.respond_to? :specification_version then
24
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
26
-
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
- s.add_runtime_dependency(%q<flexmock>, [">= 0.8.2"])
29
- s.add_runtime_dependency(%q<lockfile>, [">= 1.4.3"])
30
- s.add_development_dependency(%q<bones>, [">= 2.5.0"])
31
- else
32
- s.add_dependency(%q<flexmock>, [">= 0.8.2"])
33
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
34
- s.add_dependency(%q<bones>, [">= 2.5.0"])
35
- end
36
- else
37
- s.add_dependency(%q<flexmock>, [">= 0.8.2"])
38
- s.add_dependency(%q<lockfile>, [">= 1.4.3"])
39
- s.add_dependency(%q<bones>, [">= 2.5.0"])
40
- end
41
- end