logback 0.9.9.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.
- data/History.txt +4 -0
- data/Manifest.txt +13 -0
- data/README.txt +38 -0
- data/Rakefile +77 -0
- data/assembly.xml +17 -0
- data/lib/logback.rb +270 -0
- data/lib/logback/access.rb +1 -0
- data/lib/logback/base.rb +21 -0
- data/lib/logback/logback-access-0.9.9.jar +0 -0
- data/lib/logback/logback-classic-0.9.9.jar +0 -0
- data/lib/logback/logback-core-0.9.9.jar +0 -0
- data/pom.xml +51 -0
- data/test/test_logback.rb +152 -0
- metadata +91 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
pom.xml
|
6
|
+
assembly.xml
|
7
|
+
lib/logback.rb
|
8
|
+
lib/logback/access.rb
|
9
|
+
lib/logback/base.rb
|
10
|
+
test/test_logback.rb
|
11
|
+
lib/logback/logback-core-0.9.9.jar
|
12
|
+
lib/logback/logback-classic-0.9.9.jar
|
13
|
+
lib/logback/logback-access-0.9.9.jar
|
data/README.txt
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= logback
|
2
|
+
|
3
|
+
* http://rjack.rubyforge.org
|
4
|
+
* http://rubyforge.org/projects/rjack
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
The Logback ruby gem packages the Logback[http://logback.qos.ch/] java log
|
9
|
+
writer, and provides a JRuby facade for programmatic Logback
|
10
|
+
setup. Logback implements the SLF4J[http://www.slf4j.org/] SPI
|
11
|
+
packaged in the slf4j gem.
|
12
|
+
|
13
|
+
== License
|
14
|
+
|
15
|
+
=== Logback Ruby
|
16
|
+
|
17
|
+
Copyright (C) 2008 David Kellum
|
18
|
+
|
19
|
+
Logback Ruby is free software: you can redistribute it and/or
|
20
|
+
modify it under the terms of the
|
21
|
+
{GNU Lesser General Public License}[http://www.gnu.org/licenses/lgpl.html]
|
22
|
+
as published by the Free Software Foundation, either version 3 of the
|
23
|
+
License, or (at your option) any later version.
|
24
|
+
|
25
|
+
Logback Ruby is distributed in the hope that it will be useful, but
|
26
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
27
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
28
|
+
Lesser General Public License for more details.
|
29
|
+
|
30
|
+
=== Logback Java
|
31
|
+
|
32
|
+
Logback: the reliable, generic, fast and flexible logging library for Java.
|
33
|
+
|
34
|
+
Copyright (C) 2000-2006, QOS.ch
|
35
|
+
|
36
|
+
This library is free software, you can redistribute it and/or modify
|
37
|
+
it under the terms of the GNU Lesser General Public License as
|
38
|
+
published by the Free Software Foundation.
|
data/Rakefile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
#--
|
3
|
+
# Copyright (C) 2008 David Kellum
|
4
|
+
#
|
5
|
+
# Logback Ruby is free software: you can redistribute it and/or
|
6
|
+
# modify it under the terms of the
|
7
|
+
# {GNU Lesser General Public License}[http://www.gnu.org/licenses/lgpl.html]
|
8
|
+
# as published by the Free Software Foundation, either version 3 of the
|
9
|
+
# License, or (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Logback Ruby is distributed in the hope that it will be useful, but
|
12
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
# Lesser General Public License for more details.
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
|
19
|
+
ENV['NODOT'] = "no thank you"
|
20
|
+
require 'hoe'
|
21
|
+
|
22
|
+
$LOAD_PATH << './lib'
|
23
|
+
require 'logback/base'
|
24
|
+
|
25
|
+
JARS = %w{ core classic access }.map do |n|
|
26
|
+
"logback-#{n}-#{ LogbackBase::LOGBACK_VERSION }.jar"
|
27
|
+
end
|
28
|
+
JAR_FILES = JARS.map { |jar| "lib/logback/#{jar}" }
|
29
|
+
|
30
|
+
desc "Update the Manifest with actual jars"
|
31
|
+
task :manifest do
|
32
|
+
out = File.new( 'Manifest.txt', 'w' )
|
33
|
+
begin
|
34
|
+
out.write <<END
|
35
|
+
History.txt
|
36
|
+
Manifest.txt
|
37
|
+
README.txt
|
38
|
+
Rakefile
|
39
|
+
pom.xml
|
40
|
+
assembly.xml
|
41
|
+
lib/logback.rb
|
42
|
+
lib/logback/access.rb
|
43
|
+
lib/logback/base.rb
|
44
|
+
test/test_logback.rb
|
45
|
+
END
|
46
|
+
out.puts JAR_FILES
|
47
|
+
ensure
|
48
|
+
out.close
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
ASSEMBLY = "target/logback-assembly-1.0-bin.dir"
|
53
|
+
|
54
|
+
file ASSEMBLY => [ 'pom.xml', 'assembly.xml' ] do
|
55
|
+
sh( 'mvn package' )
|
56
|
+
end
|
57
|
+
|
58
|
+
JARS.each do |jar|
|
59
|
+
file "lib/logback/#{jar}" => [ ASSEMBLY ] do
|
60
|
+
cp_r( File.join( ASSEMBLY, jar ), 'lib/logback' )
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
[ :gem, :test ].each { |t| task t => JAR_FILES }
|
65
|
+
|
66
|
+
task :mvn_clean do
|
67
|
+
rm_f( JAR_FILES )
|
68
|
+
sh( 'mvn clean' )
|
69
|
+
end
|
70
|
+
task :clean => :mvn_clean
|
71
|
+
|
72
|
+
hoe = Hoe.new( "logback", LogbackBase::VERSION ) do |p|
|
73
|
+
p.developer( "David Kellum", "dek-gem@gravitext.com" )
|
74
|
+
p.extra_deps << [ 'slf4j', '>=1.5.3.1' ]
|
75
|
+
p.rubyforge_name = "rjack"
|
76
|
+
p.rdoc_pattern = /^(lib.*\.(rb|txt))|[^\/]*\.txt$/
|
77
|
+
end
|
data/assembly.xml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<assembly>
|
2
|
+
<id>bin</id>
|
3
|
+
<formats>
|
4
|
+
<format>dir</format>
|
5
|
+
</formats>
|
6
|
+
<includeBaseDirectory>false</includeBaseDirectory>
|
7
|
+
<dependencySets>
|
8
|
+
<dependencySet>
|
9
|
+
<includes>
|
10
|
+
<include>ch.qos.logback:logback-classic</include>
|
11
|
+
<include>ch.qos.logback:logback-core</include>
|
12
|
+
<include>ch.qos.logback:logback-access</include>
|
13
|
+
</includes>
|
14
|
+
</dependencySet>
|
15
|
+
</dependencySets>
|
16
|
+
|
17
|
+
</assembly>
|
data/lib/logback.rb
ADDED
@@ -0,0 +1,270 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2008 David Kellum
|
3
|
+
#
|
4
|
+
# Logback Ruby is free software: you can redistribute it and/or
|
5
|
+
# modify it under the terms of the
|
6
|
+
# {GNU Lesser General Public License}[http://www.gnu.org/licenses/lgpl.html]
|
7
|
+
# as published by the Free Software Foundation, either version 3 of the
|
8
|
+
# License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Logback Ruby is distributed in the hope that it will be useful, but
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#++
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
|
18
|
+
gem( 'slf4j', '>=1.5.3.1' )
|
19
|
+
require 'slf4j'
|
20
|
+
|
21
|
+
require 'java'
|
22
|
+
|
23
|
+
require 'logback/base'
|
24
|
+
|
25
|
+
# Jruby wrapper module for the Logback[http://logback.qos.ch/] log writer.
|
26
|
+
# Programmatic configuration and setting of logger output levels is supported.
|
27
|
+
#
|
28
|
+
# == Example
|
29
|
+
#
|
30
|
+
# Logback configuration:
|
31
|
+
#
|
32
|
+
# require 'slf4j'
|
33
|
+
# require 'logback'
|
34
|
+
#
|
35
|
+
# log = SLF4J[ 'example' ]
|
36
|
+
# log.info "About to reconfigure..."
|
37
|
+
#
|
38
|
+
# Logback.configure do
|
39
|
+
# console = Logback::ConsoleAppender.new do |a|
|
40
|
+
# a.target = "System.err"
|
41
|
+
# a.layout = Logback::PatternLayout.new do |p|
|
42
|
+
# p.pattern = "%r %-5level %logger{35} - %msg %ex%n"
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
# Logback.root.add_appender( console )
|
46
|
+
# Logback.root.level = Logback::INFO
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# # Adjust output levels (also works outside of configure )
|
50
|
+
# Logback[ 'example' ].level = Logback::DEBUG
|
51
|
+
#
|
52
|
+
# log.debug "...after reconfigure."
|
53
|
+
#
|
54
|
+
# Configure with Logback XML configuration:
|
55
|
+
#
|
56
|
+
# Logback.configure do
|
57
|
+
# Logback.load_xml_config( 'sample-logback.xml' )
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# == Programmatic Configuration Support
|
61
|
+
#
|
62
|
+
# Logback java classes implement interfaces +LifeCycle+ and
|
63
|
+
# +ContextAware+ for configurability with Joran (XML). To simplify
|
64
|
+
# configuration in ruby, the following classes have been extended:
|
65
|
+
#
|
66
|
+
# * ConsoleAppender
|
67
|
+
# * FileAppender
|
68
|
+
# * PatternLayout
|
69
|
+
#
|
70
|
+
# The extensions provide a block initializer which sets sensible
|
71
|
+
# defaults, yields to a block for customization, and then calls
|
72
|
+
# +start+. Logback provides many other components not yet extended in
|
73
|
+
# this way. These can be created directly and or extended in a
|
74
|
+
# similar fashion externally. Consider providing a patch to the
|
75
|
+
# jrack[http://rubyforge.org/projects/rjack] project with any desired
|
76
|
+
# extensions.
|
77
|
+
#
|
78
|
+
module Logback
|
79
|
+
include LogbackBase
|
80
|
+
|
81
|
+
def self.require_jar( name )
|
82
|
+
require File.join( LOGBACK_DIR, "#{name}-#{ LOGBACK_VERSION }.jar" )
|
83
|
+
end
|
84
|
+
|
85
|
+
require_jar 'logback-core'
|
86
|
+
require_jar 'logback-classic'
|
87
|
+
|
88
|
+
import 'ch.qos.logback.classic.Level'
|
89
|
+
|
90
|
+
TRACE = Level::TRACE
|
91
|
+
DEBUG = Level::DEBUG
|
92
|
+
INFO = Level::INFO
|
93
|
+
WARN = Level::WARN
|
94
|
+
ERROR = Level::ERROR
|
95
|
+
|
96
|
+
DEFAULT_PATTERN = "%date [%thread] %-5level %logger{35} - %msg %ex%n"
|
97
|
+
|
98
|
+
@@context = SLF4J.linked_factory
|
99
|
+
|
100
|
+
# Returns the LoggerContext
|
101
|
+
def self.context
|
102
|
+
@@context
|
103
|
+
end
|
104
|
+
|
105
|
+
module Util
|
106
|
+
def self.start( lifecycle_obj )
|
107
|
+
lifecycle_obj.start
|
108
|
+
raise "#{lifecycle_obj.class.name} did not start" if ! lifecycle_obj.started?
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Wrapper for
|
113
|
+
# ch.qos.logback.classic.Logger[http://logback.qos.ch/apidocs/ch/qos/logback/classic/Logger.html]
|
114
|
+
class Logger
|
115
|
+
def initialize( jlogger )
|
116
|
+
@jlogger = jlogger
|
117
|
+
end
|
118
|
+
|
119
|
+
# Set output level to specified constant (DEBUG,INFO,...)
|
120
|
+
def level=( level )
|
121
|
+
#FIXME: LogBack bug: level = nil
|
122
|
+
@jlogger.level = level
|
123
|
+
end
|
124
|
+
|
125
|
+
# Add appender to this logger
|
126
|
+
def add_appender( appender )
|
127
|
+
@jlogger.add_appender( appender )
|
128
|
+
end
|
129
|
+
|
130
|
+
# Set additive flag ( false means events stop at attached appender )
|
131
|
+
def additive=( is_additive )
|
132
|
+
@jlogger.additive = is_additive
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
import 'ch.qos.logback.classic.joran.JoranConfigurator'
|
137
|
+
|
138
|
+
# Load the specified Logback (Joran) XML configuration file. Should be
|
139
|
+
# called within a configure {...} block.
|
140
|
+
def self.load_xml_config( file )
|
141
|
+
cfger = JoranConfigurator.new
|
142
|
+
cfger.context = @@context
|
143
|
+
cfger.doConfigure( file )
|
144
|
+
end
|
145
|
+
|
146
|
+
import( 'ch.qos.logback.classic.PatternLayout' ) { 'JPatternLayout' }
|
147
|
+
|
148
|
+
# Extends
|
149
|
+
# ch.qos.logback.classic.PatternLayout[http://logback.qos.ch/apidocs/ch/qos/logback/access/PatternLayout.html]
|
150
|
+
# with a block initializer.
|
151
|
+
class PatternLayout < JPatternLayout
|
152
|
+
|
153
|
+
# Sets context and pattern, yields self to block, and calls self.start
|
154
|
+
#
|
155
|
+
# :call-seq:
|
156
|
+
# new(pattern=DEFAULT_PATTERN) -> PatternLayout
|
157
|
+
# new(pattern=DEFAULT_PATTERN) { |self| ... } -> PatternLayout
|
158
|
+
#
|
159
|
+
def initialize( pattern=DEFAULT_PATTERN )
|
160
|
+
super()
|
161
|
+
self.context = Logback.context
|
162
|
+
self.pattern = pattern
|
163
|
+
yield( self ) if block_given?
|
164
|
+
Util.start( self )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
module AppenderUtil
|
169
|
+
@@default_layout = Logback::PatternLayout.new
|
170
|
+
|
171
|
+
def set_defaults
|
172
|
+
self.context = Logback.context
|
173
|
+
self.name = self.class.name
|
174
|
+
self.layout = @@default_layout
|
175
|
+
end
|
176
|
+
|
177
|
+
def finish( &block )
|
178
|
+
block.call( self ) unless block.nil?
|
179
|
+
Util.start( self )
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
import( 'ch.qos.logback.core.ConsoleAppender' ) { 'JConsoleAppender' }
|
184
|
+
|
185
|
+
# Extends
|
186
|
+
# ch.qos.logback.core.ConsoleAppender[http://logback.qos.ch/apidocs/ch/qos/logback/core/ConsoleAppender.html]
|
187
|
+
# with a block initializer.
|
188
|
+
class ConsoleAppender < JConsoleAppender
|
189
|
+
include AppenderUtil
|
190
|
+
|
191
|
+
# Sets context, default name and layout, yields self to block, and
|
192
|
+
# calls self.start
|
193
|
+
#
|
194
|
+
# :call-seq:
|
195
|
+
# new() -> ConsoleAppender
|
196
|
+
# new() { |self| ... } -> ConsoleAppender
|
197
|
+
#
|
198
|
+
def initialize( &block )
|
199
|
+
super()
|
200
|
+
set_defaults
|
201
|
+
finish( &block )
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
import( 'ch.qos.logback.core.FileAppender' ) { 'JFileAppender' }
|
206
|
+
|
207
|
+
# Extends
|
208
|
+
# ch.qos.logback.core.FileAppender[http://logback.qos.ch/apidocs/ch/qos/logback/core/FileAppender.html]
|
209
|
+
# with a block initializer.
|
210
|
+
#
|
211
|
+
# Note that if buffered (immediate_flush = false, buffer_size > 0),
|
212
|
+
# you will need to +stop+ the appender before exiting in order to
|
213
|
+
# flush/close the log. Calling:
|
214
|
+
#
|
215
|
+
# Logback.configure {}
|
216
|
+
#
|
217
|
+
# Will also result in the log being flushed and closed.
|
218
|
+
#
|
219
|
+
class FileAppender < JFileAppender
|
220
|
+
include AppenderUtil
|
221
|
+
|
222
|
+
# Sets defaults, yields self to block, and calls self.start
|
223
|
+
#
|
224
|
+
# :call-seq:
|
225
|
+
# new(file_name,append = true) -> FileAppender
|
226
|
+
# new(file_name,append = true) { |self| ... } -> FileAppender
|
227
|
+
#
|
228
|
+
def initialize( file_name, append = true, &block )
|
229
|
+
super()
|
230
|
+
set_defaults
|
231
|
+
self.file = file_name
|
232
|
+
self.append = append
|
233
|
+
self.immediate_flush = true #default
|
234
|
+
self.encoding = "UTF-8"
|
235
|
+
finish( &block )
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# Configure Logback with the specified block. The Logback context is
|
240
|
+
# +shutdownAndReset+ before yielding, and then started after return
|
241
|
+
# from the block.
|
242
|
+
#
|
243
|
+
# :call-seq:
|
244
|
+
# configure { |context| ... } -> nil
|
245
|
+
#
|
246
|
+
def self.configure
|
247
|
+
@@context.shutdown_and_reset
|
248
|
+
|
249
|
+
yield( context )
|
250
|
+
|
251
|
+
Util.start( context )
|
252
|
+
nil
|
253
|
+
end
|
254
|
+
|
255
|
+
# Returns the named Logger
|
256
|
+
def self.logger( name )
|
257
|
+
Logger.new( @@context.getLogger( name ) )
|
258
|
+
end
|
259
|
+
|
260
|
+
# Synonym for logger(name)
|
261
|
+
def self.[](name)
|
262
|
+
logger( name )
|
263
|
+
end
|
264
|
+
|
265
|
+
# Returns the special "root" Logger
|
266
|
+
def self.root
|
267
|
+
logger( "root" )
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Logback.require_jar 'logback-access'
|
data/lib/logback/base.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2008 David Kellum
|
3
|
+
#
|
4
|
+
# Logback Ruby is free software: you can redistribute it and/or
|
5
|
+
# modify it under the terms of the
|
6
|
+
# {GNU Lesser General Public License}[http://www.gnu.org/licenses/lgpl.html]
|
7
|
+
# as published by the Free Software Foundation, either version 3 of the
|
8
|
+
# License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Logback Ruby is distributed in the hope that it will be useful, but
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#++
|
15
|
+
|
16
|
+
module LogbackBase
|
17
|
+
LOGBACK_VERSION = '0.9.9'
|
18
|
+
VERSION = LOGBACK_VERSION + '.1'
|
19
|
+
|
20
|
+
LOGBACK_DIR = File.dirname(__FILE__) # :nodoc:
|
21
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/pom.xml
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
2
|
+
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
<groupId>com.gravitext</groupId>
|
5
|
+
<artifactId>logback-assembly</artifactId>
|
6
|
+
<packaging>pom</packaging>
|
7
|
+
<version>1.0</version>
|
8
|
+
<name>Logback Assembly for Gem</name>
|
9
|
+
|
10
|
+
<dependencies>
|
11
|
+
|
12
|
+
<dependency>
|
13
|
+
<groupId>ch.qos.logback</groupId>
|
14
|
+
<artifactId>logback-classic</artifactId>
|
15
|
+
<version>0.9.9</version>
|
16
|
+
<scope>runtime</scope>
|
17
|
+
</dependency>
|
18
|
+
|
19
|
+
<dependency>
|
20
|
+
<groupId>ch.qos.logback</groupId>
|
21
|
+
<artifactId>logback-access</artifactId>
|
22
|
+
<version>0.9.9</version>
|
23
|
+
<scope>runtime</scope>
|
24
|
+
</dependency>
|
25
|
+
|
26
|
+
</dependencies>
|
27
|
+
|
28
|
+
<build>
|
29
|
+
<plugins>
|
30
|
+
<plugin>
|
31
|
+
<artifactId>maven-assembly-plugin</artifactId>
|
32
|
+
<configuration>
|
33
|
+
<descriptors>
|
34
|
+
<descriptor>assembly.xml</descriptor>
|
35
|
+
</descriptors>
|
36
|
+
<tarLongFileMode>gnu</tarLongFileMode>
|
37
|
+
</configuration>
|
38
|
+
<executions>
|
39
|
+
<execution>
|
40
|
+
<id>assembly</id>
|
41
|
+
<phase>package</phase>
|
42
|
+
<goals>
|
43
|
+
<goal>attached</goal>
|
44
|
+
</goals>
|
45
|
+
</execution>
|
46
|
+
</executions>
|
47
|
+
</plugin>
|
48
|
+
</plugins>
|
49
|
+
</build>
|
50
|
+
|
51
|
+
</project>
|
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
#--
|
3
|
+
# Copyright 2008 David Kellum
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
6
|
+
# may not use this file except in compliance with the License. You
|
7
|
+
# may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
14
|
+
# implied. See the License for the specific language governing
|
15
|
+
# permissions and limitations under the License.
|
16
|
+
#++
|
17
|
+
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift File.join( File.dirname(__FILE__), "..", "lib" )
|
20
|
+
|
21
|
+
require 'logback'
|
22
|
+
|
23
|
+
# Test load works
|
24
|
+
require 'logback/access'
|
25
|
+
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
class TestAppender
|
29
|
+
import 'ch.qos.logback.core.Appender'
|
30
|
+
include Appender
|
31
|
+
|
32
|
+
attr_reader :count, :last
|
33
|
+
attr_writer :layout
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
reset
|
37
|
+
end
|
38
|
+
|
39
|
+
def doAppend( event )
|
40
|
+
@count += 1
|
41
|
+
@last = event
|
42
|
+
@last = @layout.nil? ? event : @layout.doLayout( event )
|
43
|
+
end
|
44
|
+
|
45
|
+
def start; end
|
46
|
+
def stop; end
|
47
|
+
|
48
|
+
def reset
|
49
|
+
@count = 0
|
50
|
+
@last = nil
|
51
|
+
@layout = nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestLevelSet < Test::Unit::TestCase
|
56
|
+
|
57
|
+
def setup
|
58
|
+
@appender = TestAppender.new
|
59
|
+
Logback.configure do
|
60
|
+
Logback.root.add_appender( @appender )
|
61
|
+
end
|
62
|
+
@log = SLF4J[ "my.app" ]
|
63
|
+
end
|
64
|
+
|
65
|
+
def teardown
|
66
|
+
@appender.reset()
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_below_level
|
70
|
+
Logback.root.level = Logback::ERROR
|
71
|
+
assert( ! @log.debug? )
|
72
|
+
@log.debug( "not logged" )
|
73
|
+
@log.debug { "also not logged" }
|
74
|
+
assert_equal( 0, @appender.count )
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_above_level
|
78
|
+
Logback.root.level = Logback::TRACE
|
79
|
+
assert( @log.trace? )
|
80
|
+
@log.trace( "logged" )
|
81
|
+
assert_equal( 1, @appender.count )
|
82
|
+
assert_equal( Logback::TRACE, @appender.last.level )
|
83
|
+
assert_equal( "logged", @appender.last.message )
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def test_override_level
|
88
|
+
Logback.root.level = Logback::ERROR
|
89
|
+
Logback[ "my" ].level = Logback::WARN
|
90
|
+
assert( @log.warn? )
|
91
|
+
@log.warn( "override" )
|
92
|
+
assert_equal( Logback::WARN, @appender.last.level )
|
93
|
+
assert_equal( 1, @appender.count )
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
class TestConfigure < Test::Unit::TestCase
|
99
|
+
|
100
|
+
def test_file_appender_config
|
101
|
+
log_file = "./test_appends.test_file_appender.log"
|
102
|
+
|
103
|
+
Logback.configure do
|
104
|
+
appender = Logback::FileAppender.new( log_file, false ) do |a|
|
105
|
+
a.layout = Logback::PatternLayout.new( "%level-%msg" )
|
106
|
+
a.immediate_flush = true
|
107
|
+
a.encoding = "ISO-8859-1"
|
108
|
+
end
|
109
|
+
Logback.root.add_appender( appender )
|
110
|
+
end
|
111
|
+
log = SLF4J[ self.class.name ]
|
112
|
+
log.debug( "write to file" )
|
113
|
+
assert( File.file?( log_file ) )
|
114
|
+
assert( File.stat( log_file ).size > 0 )
|
115
|
+
assert_equal( 1, File.delete( log_file ) )
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_pattern_config
|
119
|
+
appender = TestAppender.new
|
120
|
+
Logback.configure do
|
121
|
+
appender.layout = Logback::PatternLayout.new( "%level-%msg" )
|
122
|
+
Logback.root.add_appender( appender )
|
123
|
+
end
|
124
|
+
|
125
|
+
log = SLF4J[ self.class.name ]
|
126
|
+
log.info( "message" )
|
127
|
+
assert_equal( 1, appender.count )
|
128
|
+
assert_equal( "INFO-message", appender.last )
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def test_console_config
|
133
|
+
log_name = "#{self.class.name}.#{self.method_name}"
|
134
|
+
appender = TestAppender.new
|
135
|
+
Logback.configure do
|
136
|
+
console = Logback::ConsoleAppender.new do |a|
|
137
|
+
a.immediate_flush = true
|
138
|
+
a.encoding = "UTF-8"
|
139
|
+
a.target = "System.out"
|
140
|
+
end
|
141
|
+
Logback.root.add_appender( console )
|
142
|
+
Logback[ log_name ].add_appender( appender )
|
143
|
+
end
|
144
|
+
|
145
|
+
Logback[ log_name ].level = Logback::DEBUG
|
146
|
+
Logback[ log_name ].additive = false
|
147
|
+
log = SLF4J[ log_name ]
|
148
|
+
log.debug( "test write to console" )
|
149
|
+
assert_equal( 1, appender.count )
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
+
requirements:
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: "0"
|
7
|
+
version:
|
8
|
+
email:
|
9
|
+
- dek-gem@gravitext.com
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
summary: The Logback ruby gem packages the Logback[http://logback.qos.ch/] java log
|
13
|
+
writer, and provides a JRuby facade for programmatic Logback setup
|
14
|
+
post_install_message:
|
15
|
+
extra_rdoc_files:
|
16
|
+
- History.txt
|
17
|
+
- Manifest.txt
|
18
|
+
- README.txt
|
19
|
+
homepage: http://rjack.rubyforge.org
|
20
|
+
signing_key:
|
21
|
+
name: logback
|
22
|
+
rdoc_options:
|
23
|
+
- --main
|
24
|
+
- README.txt
|
25
|
+
autorequire:
|
26
|
+
rubyforge_project: rjack
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
description: The Logback ruby gem packages the Logback[http://logback.qos.ch/] java
|
30
|
+
log writer, and provides a JRuby facade for programmatic Logback setup. Logback
|
31
|
+
implements the SLF4J[http://www.slf4j.org/] SPI packaged in the slf4j gem.
|
32
|
+
specification_version: 2
|
33
|
+
default_executable:
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- pom.xml
|
40
|
+
- assembly.xml
|
41
|
+
- lib/logback.rb
|
42
|
+
- lib/logback/access.rb
|
43
|
+
- lib/logback/base.rb
|
44
|
+
- test/test_logback.rb
|
45
|
+
- lib/logback/logback-core-0.9.9.jar
|
46
|
+
- lib/logback/logback-classic-0.9.9.jar
|
47
|
+
- lib/logback/logback-access-0.9.9.jar
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
authors:
|
60
|
+
- David Kellum
|
61
|
+
date: 2008-10-13 08:00:00 +00:00
|
62
|
+
platform: ruby
|
63
|
+
test_files:
|
64
|
+
- test/test_logback.rb
|
65
|
+
version: !ruby/object:Gem::Version
|
66
|
+
version: 0.9.9.1
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
dependencies:
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.5.3.1
|
76
|
+
version:
|
77
|
+
type: :runtime
|
78
|
+
version_requirement:
|
79
|
+
name: slf4j
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.0
|
86
|
+
version:
|
87
|
+
type: :development
|
88
|
+
version_requirement:
|
89
|
+
name: hoe
|
90
|
+
bindir: bin
|
91
|
+
has_rdoc: true
|