logging 0.1.0

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.
@@ -0,0 +1,121 @@
1
+ # $Id: test_logging.rb 12 2007-01-14 20:03:40Z tim_pease $
2
+
3
+ require 'test/setup.rb'
4
+
5
+ module TestLogging
6
+
7
+ class TestLogging < Test::Unit::TestCase
8
+ include LoggingTestCase
9
+
10
+ def setup
11
+ super
12
+ @levels = ::Logging::LEVELS
13
+ @lnames = ::Logging::LNAMES
14
+ end
15
+
16
+ def test_define_levels_default
17
+ empty = {}
18
+ assert_equal empty, @levels
19
+ assert_equal empty, @lnames
20
+ assert_same false, ::Logging.const_defined?(:MAX_LEVEL_LENGTH)
21
+
22
+ ::Logging::Repository.instance
23
+
24
+ assert_equal 5, @levels.length
25
+ assert_equal 5, @lnames.length
26
+ assert_equal 5, ::Logging::MAX_LEVEL_LENGTH
27
+
28
+ assert_equal 0, @levels['debug']
29
+ assert_equal 1, @levels['info']
30
+ assert_equal 2, @levels['warn']
31
+ assert_equal 3, @levels['error']
32
+ assert_equal 4, @levels['fatal']
33
+
34
+ assert_equal 'DEBUG', @lnames[0]
35
+ assert_equal 'INFO', @lnames[1]
36
+ assert_equal 'WARN', @lnames[2]
37
+ assert_equal 'ERROR', @lnames[3]
38
+ assert_equal 'FATAL', @lnames[4]
39
+ end
40
+
41
+ def test_define_levels_special
42
+ empty = {}
43
+ assert_equal empty, @levels
44
+ assert_equal empty, @lnames
45
+ assert_same false, ::Logging.const_defined?(:MAX_LEVEL_LENGTH)
46
+
47
+ assert_raise(ArgumentError) {::Logging.define_levels(1, 2, 3, 4)}
48
+
49
+ ::Logging.define_levels :one, 'two', :THREE, 'FoUr', :sIx
50
+
51
+ assert_equal 5, @levels.length
52
+ assert_equal 5, @lnames.length
53
+ assert_equal 5, ::Logging::MAX_LEVEL_LENGTH
54
+
55
+ assert_equal 0, @levels['one']
56
+ assert_equal 1, @levels['two']
57
+ assert_equal 2, @levels['three']
58
+ assert_equal 3, @levels['four']
59
+ assert_equal 4, @levels['six']
60
+
61
+ assert_equal 'ONE', @lnames[0]
62
+ assert_equal 'TWO', @lnames[1]
63
+ assert_equal 'THREE', @lnames[2]
64
+ assert_equal 'FOUR', @lnames[3]
65
+ assert_equal 'SIX', @lnames[4]
66
+ end
67
+
68
+ def test_define_levels_all_off
69
+ empty = {}
70
+ assert_equal empty, @levels
71
+ assert_equal empty, @lnames
72
+ assert_same false, ::Logging.const_defined?(:MAX_LEVEL_LENGTH)
73
+
74
+ ::Logging.define_levels %w(a b all c off d)
75
+
76
+ assert_equal 4, @levels.length
77
+ assert_equal 4, @lnames.length
78
+ assert_equal 1, ::Logging::MAX_LEVEL_LENGTH
79
+
80
+ assert_equal 0, @levels['a']
81
+ assert_equal 1, @levels['b']
82
+ assert_equal 2, @levels['c']
83
+ assert_equal 3, @levels['d']
84
+
85
+ assert_equal 'A', @lnames[0]
86
+ assert_equal 'B', @lnames[1]
87
+ assert_equal 'C', @lnames[2]
88
+ assert_equal 'D', @lnames[3]
89
+ end
90
+
91
+ def test_format_as
92
+ assert_equal false, ::Logging.const_defined?('OBJ_FORMAT')
93
+
94
+ assert_raises(ArgumentError) {::Logging.format_as 'string'}
95
+ assert_raises(ArgumentError) {::Logging.format_as String}
96
+ assert_raises(ArgumentError) {::Logging.format_as :what?}
97
+
98
+ remove_const = lambda do |const|
99
+ ::Logging.class_eval {remove_const const if const_defined? const}
100
+ end
101
+
102
+ ::Logging.format_as :string
103
+ assert ::Logging.const_defined?('OBJ_FORMAT')
104
+ assert_equal :string, ::Logging::OBJ_FORMAT
105
+ remove_const[:OBJ_FORMAT]
106
+
107
+ ::Logging.format_as :inspect
108
+ assert ::Logging.const_defined?('OBJ_FORMAT')
109
+ assert_equal :inspect, ::Logging::OBJ_FORMAT
110
+ remove_const[:OBJ_FORMAT]
111
+
112
+ ::Logging.format_as :yaml
113
+ assert ::Logging.const_defined?('OBJ_FORMAT')
114
+ assert_equal :yaml, ::Logging::OBJ_FORMAT
115
+ remove_const[:OBJ_FORMAT]
116
+ end
117
+
118
+ end # class TestLogging
119
+ end # module TestLogging
120
+
121
+ # EOF
@@ -0,0 +1,113 @@
1
+ # $Id: test_repository.rb 13 2007-01-15 17:19:37Z tim_pease $
2
+
3
+ require 'test/setup.rb'
4
+
5
+ module TestLogging
6
+
7
+ class TestRepository < Test::Unit::TestCase
8
+ include LoggingTestCase
9
+
10
+ def setup
11
+ super
12
+ @repo = ::Logging::Repository.instance
13
+ end
14
+
15
+ def test_instance
16
+ assert_same @repo, ::Logging::Repository.instance
17
+ end
18
+
19
+ def test_aref
20
+ root = @repo[:root]
21
+ assert_same root, @repo[:root]
22
+
23
+ a = []
24
+ ::Logging::Logger.new a
25
+ assert_same @repo['Array'], @repo[Array]
26
+ assert_same @repo['Array'], @repo[a]
27
+
28
+ assert_not_same @repo['Array'], @repo[:root]
29
+
30
+ ::Logging::Logger.new 'A'
31
+ ::Logging::Logger.new 'A::B'
32
+ assert_not_same @repo['A'], @repo['A::B']
33
+ end
34
+
35
+ def test_aset
36
+ root = @repo[:root]
37
+ @repo[:root] = 'root'
38
+ assert_not_same root, @repo[:root]
39
+
40
+ assert_nil @repo['blah']
41
+ @repo['blah'] = 'root'
42
+ assert_equal 'root', @repo['blah']
43
+ end
44
+
45
+ def test_fetch
46
+ assert_raise(IndexError) {@repo.fetch 'A'}
47
+ assert_same @repo[:root], @repo.fetch(:root)
48
+ end
49
+
50
+ def test_parent
51
+ %w(A A::B A::B::C::D A::B::C::E A::B::C::F).each do |name|
52
+ ::Logging::Logger.new(name)
53
+ end
54
+
55
+ assert_same @repo[:root], @repo.parent('A')
56
+ assert_same @repo['A'], @repo.parent('A::B')
57
+ assert_same @repo['A::B'], @repo.parent('A::B::C')
58
+ assert_same @repo['A::B'], @repo.parent('A::B::C::D')
59
+ assert_same @repo['A::B'], @repo.parent('A::B::C::E')
60
+ assert_same @repo['A::B'], @repo.parent('A::B::C::F')
61
+
62
+ ::Logging::Logger.new('A::B::C')
63
+
64
+ assert_same @repo['A::B'], @repo.parent('A::B::C')
65
+ assert_same @repo['A::B::C'], @repo.parent('A::B::C::D')
66
+ assert_same @repo['A::B::C'], @repo.parent('A::B::C::E')
67
+ assert_same @repo['A::B::C'], @repo.parent('A::B::C::F')
68
+
69
+ ::Logging::Logger.new('A::B::C::E::G')
70
+
71
+ assert_same @repo['A::B::C::E'], @repo.parent('A::B::C::E::G')
72
+ end
73
+
74
+ def test_children
75
+ ::Logging::Logger.new('A')
76
+
77
+ assert_equal [], @repo.children('A')
78
+
79
+ ::Logging::Logger.new('A::B')
80
+ a = %w(D E F).map {|name| ::Logging::Logger.new('A::B::C::'+name)}.sort
81
+
82
+ assert_equal [@repo['A::B']], @repo.children('A')
83
+ assert_equal a, @repo.children('A::B')
84
+ assert_equal a, @repo.children('A::B::C')
85
+
86
+ ::Logging::Logger.new('A::B::C')
87
+
88
+ assert_equal [@repo['A::B::C']], @repo.children('A::B')
89
+ assert_equal a, @repo.children('A::B::C')
90
+
91
+ ::Logging::Logger.new('A::B::C::E::G')
92
+
93
+ assert_equal a, @repo.children('A::B::C')
94
+ assert_equal [@repo['A::B::C::E::G']], @repo.children('A::B::C::E')
95
+ end
96
+
97
+ def test_to_key
98
+ assert_equal :root, @repo.to_key(:root)
99
+ assert_equal 'Object', @repo.to_key('Object')
100
+ assert_equal 'Object', @repo.to_key(Object)
101
+ assert_equal 'Object', @repo.to_key(Object.new)
102
+
103
+ assert_equal 'String', @repo.to_key(String)
104
+ assert_equal 'Array', @repo.to_key([])
105
+
106
+ assert_equal 'blah', @repo.to_key('blah')
107
+ assert_equal :blah, @repo.to_key(:blah)
108
+ end
109
+
110
+ end # class TestRepository
111
+ end # module TestLogging
112
+
113
+ # EOF
@@ -0,0 +1,67 @@
1
+ # $Id: test_root_logger.rb 13 2007-01-15 17:19:37Z tim_pease $
2
+
3
+ require 'test/setup.rb'
4
+ require 'stringio'
5
+
6
+ module TestLogging
7
+
8
+ class TestRootLogger < Test::Unit::TestCase
9
+ include LoggingTestCase
10
+
11
+ def setup
12
+ super
13
+ @root = ::Logging::Logger.root
14
+ end
15
+
16
+ def test_level_eq
17
+ assert_equal 0, @root.level
18
+
19
+ assert_raise(ArgumentError) {@root.level = -1}
20
+ assert_raise(ArgumentError) {@root.level = 6}
21
+ assert_raise(ArgumentError) {@root.level = Object}
22
+ assert_raise(ArgumentError) {@root.level = 'bob'}
23
+ assert_raise(ArgumentError) {@root.level = :wtf}
24
+
25
+ @root.level = 'INFO'
26
+ assert_equal 1, @root.level
27
+
28
+ @root.level = :warn
29
+ assert_equal 2, @root.level
30
+
31
+ @root.level = 'error'
32
+ assert_equal 3, @root.level
33
+
34
+ @root.level = 4
35
+ assert_equal 4, @root.level
36
+
37
+ @root.level = :all
38
+ assert_equal 0, @root.level
39
+
40
+ @root.level = 'OFF'
41
+ assert_equal 5, @root.level
42
+
43
+ @root.level = nil
44
+ assert_equal 0, @root.level
45
+ end
46
+
47
+ def test_name
48
+ assert_equal 'root', @root.name
49
+ end
50
+
51
+ def test_spaceship
52
+ logs = %w(
53
+ A A::B A::B::C A::B::C::D A::B::C::E A::B::C::E::G A::B::C::F
54
+ ).map {|x| ::Logging::Logger[x]}
55
+
56
+ logs.each do |log|
57
+ assert_equal(-1, @root <=> log, "'root' <=> '#{log.name}'")
58
+ end
59
+
60
+ assert_equal 0, @root <=> @root
61
+ assert_raise(ArgumentError) {@root <=> 'string'}
62
+ end
63
+
64
+ end # class TestRootLogger
65
+ end # module TestLogging
66
+
67
+ # EOF
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: logging
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-01-15 00:00:00 -07:00
8
+ summary: A flexible and extendable logging library for Ruby.
9
+ require_paths:
10
+ - lib
11
+ - test
12
+ email: tim.pease@gmail.com
13
+ homepage: http://logging.rubyforge.org/
14
+ rubyforge_project: logging
15
+ description: 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.
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Tim Pease
32
+ files:
33
+ - README.txt
34
+ - lib/logging.rb
35
+ - lib/logging/appender.rb
36
+ - lib/logging/appenders/console.rb
37
+ - lib/logging/appenders/file.rb
38
+ - lib/logging/appenders/io.rb
39
+ - lib/logging/appenders/static_appender.rb
40
+ - lib/logging/layout.rb
41
+ - lib/logging/layouts/basic.rb
42
+ - lib/logging/layouts/pattern.rb
43
+ - lib/logging/log_event.rb
44
+ - lib/logging/logger.rb
45
+ - lib/logging/repository.rb
46
+ - lib/logging/root_logger.rb
47
+ - test/appenders/test_console.rb
48
+ - test/appenders/test_file.rb
49
+ - test/appenders/test_io.rb
50
+ - test/benchmark.rb
51
+ - test/layouts/test_basic.rb
52
+ - test/layouts/test_pattern.rb
53
+ - test/setup.rb
54
+ - test/test_all.rb
55
+ - test/test_appender.rb
56
+ - test/test_layout.rb
57
+ - test/test_log_event.rb
58
+ - test/test_logger.rb
59
+ - test/test_logging.rb
60
+ - test/test_repository.rb
61
+ - test/test_root_logger.rb
62
+ test_files:
63
+ - test/test_all.rb
64
+ rdoc_options: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ executables: []
69
+
70
+ extensions: []
71
+
72
+ requirements: []
73
+
74
+ dependencies: []
75
+