loggr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSES.md +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +230 -0
- data/Rakefile +14 -0
- data/lib/logback-classic-0.9.29.jar +0 -0
- data/lib/logback-core-0.9.29.jar +0 -0
- data/lib/loggr.rb +38 -0
- data/lib/loggr/adapter.rb +114 -0
- data/lib/loggr/adapter/abstract.rb +25 -0
- data/lib/loggr/adapter/base.rb +54 -0
- data/lib/loggr/adapter/buffered.rb +25 -0
- data/lib/loggr/adapter/nop.rb +39 -0
- data/lib/loggr/adapter/rails.rb +36 -0
- data/lib/loggr/adapter/slf4j.rb +30 -0
- data/lib/loggr/factory.rb +9 -0
- data/lib/loggr/lint.rb +54 -0
- data/lib/loggr/severity.rb +16 -0
- data/lib/loggr/slf4j.rb +7 -0
- data/lib/loggr/slf4j/jars.rb +44 -0
- data/lib/loggr/slf4j/logger.rb +88 -0
- data/lib/loggr/slf4j/mdc.rb +35 -0
- data/lib/loggr/version.rb +3 -0
- data/lib/slf4j-api-1.6.1.jar +0 -0
- data/loggr.gemspec +26 -0
- data/test/logback_helper.rb +54 -0
- data/test/test_helper.rb +50 -0
- data/test/unit/adapter/abstract_test.rb +12 -0
- data/test/unit/adapter/base_test.rb +65 -0
- data/test/unit/adapter/buffered_test.rb +44 -0
- data/test/unit/adapter/nop_test.rb +24 -0
- data/test/unit/adapter/rails_test.rb +38 -0
- data/test/unit/adapter/slf4j_test.rb +25 -0
- data/test/unit/factory_test.rb +60 -0
- data/test/unit/slf4j/jars_test.rb +22 -0
- data/test/unit/slf4j/logger_test.rb +139 -0
- data/test/unit/slf4j/mdc_test.rb +77 -0
- metadata +151 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'logback_helper'
|
3
|
+
require 'loggr/slf4j/jars'
|
4
|
+
|
5
|
+
class Loggr::SLF4J::JarsTest < MiniTest::Unit::TestCase
|
6
|
+
include Loggr::SLF4J
|
7
|
+
|
8
|
+
def test_slf4j_api_jar_path
|
9
|
+
assert File.exist?(Jars.slf4j_api_jar_path)
|
10
|
+
assert_match Jars.slf4j_api_jar_path, %r{/slf4j-api-[0-9\.]+\.jar\z}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_logback_core_jar_path
|
14
|
+
assert File.exist?(Jars.logback_core_jar_path)
|
15
|
+
assert_match Jars.logback_core_jar_path, %r{/logback-core-[0-9\.]+\.jar\z}
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_logback_jar_path
|
19
|
+
assert File.exist?(Jars.logback_jar_path)
|
20
|
+
assert_match Jars.logback_jar_path, %r{/logback-classic-[0-9\.]+\.jar\z}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'logback_helper'
|
3
|
+
|
4
|
+
class Loggr::SLF4J::LoggerTest < MiniTest::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_logback!
|
7
|
+
if_jruby do
|
8
|
+
require 'loggr/slf4j/logger'
|
9
|
+
@logger = Loggr::SLF4J::Logger.new('test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_setting_logger_name
|
14
|
+
skip_unless_jruby
|
15
|
+
assert_equal 'test', @logger.java_logger.getName()
|
16
|
+
assert_equal 'test', Loggr::SLF4J::Logger.new(:test).java_logger.getName()
|
17
|
+
assert_equal 'test/fancy::Logger', Loggr::SLF4J::Logger.new(:'test/fancy::Logger').java_logger.getName()
|
18
|
+
assert_equal 'test.Logger', Loggr::SLF4J::Logger.new('test.Logger').java_logger.getName()
|
19
|
+
assert_equal 'Loggr::SLF4J', Loggr::SLF4J::Logger.new('Loggr::SLF4J').java_logger.getName()
|
20
|
+
assert_equal 'Loggr::SLF4J/basic', Loggr::SLF4J::Logger.new('Loggr::SLF4J/basic').java_logger.getName()
|
21
|
+
assert_equal 'loggr.slf4j.LoggerTest', Loggr::SLF4J::Logger.new(self).java_logger.getName()
|
22
|
+
assert_equal 'loggr.slf4j.LoggerTest', Loggr::SLF4J::Logger.new(self.class).java_logger.getName()
|
23
|
+
assert_equal 'loggr.SLF4J', Loggr::SLF4J::Logger.new(Loggr::SLF4J).java_logger.getName()
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_behaves_like_stdlib_logger
|
27
|
+
skip_unless_jruby
|
28
|
+
%w{debug info warn error fatal}.each do |level|
|
29
|
+
assert_respond_to @logger, level
|
30
|
+
assert_respond_to @logger, "#{level}?"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_respond_to_close_and_flush
|
35
|
+
skip_unless_jruby
|
36
|
+
assert_respond_to @logger, :close
|
37
|
+
assert_respond_to @logger, :flush
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_trace_message
|
41
|
+
skip_unless_jruby
|
42
|
+
@logger.trace "a trace message"
|
43
|
+
assert_log_event 5000, "a trace message", @appender.last
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_debug_message
|
47
|
+
skip_unless_jruby
|
48
|
+
@logger.debug "a debug message"
|
49
|
+
assert_log_event 10000, "a debug message", @appender.last
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_info_message
|
53
|
+
skip_unless_jruby
|
54
|
+
@logger.info "an info message"
|
55
|
+
assert_log_event 20000, "an info message", @appender.last
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_warn_message
|
59
|
+
skip_unless_jruby
|
60
|
+
@logger.warn "a warn message"
|
61
|
+
assert_log_event 30000, "a warn message", @appender.last
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_error_message
|
65
|
+
skip_unless_jruby
|
66
|
+
@logger.error "an error message"
|
67
|
+
assert_log_event 40000, "an error message", @appender.last
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_fatal_message
|
71
|
+
skip_unless_jruby
|
72
|
+
@logger.fatal "a fatal message"
|
73
|
+
assert_log_event 40000, "a fatal message", @appender.last
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_logging_message_using_block
|
77
|
+
skip_unless_jruby
|
78
|
+
@logger.info { "block info message" }
|
79
|
+
assert_log_event 20000, "block info message", @appender.last
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_default_logger_has_no_marker
|
83
|
+
skip_unless_jruby
|
84
|
+
@logger.info "no marker"
|
85
|
+
assert_equal nil, @appender.last.getMarker()
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_use_progname_as_marker
|
89
|
+
skip_unless_jruby
|
90
|
+
@logger.info "with marker", "MARK"
|
91
|
+
assert_equal "MARK", @appender.last.getMarker().to_s
|
92
|
+
|
93
|
+
@logger.debug "other marker", "KRAM"
|
94
|
+
assert_equal "KRAM", @appender.last.getMarker().to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_ability_to_provide_default_marker
|
98
|
+
skip_unless_jruby
|
99
|
+
@other = Loggr::SLF4J::Logger.new('test.marker', :marker => "MARK")
|
100
|
+
|
101
|
+
@other.info "no marker"
|
102
|
+
assert_equal "MARK", @appender.last.getMarker().to_s
|
103
|
+
|
104
|
+
@other.debug "other marker", "KRAM"
|
105
|
+
assert_equal "KRAM", @appender.last.getMarker().to_s
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_level_should_be_unknown
|
109
|
+
skip_unless_jruby
|
110
|
+
assert_equal Loggr::SLF4J::Logger::UNKNOWN, @logger.level
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_java_logger
|
114
|
+
skip_unless_jruby
|
115
|
+
refute_nil @logger.java_logger
|
116
|
+
assert_kind_of Java::OrgSlf4j::Logger, @logger.java_logger
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_java_marker
|
120
|
+
skip_unless_jruby
|
121
|
+
assert_nil @logger.java_marker
|
122
|
+
|
123
|
+
@other = Loggr::SLF4J::Logger.new('test.marker', :marker => 'APP')
|
124
|
+
refute_nil @other.java_marker
|
125
|
+
assert_kind_of Java::OrgSlf4j::Marker, @other.java_marker
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_internal_marker_factory
|
129
|
+
skip_unless_jruby
|
130
|
+
assert_nil Loggr::SLF4J::MarkerFactory[nil]
|
131
|
+
assert_nil Loggr::SLF4J::MarkerFactory[' ']
|
132
|
+
assert_nil Loggr::SLF4J::MarkerFactory[""]
|
133
|
+
|
134
|
+
@marker = Loggr::SLF4J::MarkerFactory["MARK"]
|
135
|
+
refute_nil @marker
|
136
|
+
assert_kind_of Java::OrgSlf4j::Marker, @marker
|
137
|
+
assert_same @marker, Loggr::SLF4J::MarkerFactory["MARK"]
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'logback_helper'
|
3
|
+
|
4
|
+
class Loggr::SLF4J::MdcTest < MiniTest::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_logback!
|
7
|
+
if_jruby do
|
8
|
+
require 'loggr/slf4j/mdc'
|
9
|
+
require 'loggr/slf4j/logger'
|
10
|
+
@logger = Loggr::SLF4J::Logger.new('test')
|
11
|
+
@mdc = Loggr::SLF4J::MDCWrapper.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_allow_setting_and_getting_values
|
16
|
+
skip_unless_jruby
|
17
|
+
@mdc[:key] = "value"
|
18
|
+
@mdc["string"] = "string"
|
19
|
+
assert_equal "value", @mdc[:key]
|
20
|
+
assert_equal "value", @mdc["key"]
|
21
|
+
assert_equal "string", @mdc[:string]
|
22
|
+
assert_equal "string", @mdc["string"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_clearing_mdc
|
26
|
+
skip_unless_jruby
|
27
|
+
@mdc[:key] = "value"
|
28
|
+
@mdc[:string] = "string"
|
29
|
+
assert_equal "value", @mdc[:key]
|
30
|
+
assert_equal "string", @mdc[:string]
|
31
|
+
@mdc.clear
|
32
|
+
assert_nil @mdc[:key]
|
33
|
+
assert_nil @mdc[:string]
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_delete_from_mdc
|
37
|
+
skip_unless_jruby
|
38
|
+
@mdc[:key] = "value"
|
39
|
+
@mdc[:string] = "string"
|
40
|
+
assert_equal "value", @mdc[:key]
|
41
|
+
assert_equal "string", @mdc[:string]
|
42
|
+
@mdc.delete(:string)
|
43
|
+
assert_equal "value", @mdc[:key]
|
44
|
+
assert_nil @mdc[:string]
|
45
|
+
@mdc.delete(:string)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_to_hash
|
49
|
+
skip_unless_jruby
|
50
|
+
@mdc[:key] = "value"
|
51
|
+
@mdc[:string] = "string"
|
52
|
+
hash = @mdc.to_hash
|
53
|
+
assert hash.frozen?, "hash should be frozen"
|
54
|
+
assert_equal "value", hash["key"]
|
55
|
+
assert_equal "string", hash["string"]
|
56
|
+
assert_nil hash[:key]
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_is_written_to_logback_appender
|
60
|
+
skip_unless_jruby
|
61
|
+
@mdc[:key] = "value"
|
62
|
+
@mdc[:string] = "string"
|
63
|
+
|
64
|
+
@logger.info "with mdc!"
|
65
|
+
assert_equal({ "key" => "value", "string" => "string" }, @appender.last.getMdc())
|
66
|
+
|
67
|
+
@mdc.delete(:string)
|
68
|
+
@logger.info "no longer has :string mdc"
|
69
|
+
assert_equal({ "key" => "value" }, @appender.last.getMdc())
|
70
|
+
|
71
|
+
@mdc.clear
|
72
|
+
@logger.info "no mdc anymore"
|
73
|
+
|
74
|
+
java_mdc_map = @appender.last.getMdc()
|
75
|
+
assert java_mdc_map.nil? || java_mdc_map.empty?, "getMdc() -> Map<String,String> should be nil or empty"
|
76
|
+
end
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: loggr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lukas Westermann
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-07 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: minitest
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 3.0.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Adapters for different ruby logging backends. Create loggers using different adapters, like Logger (Stdlib), Rails or SLF4J (in JRuby only).
|
54
|
+
email:
|
55
|
+
- lukas@at-point.ch
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSES.md
|
66
|
+
- MIT-LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/logback-classic-0.9.29.jar
|
70
|
+
- lib/logback-core-0.9.29.jar
|
71
|
+
- lib/loggr.rb
|
72
|
+
- lib/loggr/adapter.rb
|
73
|
+
- lib/loggr/adapter/abstract.rb
|
74
|
+
- lib/loggr/adapter/base.rb
|
75
|
+
- lib/loggr/adapter/buffered.rb
|
76
|
+
- lib/loggr/adapter/nop.rb
|
77
|
+
- lib/loggr/adapter/rails.rb
|
78
|
+
- lib/loggr/adapter/slf4j.rb
|
79
|
+
- lib/loggr/factory.rb
|
80
|
+
- lib/loggr/lint.rb
|
81
|
+
- lib/loggr/severity.rb
|
82
|
+
- lib/loggr/slf4j.rb
|
83
|
+
- lib/loggr/slf4j/jars.rb
|
84
|
+
- lib/loggr/slf4j/logger.rb
|
85
|
+
- lib/loggr/slf4j/mdc.rb
|
86
|
+
- lib/loggr/version.rb
|
87
|
+
- lib/slf4j-api-1.6.1.jar
|
88
|
+
- loggr.gemspec
|
89
|
+
- test/logback_helper.rb
|
90
|
+
- test/test_helper.rb
|
91
|
+
- test/unit/adapter/abstract_test.rb
|
92
|
+
- test/unit/adapter/base_test.rb
|
93
|
+
- test/unit/adapter/buffered_test.rb
|
94
|
+
- test/unit/adapter/nop_test.rb
|
95
|
+
- test/unit/adapter/rails_test.rb
|
96
|
+
- test/unit/adapter/slf4j_test.rb
|
97
|
+
- test/unit/factory_test.rb
|
98
|
+
- test/unit/slf4j/jars_test.rb
|
99
|
+
- test/unit/slf4j/logger_test.rb
|
100
|
+
- test/unit/slf4j/mdc_test.rb
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: https://github.com/at-point/loggr/wiki
|
103
|
+
licenses: []
|
104
|
+
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 57
|
116
|
+
segments:
|
117
|
+
- 1
|
118
|
+
- 8
|
119
|
+
- 7
|
120
|
+
version: 1.8.7
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: 23
|
127
|
+
segments:
|
128
|
+
- 1
|
129
|
+
- 3
|
130
|
+
- 6
|
131
|
+
version: 1.3.6
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.4.1
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Logger factory framework (including an SLF4J wrapper)
|
139
|
+
test_files:
|
140
|
+
- test/logback_helper.rb
|
141
|
+
- test/test_helper.rb
|
142
|
+
- test/unit/adapter/abstract_test.rb
|
143
|
+
- test/unit/adapter/base_test.rb
|
144
|
+
- test/unit/adapter/buffered_test.rb
|
145
|
+
- test/unit/adapter/nop_test.rb
|
146
|
+
- test/unit/adapter/rails_test.rb
|
147
|
+
- test/unit/adapter/slf4j_test.rb
|
148
|
+
- test/unit/factory_test.rb
|
149
|
+
- test/unit/slf4j/jars_test.rb
|
150
|
+
- test/unit/slf4j/logger_test.rb
|
151
|
+
- test/unit/slf4j/mdc_test.rb
|