Imported Upstream version 1.7.12
Emmanuel Bourg
8 years ago
0 | Copyright (c) 2004-2014 QOS.ch | |
1 | All rights reserved. | |
2 | ||
3 | Permission is hereby granted, free of charge, to any person obtaining | |
4 | a copy of this software and associated documentation files (the | |
5 | "Software"), to deal in the Software without restriction, including | |
6 | without limitation the rights to use, copy, modify, merge, publish, | |
7 | distribute, sublicense, and/or sell copies of the Software, and to | |
8 | permit persons to whom the Software is furnished to do so, subject to | |
9 | the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be | |
12 | included in all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
21 | ||
22 | ||
23 |
0 | # About SLF4J | |
1 | The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time. | |
2 | More information can be found on the [SLF4J website](http://www.slf4j.org). | |
3 | # Build Status | |
4 | [](https://travis-ci.org/qos-ch/slf4j) | |
5 | ||
6 | # How to contribute pull requests | |
7 | If you are interested in improving SLF4J, great! The SLF4J community looks forward to your contribution. Please follow this process: | |
8 | ||
9 | 1. Start a discussion on the [slf4j-dev mailing list](http://www.slf4j.org/mailing-lists.html) about your proposed change. Alternately file a [bug report](http://www.slf4j.org/bug-reporting.html). | |
10 | 2. Fork qos-ch/slf4j. Ideally, create a new branch from your fork for your contribution to make it easier to merge your changes back. | |
11 | 3. Make your changes on the branch you hopefuly created in Step 2. Be sure that your code passes existing unit tests. Please add unit tests for your work if appropriate. It usually is. | |
12 | 4. Push your changes to your fork/branch in github. Don't push it to your master! If you do it will make it harder to submit new changes later. | |
13 | 5. Submit a pull request to SLF4J from from your commit page on github. |
0 | <project name="integration" default="testAll" basedir="."> | |
1 | ||
2 | <!-- | |
3 | This build file is usually run indirectly via Maven. | |
4 | ||
5 | When running this build file through Ant directly, you must | |
6 | define the currentVersion property on the command line, e.g.: | |
7 | ||
8 | ant -DcurrentVersion=1.5.4-SNAPSHOT | |
9 | --> | |
10 | ||
11 | <echo message="compile classpath: ${compile_classpath}" /> | |
12 | <echo message="runtime classpath: ${runtime_classpath}" /> | |
13 | <echo message="test classpath: ${test_classpath}" /> | |
14 | <echo message="plugin classpath: ${plugin_classpath}" /> | |
15 | ||
16 | ||
17 | <path id="path142Binding"> | |
18 | <pathelement location="target/test-classes/" /> | |
19 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
20 | <pathelement location="./lib/slf4j-simple-1.4.2.jar" /> | |
21 | </path > | |
22 | ||
23 | <path id="path150Binding"> | |
24 | <pathelement location="target/test-classes/" /> | |
25 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
26 | <pathelement location="./lib/slf4j-simple-1.5.0.jar" /> | |
27 | </path > | |
28 | ||
29 | <path id="path1511API"> | |
30 | <pathelement location="target/test-classes/" /> | |
31 | <pathelement location="./lib/slf4j-api-1.5.11.jar" /> | |
32 | <pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" /> | |
33 | </path > | |
34 | ||
35 | <path id="path1511Binding"> | |
36 | <pathelement location="target/test-classes/" /> | |
37 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
38 | <pathelement location="./lib/slf4j-simple-1.5.11.jar" /> | |
39 | </path > | |
40 | ||
41 | <!--<path id="pathIncompatible"> | |
42 | <pathelement location="target/test-classes/" /> | |
43 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
44 | <pathelement location="./lib/slf4j-simple-INCOMPATIBLE.jar" /> | |
45 | </path > | |
46 | --> | |
47 | ||
48 | <path id="pathCurrent"> | |
49 | <pathelement location="target/test-classes/" /> | |
50 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
51 | <pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" /> | |
52 | </path > | |
53 | ||
54 | ||
55 | <path id="incompatibleMultiBinding"> | |
56 | <pathelement location="target/test-classes/" /> | |
57 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
58 | <pathelement location="./lib/slf4j-simple-1.5.0.jar" /> | |
59 | <pathelement location="./lib/slf4j-nop-1.5.6.jar" /> | |
60 | </path > | |
61 | ||
62 | <path id="multiBinding"> | |
63 | <pathelement location="target/test-classes/" /> | |
64 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
65 | <pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" /> | |
66 | <pathelement location="../slf4j-nop/target/slf4j-nop-${currentVersion}.jar" /> | |
67 | </path > | |
68 | ||
69 | <path id="binding166"> | |
70 | <pathelement location="target/test-classes/" /> | |
71 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
72 | <pathelement location="./lib/slf4j-simple-1.6.6.jar" /> | |
73 | </path > | |
74 | ||
75 | <path id="binding2099"> | |
76 | <pathelement location="target/test-classes/" /> | |
77 | <pathelement location="../slf4j-api/target/slf4j-api-${currentVersion}.jar" /> | |
78 | <pathelement location="./lib/slf4j-simple-2.0.99.jar" /> | |
79 | </path > | |
80 | ||
81 | ||
82 | <path id="api166"> | |
83 | <pathelement location="target/test-classes/" /> | |
84 | <pathelement location="../slf4j-simple/target/slf4j-simple-${currentVersion}.jar" /> | |
85 | <pathelement location="./lib/slf4j-api-1.6.6.jar" /> | |
86 | </path > | |
87 | ||
88 | ||
89 | <!-- this is really very ugly, but it's the only way to circumvent | |
90 | http://jira.codehaus.org/browse/MANTRUN-95 | |
91 | --> | |
92 | <taskdef name="junit" classpath="${plugin_classpath};${compile_classpath}" | |
93 | classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" /> | |
94 | ||
95 | <target name="init"> | |
96 | <mkdir dir="target/unit-reports" /> | |
97 | </target> | |
98 | ||
99 | <target name="testAll" depends="init, | |
100 | testMissingSingletonMethod, | |
101 | testMismatch, | |
102 | testMatch, | |
103 | testMultiBinding, | |
104 | testIncompatibleMultiBinding, | |
105 | testFuture_16Series"> | |
106 | </target> | |
107 | ||
108 | ||
109 | <target name="testMissingSingletonMethod"> | |
110 | ||
111 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
112 | <classpath refid="path142Binding" /> | |
113 | <formatter type="plain" /> | |
114 | <test fork="yes" todir="target/unit-reports" | |
115 | outfile="TEST-142BININDING" | |
116 | name="org.slf4j.MissingSingletonMethodAssertionTest" /> | |
117 | </junit> | |
118 | ||
119 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
120 | <classpath refid="path150Binding" /> | |
121 | <formatter type="plain" /> | |
122 | <test fork="yes" todir="target/unit-reports" | |
123 | outfile="TEST-150BINDING" | |
124 | name="org.slf4j.MissingSingletonMethodAssertionTest" /> | |
125 | </junit> | |
126 | ||
127 | </target> | |
128 | ||
129 | <target name="testMismatch"> | |
130 | ||
131 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
132 | <classpath refid="path1511API" /> | |
133 | <formatter type="plain" /> | |
134 | <test fork="yes" todir="target/unit-reports" | |
135 | outfile="TEST-MISMATCH-1511API" | |
136 | name="org.slf4j.VersionMismatchAssertionTest" /> | |
137 | </junit> | |
138 | ||
139 | ||
140 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
141 | <classpath refid="path1511Binding" /> | |
142 | <formatter type="plain" /> | |
143 | <test fork="yes" todir="target/unit-reports" | |
144 | outfile="TEST-MISMATCH-1511Binding" | |
145 | name="org.slf4j.VersionMismatchAssertionTest" /> | |
146 | </junit> | |
147 | ||
148 | </target> | |
149 | ||
150 | <target name="testMatch"> | |
151 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
152 | <classpath refid="pathCurrent" /> | |
153 | <formatter type="plain" /> | |
154 | <test fork="yes" todir="target/unit-reports" | |
155 | outfile="TEST-Match" | |
156 | name="org.slf4j.CompatibilityAssertionTest" /> | |
157 | </junit> | |
158 | </target> | |
159 | ||
160 | <target name="testIncompatibleMultiBinding"> | |
161 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
162 | <classpath refid="incompatibleMultiBinding" /> | |
163 | <formatter type="plain" /> | |
164 | <test fork="yes" todir="target/unit-reports" | |
165 | outfile="TEST-IncompatibleMultiBinding" | |
166 | name="org.slf4j.IncompatibleMultiBindingAssertionTest" /> | |
167 | </junit> | |
168 | </target> | |
169 | ||
170 | <target name="testMultiBinding"> | |
171 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
172 | <classpath refid="multiBinding" /> | |
173 | <formatter type="plain" /> | |
174 | <test fork="yes" todir="target/unit-reports" | |
175 | outfile="TEST-MultiBinding" | |
176 | name="org.slf4j.MultiBindingAssertionTest" /> | |
177 | </junit> | |
178 | </target> | |
179 | ||
180 | <target name="testFuture_16Series"> | |
181 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
182 | <classpath refid="binding166" /> | |
183 | <formatter type="plain" /> | |
184 | <test fork="yes" todir="target/unit-reports" | |
185 | outfile="TEST-binding166" | |
186 | name="org.slf4j.CompatibilityAssertionTest" /> | |
187 | </junit> | |
188 | ||
189 | ||
190 | <junit printsummary="yes" fork="no" haltonfailure="yes"> | |
191 | <classpath refid="api166" /> | |
192 | <formatter type="plain" /> | |
193 | <test fork="yes" todir="target/unit-reports" | |
194 | outfile="TEST-api166" | |
195 | name="org.slf4j.CompatibilityAssertionTest" /> | |
196 | </junit> | |
197 | ||
198 | </target> | |
199 | </project>⏎ |
0 | <project name="osgi-test" default="testAll"> | |
1 | ||
2 | <!-- | |
3 | This build file is usually run indirectly via Maven. | |
4 | ||
5 | When running this build file through Ant directly, you must | |
6 | define the currentVersion property on the command line, e.g.: | |
7 | ||
8 | ant -DcurrentVersion=1.5.4-SNAPSHOT | |
9 | --> | |
10 | ||
11 | <echo message="compile classpath: ${currentVersion}" /> | |
12 | <echo message="test classpath: ${test_classpath}" /> | |
13 | <echo message="basedir: ${basedir}" /> | |
14 | ||
15 | <property name="iBundleJar" value="target/iBundle.jar"/> | |
16 | <property name="bundlesDir" value="bundle"/> | |
17 | ||
18 | ||
19 | <!-- this is really very ugly, but it's the only way to circumvent | |
20 | http://jira.codehaus.org/browse/MANTRUN-95 | |
21 | --> | |
22 | <taskdef name="junit" classpath="${test_classpath}" | |
23 | classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" /> | |
24 | ||
25 | <path id="minimal"> | |
26 | <pathelement location="target/test-classes/" /> | |
27 | </path > | |
28 | ||
29 | <target name="init"> | |
30 | <mkdir dir="target/unit-reports" /> | |
31 | </target> | |
32 | ||
33 | <target name="createIBundle"> | |
34 | <mkdir dir="${bundlesDir}"/> | |
35 | <jar destFile="${iBundleJar}" | |
36 | manifest="src/IBUNDLE-META-INF/MANIFEST.MF" | |
37 | basedir="target/test-classes/" | |
38 | includes="integrator/**.class"/> | |
39 | ||
40 | </target> | |
41 | ||
42 | <target name="testAll" depends="init, createIBundle, nop, simple, jdk14"> | |
43 | </target> | |
44 | ||
45 | ||
46 | <macrodef name="prepareOSGiHarness"> | |
47 | <attribute name="binding"/> | |
48 | <sequential> | |
49 | <delete> | |
50 | <fileset dir="${bundlesDir}" includes="*.jar"/> | |
51 | </delete> | |
52 | <copy file="${iBundleJar}" todir="${bundlesDir}"/> | |
53 | <copy file="../slf4j-api/target/slf4j-api-${currentVersion}.jar" todir="${bundlesDir}"/> | |
54 | <copy file="../slf4j-@{binding}/target/slf4j-@{binding}-${currentVersion}.jar" todir="${bundlesDir}"/> | |
55 | <echo>value of t = @{t}</echo> | |
56 | </sequential> | |
57 | </macrodef> | |
58 | ||
59 | ||
60 | <!-- for some reason if mvn is invoked from the parent directory, junit gets | |
61 | invoked from the parent dir, which messes up theses tests. Hence, the | |
62 | fork="yes" dir="${basedir}" --> | |
63 | ||
64 | <target name="nop"> | |
65 | <prepareOSGiHarness binding="nop"/> | |
66 | <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> | |
67 | <classpath path="${test_classpath}"/> | |
68 | <formatter type="plain" /> | |
69 | <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> | |
70 | </junit> | |
71 | </target> | |
72 | ||
73 | <target name="simple"> | |
74 | <prepareOSGiHarness binding="simple"/> | |
75 | <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> | |
76 | <classpath path="${test_classpath}"/> | |
77 | <formatter type="plain" /> | |
78 | <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> | |
79 | </junit> | |
80 | </target> | |
81 | ||
82 | <target name="jdk14"> | |
83 | <prepareOSGiHarness binding="jdk14"/> | |
84 | <junit printsummary="yes" fork="yes" dir="${basedir}" haltonfailure="yes"> | |
85 | <classpath path="${test_classpath}"/> | |
86 | <formatter type="plain" /> | |
87 | <test fork="yes" todir="target/unit-reports" name="org.slf4j.test_osgi.BundleTest" /> | |
88 | </junit> | |
89 | </target> | |
90 | ||
91 | </project>⏎ |
0 | <project | |
1 | xmlns="http://maven.apache.org/POM/4.0.0" | |
2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | ||
5 | <modelVersion>4.0.0</modelVersion> | |
6 | ||
7 | <parent> | |
8 | <groupId>org.slf4j</groupId> | |
9 | <artifactId>slf4j-parent</artifactId> | |
10 | <version>1.7.12</version> | |
11 | </parent> | |
12 | ||
13 | ||
14 | <artifactId>integration</artifactId> | |
15 | <packaging>jar</packaging> | |
16 | <name>SLF4J Integration tests</name> | |
17 | ||
18 | <url>http://www.slf4j.org</url> | |
19 | <description>SLF4J integration tests</description> | |
20 | ||
21 | <dependencies> | |
22 | <dependency> | |
23 | <groupId>org.slf4j</groupId> | |
24 | <artifactId>slf4j-api</artifactId> | |
25 | </dependency> | |
26 | ||
27 | <!-- declaration to circumvent http://jira.codehaus.org/browse/MANTRUN-95 --> | |
28 | <dependency> | |
29 | <groupId>junit</groupId> | |
30 | <artifactId>junit</artifactId> | |
31 | <version>3.8.1</version> | |
32 | </dependency> | |
33 | <!-- declaration to circumvent http://jira.codehaus.org/browse/MANTRUN-95 --> | |
34 | <dependency> | |
35 | <groupId>ant</groupId> | |
36 | <artifactId>ant-junit</artifactId> | |
37 | <version>1.6.5</version> | |
38 | </dependency> | |
39 | ||
40 | ||
41 | <!-- some test run Felix in hosted mode --> | |
42 | <dependency> | |
43 | <groupId>org.apache.felix</groupId> | |
44 | <artifactId>org.apache.felix.main</artifactId> | |
45 | <version>2.0.2</version> | |
46 | </dependency> | |
47 | </dependencies> | |
48 | ||
49 | <build> | |
50 | <plugins> | |
51 | <plugin> | |
52 | <artifactId>maven-antrun-plugin</artifactId> | |
53 | <version>1.2</version> | |
54 | <dependencies> | |
55 | <dependency> | |
56 | <groupId>junit</groupId> | |
57 | <artifactId>junit</artifactId> | |
58 | <version>3.8.1</version> | |
59 | </dependency> | |
60 | <dependency> | |
61 | <groupId>ant</groupId> | |
62 | <artifactId>ant-junit</artifactId> | |
63 | <version>1.6.5</version> | |
64 | </dependency> | |
65 | </dependencies> | |
66 | <executions> | |
67 | <execution> | |
68 | <id>ant-test</id> | |
69 | <phase>package</phase> | |
70 | <configuration> | |
71 | <tasks> | |
72 | <property name="currentVersion" value="${project.version}"/> | |
73 | <property name="compile_classpath" refid="maven.compile.classpath"/> | |
74 | <property name="runtime_classpath" refid="maven.runtime.classpath"/> | |
75 | <property name="test_classpath" refid="maven.test.classpath"/> | |
76 | <property name="plugin_classpath" refid="maven.plugin.classpath"/> | |
77 | <ant antfile="${basedir}/build.xml"/> | |
78 | </tasks> | |
79 | </configuration> | |
80 | <goals> | |
81 | <goal>run</goal> | |
82 | </goals> | |
83 | </execution> | |
84 | <execution> | |
85 | <id>ant-osgi-test</id> | |
86 | <phase>package</phase> | |
87 | <configuration> | |
88 | <tasks> | |
89 | <property name="currentVersion" value="${project.version}"/> | |
90 | <property name="test_classpath" refid="maven.test.classpath"/> | |
91 | <property name="basedir" value="${basedir}"/> | |
92 | <ant antfile="${basedir}/osgi-build.xml"/> | |
93 | </tasks> | |
94 | </configuration> | |
95 | <goals> | |
96 | <goal>run</goal> | |
97 | </goals> | |
98 | </execution> | |
99 | ||
100 | </executions> | |
101 | </plugin> | |
102 | ||
103 | <plugin> | |
104 | <groupId>org.apache.maven.plugins</groupId> | |
105 | <artifactId>maven-surefire-plugin</artifactId> | |
106 | <configuration> | |
107 | <forkMode>once</forkMode> | |
108 | <reportFormat>plain</reportFormat> | |
109 | <trimStackTrace>false</trimStackTrace> | |
110 | <excludes> | |
111 | <exclude>**/*Test.java</exclude> | |
112 | </excludes> | |
113 | </configuration> | |
114 | </plugin> | |
115 | </plugins> | |
116 | ||
117 | ||
118 | </build> | |
119 | ||
120 | </project>⏎ |
0 | Manifest-Version: 1.0 | |
1 | Archiver-Version: Plexus Archiver | |
2 | Created-By: Apache Maven | |
3 | Built-By: ceki | |
4 | Build-Jdk: 1.6.0_16 | |
5 | Bundle-Description: iBundle | |
6 | Bundle-Version: 0.1 | |
7 | Bundle-Activator: integrator.Activator | |
8 | Implementation-Title: iBundle | |
9 | Bundle-ManifestVersion: 2 | |
10 | Bundle-SymbolicName: iBundle | |
11 | Bundle-Name: abundle | |
12 | Bundle-RequiredExecutionEnvironment: J2SE-1.5 | |
13 | Export-Package: apack | |
14 | Import-Package: org.osgi.framework, org.slf4j;version=1.5⏎ |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package integrator; | |
25 | ||
26 | import org.osgi.framework.Bundle; | |
27 | import org.osgi.framework.BundleActivator; | |
28 | import org.osgi.framework.BundleContext; | |
29 | import org.slf4j.Logger; | |
30 | import org.slf4j.LoggerFactory; | |
31 | ||
32 | /** | |
33 | * A BundleActivator which invokes slf4j loggers | |
34 | * @author Ceki Gülcü | |
35 | * | |
36 | */ | |
37 | public class Activator implements BundleActivator { | |
38 | ||
39 | private BundleContext m_context = null; | |
40 | ||
41 | public void start(BundleContext context) { | |
42 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
43 | logger.info("Activator.start()"); | |
44 | m_context = context; | |
45 | } | |
46 | ||
47 | public void stop(BundleContext context) { | |
48 | m_context = null; | |
49 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
50 | logger.info("Activator.stop"); | |
51 | } | |
52 | ||
53 | public Bundle[] getBundles() { | |
54 | if (m_context != null) { | |
55 | return m_context.getBundles(); | |
56 | } | |
57 | return null; | |
58 | } | |
59 | }⏎ |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | ||
25 | package org.slf4j; | |
26 | ||
27 | import java.io.PrintStream; | |
28 | import java.util.Random; | |
29 | ||
30 | import junit.framework.TestCase; | |
31 | ||
32 | public class CompatibilityAssertionTest extends TestCase { | |
33 | ||
34 | StringPrintStream sps = new StringPrintStream(System.err); | |
35 | PrintStream old = System.err; | |
36 | int diff = 1024 + new Random().nextInt(10000); | |
37 | ||
38 | public CompatibilityAssertionTest(String name) { | |
39 | super(name); | |
40 | } | |
41 | ||
42 | protected void setUp() throws Exception { | |
43 | super.setUp(); | |
44 | System.setErr(sps); | |
45 | } | |
46 | ||
47 | protected void tearDown() throws Exception { | |
48 | super.tearDown(); | |
49 | System.setErr(old); | |
50 | } | |
51 | ||
52 | public void test() throws Exception { | |
53 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
54 | String msg = "hello world " + diff; | |
55 | logger.info(msg); | |
56 | assertEquals(1, sps.stringList.size()); | |
57 | String s0 = (String) sps.stringList.get(0); | |
58 | assertTrue(s0.contains(msg)); | |
59 | } | |
60 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.List; | |
28 | import java.util.Random; | |
29 | ||
30 | import junit.framework.TestCase; | |
31 | ||
32 | public class IncompatibleMultiBindingAssertionTest extends TestCase { | |
33 | ||
34 | StringPrintStream sps = new StringPrintStream(System.err); | |
35 | PrintStream old = System.err; | |
36 | int diff = 1024 + new Random().nextInt(10000); | |
37 | ||
38 | public IncompatibleMultiBindingAssertionTest(String name) { | |
39 | super(name); | |
40 | } | |
41 | ||
42 | protected void setUp() throws Exception { | |
43 | super.setUp(); | |
44 | System.setErr(sps); | |
45 | } | |
46 | ||
47 | protected void tearDown() throws Exception { | |
48 | super.tearDown(); | |
49 | System.setErr(old); | |
50 | } | |
51 | ||
52 | public void test() throws Exception { | |
53 | try { | |
54 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
55 | String msg = "hello world " + diff; | |
56 | logger.info(msg); | |
57 | fail("was expecting NoSuchMethodError"); | |
58 | } catch (NoSuchMethodError e) { | |
59 | } | |
60 | List<String> list = sps.stringList; | |
61 | assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings."); | |
62 | assertMsgContains(list, 1, "Found binding in"); | |
63 | assertMsgContains(list, 2, "Found binding in"); | |
64 | assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html"); | |
65 | assertMsgContains(list, 4, "slf4j-api 1.6.x (or later) is incompatible with this binding"); | |
66 | assertMsgContains(list, 5, "Your binding is version 1.5.5 or earlier."); | |
67 | ||
68 | } | |
69 | ||
70 | void assertMsgContains(List<String> strList, int index, String msg) { | |
71 | assertTrue(((String) strList.get(index)).contains(msg)); | |
72 | } | |
73 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.Random; | |
28 | ||
29 | import junit.framework.TestCase; | |
30 | ||
31 | public class MissingSingletonMethodAssertionTest extends TestCase { | |
32 | ||
33 | StringPrintStream sps = new StringPrintStream(System.err); | |
34 | PrintStream old = System.err; | |
35 | int diff = 1024 + new Random().nextInt(10000); | |
36 | ||
37 | public MissingSingletonMethodAssertionTest(String name) { | |
38 | super(name); | |
39 | } | |
40 | ||
41 | protected void setUp() throws Exception { | |
42 | super.setUp(); | |
43 | System.setErr(sps); | |
44 | } | |
45 | ||
46 | protected void tearDown() throws Exception { | |
47 | super.tearDown(); | |
48 | System.setErr(old); | |
49 | } | |
50 | ||
51 | public void test() throws Exception { | |
52 | try { | |
53 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
54 | String msg = "hello world " + diff; | |
55 | logger.info(msg); | |
56 | fail("NoSuchMethodError expected"); | |
57 | } catch (NoSuchMethodError e) { | |
58 | } | |
59 | ||
60 | int lineCount = sps.stringList.size(); | |
61 | assertTrue("number of lines should be 3 but was " + lineCount, lineCount == 3); | |
62 | ||
63 | // expected output: | |
64 | // SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding. | |
65 | // SLF4J: Your binding is version 1.4.x or earlier. | |
66 | // SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x | |
67 | ||
68 | { | |
69 | String s = (String) sps.stringList.get(0); | |
70 | assertTrue(s.contains("SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.")); | |
71 | } | |
72 | { | |
73 | String s = (String) sps.stringList.get(1); | |
74 | assertTrue(s.contains("SLF4J: Your binding is version 1.5.5 or earlier.")); | |
75 | } | |
76 | { | |
77 | String s = (String) sps.stringList.get(2); | |
78 | assertTrue(s.contains("SLF4J: Upgrade your binding to version 1.6.x.")); | |
79 | } | |
80 | ||
81 | } | |
82 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.List; | |
28 | import java.util.Random; | |
29 | ||
30 | import junit.framework.TestCase; | |
31 | ||
32 | public class MultiBindingAssertionTest extends TestCase { | |
33 | ||
34 | StringPrintStream sps = new StringPrintStream(System.err); | |
35 | PrintStream old = System.err; | |
36 | int diff = 1024 + new Random().nextInt(10000); | |
37 | ||
38 | public MultiBindingAssertionTest(String name) { | |
39 | super(name); | |
40 | } | |
41 | ||
42 | protected void setUp() throws Exception { | |
43 | super.setUp(); | |
44 | System.setErr(sps); | |
45 | } | |
46 | ||
47 | protected void tearDown() throws Exception { | |
48 | super.tearDown(); | |
49 | System.setErr(old); | |
50 | } | |
51 | ||
52 | public void test() throws Exception { | |
53 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
54 | String msg = "hello world " + diff; | |
55 | logger.info(msg); | |
56 | List<String> list = sps.stringList; | |
57 | assertMsgContains(list, 0, "Class path contains multiple SLF4J bindings."); | |
58 | assertMsgContains(list, 1, "Found binding in"); | |
59 | assertMsgContains(list, 2, "Found binding in"); | |
60 | assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html"); | |
61 | assertMsgContains(list, 4, "Actual binding is of type ["); | |
62 | } | |
63 | ||
64 | void assertMsgContains(List<String> strList, int index, String msg) { | |
65 | assertTrue(((String) strList.get(index)).contains(msg)); | |
66 | } | |
67 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.ArrayList; | |
28 | import java.util.List; | |
29 | ||
30 | public class StringPrintStream extends PrintStream { | |
31 | ||
32 | public static final String LINE_SEP = System.getProperty("line.separator"); | |
33 | PrintStream other; | |
34 | List<String> stringList = new ArrayList<String>(); | |
35 | ||
36 | public StringPrintStream(PrintStream ps) { | |
37 | super(ps); | |
38 | other = ps; | |
39 | } | |
40 | ||
41 | public void print(String s) { | |
42 | other.print(s); | |
43 | stringList.add(s); | |
44 | } | |
45 | ||
46 | public void println(String s) { | |
47 | other.println(s); | |
48 | stringList.add(s); | |
49 | } | |
50 | ||
51 | public void println(Object o) { | |
52 | other.println(o); | |
53 | stringList.add(o.toString()); | |
54 | } | |
55 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j; | |
25 | ||
26 | import java.io.PrintStream; | |
27 | import java.util.Random; | |
28 | ||
29 | import junit.framework.TestCase; | |
30 | ||
31 | public class VersionMismatchAssertionTest extends TestCase { | |
32 | ||
33 | StringPrintStream sps = new StringPrintStream(System.err); | |
34 | PrintStream old = System.err; | |
35 | int diff = 1024 + new Random().nextInt(10000); | |
36 | ||
37 | public VersionMismatchAssertionTest(String name) { | |
38 | super(name); | |
39 | } | |
40 | ||
41 | protected void setUp() throws Exception { | |
42 | super.setUp(); | |
43 | System.setErr(sps); | |
44 | } | |
45 | ||
46 | protected void tearDown() throws Exception { | |
47 | super.tearDown(); | |
48 | System.setErr(old); | |
49 | } | |
50 | ||
51 | public void test() throws Exception { | |
52 | Logger logger = LoggerFactory.getLogger(this.getClass()); | |
53 | String msg = "hello world " + diff; | |
54 | logger.info(msg); | |
55 | ||
56 | String s0 = (String) sps.stringList.get(0); | |
57 | assertTrue(s0.matches("SLF4J: The requested version .* by your slf4j binding is not compatible with.*")); | |
58 | ||
59 | String s1 = (String) sps.stringList.get(1); | |
60 | assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH)); | |
61 | ||
62 | String s2 = (String) sps.stringList.get(2); | |
63 | assertTrue(s2.contains(msg)); | |
64 | ||
65 | } | |
66 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.test_osgi; | |
25 | ||
26 | import java.io.File; | |
27 | ||
28 | import junit.framework.TestCase; | |
29 | ||
30 | public class BundleTest extends TestCase { | |
31 | ||
32 | FrameworkErrorListener fel = new FrameworkErrorListener(); | |
33 | CheckingBundleListener mbl = new CheckingBundleListener(); | |
34 | ||
35 | FelixHost felixHost = new FelixHost(fel, mbl); | |
36 | ||
37 | protected void setUp() throws Exception { | |
38 | super.setUp(); | |
39 | felixHost.doLaunch(); | |
40 | } | |
41 | ||
42 | protected void tearDown() throws Exception { | |
43 | super.tearDown(); | |
44 | felixHost.stop(); | |
45 | } | |
46 | ||
47 | public void testSmoke() { | |
48 | System.out.println("===========" + new File(".").getAbsolutePath()); | |
49 | mbl.dumpAll(); | |
50 | // check that the bundle was installed | |
51 | assertTrue(mbl.exists("iBundle")); | |
52 | if (fel.errorList.size() != 0) { | |
53 | fel.dumpAll(); | |
54 | } | |
55 | // check that no errors occured | |
56 | assertEquals(0, fel.errorList.size()); | |
57 | } | |
58 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.test_osgi; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.List; | |
28 | ||
29 | import org.osgi.framework.Bundle; | |
30 | import org.osgi.framework.BundleEvent; | |
31 | import org.osgi.framework.BundleListener; | |
32 | ||
33 | public class CheckingBundleListener implements BundleListener { | |
34 | ||
35 | List<BundleEvent> eventList = new ArrayList<BundleEvent>(); | |
36 | ||
37 | public void bundleChanged(BundleEvent be) { | |
38 | eventList.add(be); | |
39 | } | |
40 | ||
41 | private void dump(BundleEvent be) { | |
42 | System.out.println("BE:" + ", source " + be.getSource() + ", bundle=" + be.getBundle() + ", type=" + be.getType()); | |
43 | ||
44 | } | |
45 | ||
46 | public void dumpAll() { | |
47 | for (int i = 0; i < eventList.size(); i++) { | |
48 | BundleEvent fe = (BundleEvent) eventList.get(i); | |
49 | dump(fe); | |
50 | } | |
51 | } | |
52 | ||
53 | boolean exists(String bundleName) { | |
54 | for (int i = 0; i < eventList.size(); i++) { | |
55 | BundleEvent fe = (BundleEvent) eventList.get(i); | |
56 | Bundle b = fe.getBundle(); | |
57 | System.out.println("===[" + b + "]"); | |
58 | if (bundleName.equals(b.getSymbolicName())) { | |
59 | return true; | |
60 | } | |
61 | } | |
62 | return false; | |
63 | } | |
64 | ||
65 | } |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.test_osgi; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.List; | |
28 | import java.util.Properties; | |
29 | ||
30 | import org.apache.felix.framework.Felix; | |
31 | import org.apache.felix.framework.util.FelixConstants; | |
32 | import org.apache.felix.framework.util.StringMap; | |
33 | import org.apache.felix.main.AutoProcessor; | |
34 | import org.osgi.framework.Bundle; | |
35 | import org.osgi.framework.BundleContext; | |
36 | import org.osgi.framework.BundleException; | |
37 | import org.osgi.framework.Constants; | |
38 | ||
39 | /** | |
40 | * Runs a hosted version of Felix for testing purposes. Any bundle errors are | |
41 | * reported via the FrameworkListener passed to the constructor. | |
42 | * | |
43 | * @author Ceki Gücü | |
44 | */ | |
45 | public class FelixHost { | |
46 | ||
47 | private Felix felix = null; | |
48 | ||
49 | Properties otherProps = new Properties(); | |
50 | ||
51 | final FrameworkErrorListener frameworkErrorListener; | |
52 | final CheckingBundleListener myBundleListener; | |
53 | ||
54 | public FelixHost(FrameworkErrorListener frameworkErrorListener, CheckingBundleListener myBundleListener) { | |
55 | this.frameworkErrorListener = frameworkErrorListener; | |
56 | this.myBundleListener = myBundleListener; | |
57 | } | |
58 | ||
59 | public void doLaunch() { | |
60 | // Create a case-insensitive configuration property map. | |
61 | StringMap configMap = new StringMap(false); | |
62 | // Configure the Felix instance to be embedded. | |
63 | // configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); | |
64 | // Add core OSGi packages to be exported from the class path | |
65 | // via the system bundle. | |
66 | configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0," | |
67 | + "org.osgi.service.startlevel; version=1.0.0," + "org.osgi.service.url; version=1.0.0"); | |
68 | ||
69 | configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); | |
70 | ||
71 | // Explicitly specify the directory to use for caching bundles. | |
72 | // configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache"); | |
73 | ||
74 | try { | |
75 | // Create host activator; | |
76 | ||
77 | List<Object> list = new ArrayList<Object>(); | |
78 | ||
79 | // list.add(new HostActivator()); | |
80 | configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.xml.sax, org.xml.sax.helpers, javax.xml.parsers, javax.naming"); | |
81 | configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list); | |
82 | configMap.put("felix.log.level", "4"); | |
83 | ||
84 | // Now create an instance of the framework with | |
85 | // our configuration properties and activator. | |
86 | felix = new Felix(configMap); | |
87 | felix.init(); | |
88 | ||
89 | // otherProps.put(Constants.FRAMEWORK_STORAGE, "bundles"); | |
90 | ||
91 | otherProps.put(AutoProcessor.AUTO_DEPLOY_DIR_PROPERY, AutoProcessor.AUTO_DEPLOY_DIR_VALUE); | |
92 | otherProps.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY, AutoProcessor.AUTO_DEPLOY_START_VALUE + "," + AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE); | |
93 | ||
94 | BundleContext felixBudleContext = felix.getBundleContext(); | |
95 | ||
96 | AutoProcessor.process(otherProps, felixBudleContext); | |
97 | // listen to errors | |
98 | felixBudleContext.addFrameworkListener(frameworkErrorListener); | |
99 | felixBudleContext.addBundleListener(myBundleListener); | |
100 | // Now start Felix instance. | |
101 | felix.start(); | |
102 | System.out.println("felix started"); | |
103 | ||
104 | } catch (Exception ex) { | |
105 | ex.printStackTrace(); | |
106 | } | |
107 | } | |
108 | ||
109 | public void stop() throws BundleException { | |
110 | felix.stop(); | |
111 | } | |
112 | ||
113 | public Bundle[] getInstalledBundles() { | |
114 | // Use the system bundle activator to gain external | |
115 | // access to the set of installed bundles. | |
116 | return null;// m_activator.getBundles(); | |
117 | } | |
118 | }⏎ |
0 | /** | |
1 | * Copyright (c) 2004-2011 QOS.ch | |
2 | * All rights reserved. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining | |
5 | * a copy of this software and associated documentation files (the | |
6 | * "Software"), to deal in the Software without restriction, including | |
7 | * without limitation the rights to use, copy, modify, merge, publish, | |
8 | * distribute, sublicense, and/or sell copies of the Software, and to | |
9 | * permit persons to whom the Software is furnished to do so, subject to | |
10 | * the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be | |
13 | * included in all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | */ | |
24 | package org.slf4j.test_osgi; | |
25 | ||
26 | import java.util.ArrayList; | |
27 | import java.util.List; | |
28 | ||
29 | import org.osgi.framework.FrameworkEvent; | |
30 | import org.osgi.framework.FrameworkListener; | |
31 | ||
32 | public class FrameworkErrorListener implements FrameworkListener { | |
33 | ||
34 | public List<FrameworkEvent> errorList = new ArrayList<FrameworkEvent>(); | |
35 | ||
36 | public void frameworkEvent(FrameworkEvent fe) { | |
37 | if (fe.getType() == FrameworkEvent.ERROR) { | |
38 | errorList.add(fe); | |
39 | ||
40 | } | |
41 | } | |
42 | ||
43 | private void dump(FrameworkEvent fe) { | |
44 | Throwable t = fe.getThrowable(); | |
45 | String tString = null; | |
46 | if (t != null) { | |
47 | tString = t.toString(); | |
48 | } | |
49 | System.out.println("Framework ERROR:" + ", source " + fe.getSource() + ", bundle=" + fe.getBundle() + ", ex=" + tString); | |
50 | if (t != null) { | |
51 | t.printStackTrace(); | |
52 | } | |
53 | } | |
54 | ||
55 | public void dumpAll() { | |
56 | for (int i = 0; i < errorList.size(); i++) { | |
57 | FrameworkEvent fe = (FrameworkEvent) errorList.get(i); | |
58 | dump(fe); | |
59 | } | |
60 | } | |
61 | } |
0 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
1 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
2 | ||
3 | <parent> | |
4 | <groupId>org.slf4j</groupId> | |
5 | <artifactId>slf4j-parent</artifactId> | |
6 | <version>1.7.12</version> | |
7 | </parent> | |
8 | ||
9 | <modelVersion>4.0.0</modelVersion> | |
10 | ||
11 | <artifactId>jcl-over-slf4j</artifactId> | |
12 | <packaging>jar</packaging> | |
13 | <name>JCL 1.1.1 implemented over SLF4J</name> | |
14 | <description>JCL 1.1.1 implemented over SLF4J</description> | |
15 | <url>http://www.slf4j.org</url> | |
16 | ||
17 | ||
18 | <dependencies> | |
19 | <!-- | |
20 | <dependency> | |
21 | <groupId>org.slf4j</groupId> | |
22 | <artifactId>slf4j-nop</artifactId> | |
23 | <version>${project.version}</version> | |
24 | <scope>provided</scope> | |
25 | </dependency> | |
26 | --> | |
27 | ||
28 | <dependency> | |
29 | <groupId>org.slf4j</groupId> | |
30 | <artifactId>slf4j-api</artifactId> | |
31 | </dependency> | |
32 | ||
33 | <dependency> | |
34 | <groupId>org.slf4j</groupId> | |
35 | <artifactId>slf4j-jdk14</artifactId> | |
36 | <scope>test</scope> | |
37 | </dependency> | |
38 | ||
39 | </dependencies> | |
40 | ||
41 | <build> | |
42 | <plugins> | |
43 | ||
44 | <plugin> | |
45 | <groupId>org.apache.maven.plugins</groupId> | |
46 | <artifactId>maven-jar-plugin</artifactId> | |
47 | <configuration> | |
48 | <archive> | |
49 | <manifestEntries> | |
50 | <Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version> | |
51 | <Bundle-Description>${project.description}</Bundle-Description> | |
52 | <Implementation-Version>${project.version}</Implementation-Version> | |
53 | </manifestEntries> | |
54 | <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> | |
55 | </archive> | |
56 | </configuration> | |
57 | </plugin> | |
58 | ||
59 | </plugins> | |
60 | ||
61 | ||
62 | </build> | |
63 | ||
64 | </project>⏎ |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging; | |
17 | ||
18 | /** | |
19 | * <p>A simple logging interface abstracting logging APIs. In order to be | |
20 | * instantiated successfully by {@link LogFactory}, classes that implement | |
21 | * this interface must have a constructor that takes a single String | |
22 | * parameter representing the "name" of this Log.</p> | |
23 | * | |
24 | * <p> The six logging levels used by <code>Log</code> are (in order): | |
25 | * <ol> | |
26 | * <li>trace (the least serious)</li> | |
27 | * <li>debug</li> | |
28 | * <li>info</li> | |
29 | * <li>warn</li> | |
30 | * <li>error</li> | |
31 | * <li>fatal (the most serious)</li> | |
32 | * </ol> | |
33 | * The mapping of these log levels to the concepts used by the underlying | |
34 | * logging system is implementation dependent. | |
35 | * The implementation should ensure, though, that this ordering behaves | |
36 | * as expected.</p> | |
37 | * | |
38 | * <p>Performance is often a logging concern. | |
39 | * By examining the appropriate property, | |
40 | * a component can avoid expensive operations (producing information | |
41 | * to be logged).</p> | |
42 | * | |
43 | * <p> For example, | |
44 | * <code><pre> | |
45 | * if (log.isDebugEnabled()) { | |
46 | * ... do something expensive ... | |
47 | * log.debug(theResult); | |
48 | * } | |
49 | * </pre></code> | |
50 | * </p> | |
51 | * | |
52 | * <p>Configuration of the underlying logging system will generally be done | |
53 | * external to the Logging APIs, through whatever mechanism is supported by | |
54 | * that system.</p> | |
55 | * | |
56 | * <p style="color: #E40; font-weight: bold;">Please note that this interface is identical to that found in JCL 1.1.1.</p> | |
57 | * | |
58 | * @author <a href="mailto:sanders@apache.org">Scott Sanders</a> | |
59 | * @author Rod Waldhoff | |
60 | * @version $Id: Log.java,v 1.19 2004/06/06 21:16:04 rdonkin Exp $ | |
61 | */ | |
62 | public interface Log { | |
63 | ||
64 | // ----------------------------------------------------- Logging Properties | |
65 | ||
66 | /** | |
67 | * <p> Is debug logging currently enabled? </p> | |
68 | * | |
69 | * <p> Call this method to prevent having to perform expensive operations | |
70 | * (for example, <code>String</code> concatenation) | |
71 | * when the log level is more than debug. </p> | |
72 | */ | |
73 | public boolean isDebugEnabled(); | |
74 | ||
75 | /** | |
76 | * <p> Is error logging currently enabled? </p> | |
77 | * | |
78 | * <p> Call this method to prevent having to perform expensive operations | |
79 | * (for example, <code>String</code> concatenation) | |
80 | * when the log level is more than error. </p> | |
81 | */ | |
82 | public boolean isErrorEnabled(); | |
83 | ||
84 | /** | |
85 | * <p> Is fatal logging currently enabled? </p> | |
86 | * | |
87 | * <p> Call this method to prevent having to perform expensive operations | |
88 | * (for example, <code>String</code> concatenation) | |
89 | * when the log level is more than fatal. </p> | |
90 | */ | |
91 | public boolean isFatalEnabled(); | |
92 | ||
93 | /** | |
94 | * <p> Is info logging currently enabled? </p> | |
95 | * | |
96 | * <p> Call this method to prevent having to perform expensive operations | |
97 | * (for example, <code>String</code> concatenation) | |
98 | * when the log level is more than info. </p> | |
99 | * | |
100 | * @return true if info enabled, false otherwise | |
101 | */ | |
102 | public boolean isInfoEnabled(); | |
103 | ||
104 | /** | |
105 | * <p> Is trace logging currently enabled? </p> | |
106 | * | |
107 | * <p> Call this method to prevent having to perform expensive operations | |
108 | * (for example, <code>String</code> concatenation) | |
109 | * when the log level is more than trace. </p> | |
110 | * | |
111 | * @return true if trace enabled, false otherwise | |
112 | */ | |
113 | public boolean isTraceEnabled(); | |
114 | ||
115 | /** | |
116 | * <p> Is warn logging currently enabled? </p> | |
117 | * | |
118 | * <p> Call this method to prevent having to perform expensive operations | |
119 | * (for example, <code>String</code> concatenation) | |
120 | * when the log level is more than warn. </p> | |
121 | */ | |
122 | public boolean isWarnEnabled(); | |
123 | ||
124 | // -------------------------------------------------------- Logging Methods | |
125 | ||
126 | /** | |
127 | * <p> Log a message with trace log level. </p> | |
128 | * | |
129 | * @param message log this message | |
130 | */ | |
131 | public void trace(Object message); | |
132 | ||
133 | /** | |
134 | * <p> Log an error with trace log level. </p> | |
135 | * | |
136 | * @param message log this message | |
137 | * @param t log this cause | |
138 | */ | |
139 | public void trace(Object message, Throwable t); | |
140 | ||
141 | /** | |
142 | * <p> Log a message with debug log level. </p> | |
143 | * | |
144 | * @param message log this message | |
145 | */ | |
146 | public void debug(Object message); | |
147 | ||
148 | /** | |
149 | * <p> Log an error with debug log level. </p> | |
150 | * | |
151 | * @param message log this message | |
152 | * @param t log this cause | |
153 | */ | |
154 | public void debug(Object message, Throwable t); | |
155 | ||
156 | /** | |
157 | * <p> Log a message with info log level. </p> | |
158 | * | |
159 | * @param message log this message | |
160 | */ | |
161 | public void info(Object message); | |
162 | ||
163 | /** | |
164 | * <p> Log an error with info log level. </p> | |
165 | * | |
166 | * @param message log this message | |
167 | * @param t log this cause | |
168 | */ | |
169 | public void info(Object message, Throwable t); | |
170 | ||
171 | /** | |
172 | * <p> Log a message with warn log level. </p> | |
173 | * | |
174 | * @param message log this message | |
175 | */ | |
176 | public void warn(Object message); | |
177 | ||
178 | /** | |
179 | * <p> Log an error with warn log level. </p> | |
180 | * | |
181 | * @param message log this message | |
182 | * @param t log this cause | |
183 | */ | |
184 | public void warn(Object message, Throwable t); | |
185 | ||
186 | /** | |
187 | * <p> Log a message with error log level. </p> | |
188 | * | |
189 | * @param message log this message | |
190 | */ | |
191 | public void error(Object message); | |
192 | ||
193 | /** | |
194 | * <p> Log an error with error log level. </p> | |
195 | * | |
196 | * @param message log this message | |
197 | * @param t log this cause | |
198 | */ | |
199 | public void error(Object message, Throwable t); | |
200 | ||
201 | /** | |
202 | * <p> Log a message with fatal log level. </p> | |
203 | * | |
204 | * @param message log this message | |
205 | */ | |
206 | public void fatal(Object message); | |
207 | ||
208 | /** | |
209 | * <p> Log an error with fatal log level. </p> | |
210 | * | |
211 | * @param message log this message | |
212 | * @param t log this cause | |
213 | */ | |
214 | public void fatal(Object message, Throwable t); | |
215 | ||
216 | } |
+93
-0
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging; | |
17 | ||
18 | /** | |
19 | * <p> | |
20 | * An exception that is thrown only if a suitable <code>LogFactory</code> or | |
21 | * <code>Log</code> instance cannot be created by the corresponding factory | |
22 | * methods. | |
23 | * </p> | |
24 | * | |
25 | * <p> | |
26 | * In this version of JCL, this exception will never be thrown in practice. | |
27 | * However, it is included here to ensure total compile time and run time | |
28 | * compatibility with the original JCL 1.0.4. | |
29 | * | |
30 | * @author Craig R. McClanahan | |
31 | */ | |
32 | ||
33 | public class LogConfigurationException extends RuntimeException { | |
34 | ||
35 | private static final long serialVersionUID = 8486587136871052495L; | |
36 | ||
37 | /** | |
38 | * Construct a new exception with <code>null</code> as its detail message. | |
39 | */ | |
40 | public LogConfigurationException() { | |
41 | super(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * Construct a new exception with the specified detail message. | |
46 | * | |
47 | * @param message | |
48 | * The detail message | |
49 | */ | |
50 | public LogConfigurationException(String message) { | |
51 | super(message); | |
52 | } | |
53 | ||
54 | /** | |
55 | * Construct a new exception with the specified cause and a derived detail | |
56 | * message. | |
57 | * | |
58 | * @param cause | |
59 | * The underlying cause | |
60 | */ | |
61 | public LogConfigurationException(Throwable cause) { | |
62 | ||
63 | this((cause == null) ? null : cause.toString(), cause); | |
64 | ||
65 | } | |
66 | ||
67 | /** | |
68 | * Construct a new exception with the specified detail message and cause. | |
69 | * | |
70 | * @param message | |
71 | * The detail message | |
72 | * @param cause | |
73 | * The underlying cause | |
74 | */ | |
75 | public LogConfigurationException(String message, Throwable cause) { | |
76 | super(message + " (Caused by " + cause + ")"); | |
77 | this.cause = cause; // Two-argument version requires JDK 1.4 or later | |
78 | } | |
79 | ||
80 | /** | |
81 | * The underlying cause of this exception. | |
82 | */ | |
83 | protected Throwable cause = null; | |
84 | ||
85 | /** | |
86 | * Return the underlying cause of this exception (if any). | |
87 | */ | |
88 | public Throwable getCause() { | |
89 | return (this.cause); | |
90 | } | |
91 | ||
92 | } |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging; | |
17 | ||
18 | import java.util.Hashtable; | |
19 | ||
20 | import org.apache.commons.logging.impl.SLF4JLogFactory; | |
21 | ||
22 | /** | |
23 | * <p> | |
24 | * Factory for creating {@link Log} instances, which always delegates to an | |
25 | * instance of {@link SLF4JLogFactory}. | |
26 | * | |
27 | * </p> | |
28 | * | |
29 | * @author Craig R. McClanahan | |
30 | * @author Costin Manolache | |
31 | * @author Richard A. Sitze | |
32 | * @author Ceki Gülcü | |
33 | */ | |
34 | ||
35 | @SuppressWarnings("rawtypes") | |
36 | public abstract class LogFactory { | |
37 | ||
38 | static String UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J = "http://www.slf4j.org/codes.html#unsupported_operation_in_jcl_over_slf4j"; | |
39 | ||
40 | static LogFactory logFactory = new SLF4JLogFactory(); | |
41 | ||
42 | /** | |
43 | * The name (<code>priority</code>) of the key in the config file used to | |
44 | * specify the priority of that particular config file. The associated value | |
45 | * is a floating-point number; higher values take priority over lower values. | |
46 | * | |
47 | * <p> | |
48 | * This property is not used but preserved here for compatibility. | |
49 | */ | |
50 | public static final String PRIORITY_KEY = "priority"; | |
51 | ||
52 | /** | |
53 | * The name (<code>use_tccl</code>) of the key in the config file used to | |
54 | * specify whether logging classes should be loaded via the thread context | |
55 | * class loader (TCCL), or not. By default, the TCCL is used. | |
56 | * | |
57 | * <p> | |
58 | * This property is not used but preserved here for compatibility. | |
59 | */ | |
60 | public static final String TCCL_KEY = "use_tccl"; | |
61 | ||
62 | /** | |
63 | * The name of the property used to identify the LogFactory implementation | |
64 | * class name. | |
65 | * <p> | |
66 | * This property is not used but preserved here for compatibility. | |
67 | */ | |
68 | public static final String FACTORY_PROPERTY = "org.apache.commons.logging.LogFactory"; | |
69 | ||
70 | /** | |
71 | * The fully qualified class name of the fallback <code>LogFactory</code> | |
72 | * implementation class to use, if no other can be found. | |
73 | * | |
74 | * <p> | |
75 | * This property is not used but preserved here for compatibility. | |
76 | */ | |
77 | public static final String FACTORY_DEFAULT = "org.apache.commons.logging.impl.SLF4JLogFactory"; | |
78 | ||
79 | /** | |
80 | * The name of the properties file to search for. | |
81 | * <p> | |
82 | * This property is not used but preserved here for compatibility. | |
83 | */ | |
84 | public static final String FACTORY_PROPERTIES = "commons-logging.properties"; | |
85 | ||
86 | /** | |
87 | * JDK1.3+ <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider"> | |
88 | * 'Service Provider' specification</a>. | |
89 | * <p> | |
90 | * This property is not used but preserved here for compatibility. | |
91 | */ | |
92 | protected static final String SERVICE_ID = "META-INF/services/org.apache.commons.logging.LogFactory"; | |
93 | ||
94 | /** | |
95 | * The name (<code>org.apache.commons.logging.diagnostics.dest</code>) of | |
96 | * the property used to enable internal commons-logging diagnostic output, in | |
97 | * order to get information on what logging implementations are being | |
98 | * discovered, what classloaders they are loaded through, etc. | |
99 | * | |
100 | * <p> | |
101 | * This property is not used but preserved here for compatibility. | |
102 | */ | |
103 | public static final String DIAGNOSTICS_DEST_PROPERTY = "org.apache.commons.logging.diagnostics.dest"; | |
104 | ||
105 | /** | |
106 | * <p> | |
107 | * Setting this system property value allows the <code>Hashtable</code> used | |
108 | * to store classloaders to be substituted by an alternative implementation. | |
109 | * <p> | |
110 | * This property is not used but preserved here for compatibility. | |
111 | */ | |
112 | public static final String HASHTABLE_IMPLEMENTATION_PROPERTY = "org.apache.commons.logging.LogFactory.HashtableImpl"; | |
113 | ||
114 | /** | |
115 | * The previously constructed <code>LogFactory</code> instances, keyed by | |
116 | * the <code>ClassLoader</code> with which it was created. | |
117 | * | |
118 | * <p> | |
119 | * This property is not used but preserved here for compatibility. | |
120 | */ | |
121 | protected static Hashtable factories = null; | |
122 | ||
123 | /** | |
124 | * <p> | |
125 | * This property is not used but preserved here for compatibility. | |
126 | */ | |
127 | protected static LogFactory nullClassLoaderFactory = null; | |
128 | ||
129 | /** | |
130 | * Protected constructor that is not available for public use. | |
131 | */ | |
132 | protected LogFactory() { | |
133 | } | |
134 | ||
135 | // --------------------------------------------------------- Public Methods | |
136 | ||
137 | /** | |
138 | * Return the configuration attribute with the specified name (if any), or | |
139 | * <code>null</code> if there is no such attribute. | |
140 | * | |
141 | * @param name Name of the attribute to return | |
142 | * @return configuration attribute | |
143 | */ | |
144 | public abstract Object getAttribute(String name); | |
145 | ||
146 | /** | |
147 | * Return an array containing the names of all currently defined configuration | |
148 | * attributes. If there are no such attributes, a zero length array is | |
149 | * returned. | |
150 | * | |
151 | * @return names of all currently defined configuration attributes | |
152 | */ | |
153 | public abstract String[] getAttributeNames(); | |
154 | ||
155 | /** | |
156 | * Convenience method to derive a name from the specified class and call | |
157 | * <code>getInstance(String)</code> with it. | |
158 | * | |
159 | * @param clazz | |
160 | * Class for which a suitable Log name will be derived | |
161 | * | |
162 | * @exception LogConfigurationException | |
163 | * if a suitable <code>Log</code> instance cannot be | |
164 | * returned | |
165 | */ | |
166 | public abstract Log getInstance(Class clazz) throws LogConfigurationException; | |
167 | ||
168 | /** | |
169 | * <p> | |
170 | * Construct (if necessary) and return a <code>Log</code> instance, using | |
171 | * the factory's current set of configuration attributes. | |
172 | * </p> | |
173 | * | |
174 | * <p> | |
175 | * <strong>NOTE </strong>- Depending upon the implementation of the | |
176 | * <code>LogFactory</code> you are using, the <code>Log</code> instance | |
177 | * you are returned may or may not be local to the current application, and | |
178 | * may or may not be returned again on a subsequent call with the same name | |
179 | * argument. | |
180 | * </p> | |
181 | * | |
182 | * @param name | |
183 | * Logical name of the <code>Log</code> instance to be | |
184 | * returned (the meaning of this name is only known to the | |
185 | * underlying logging implementation that is being wrapped) | |
186 | * | |
187 | * @exception LogConfigurationException | |
188 | * if a suitable <code>Log</code> instance cannot be | |
189 | * returned | |
190 | */ | |
191 | public abstract Log getInstance(String name) throws LogConfigurationException; | |
192 | ||
193 | /** | |
194 | * Release any internal references to previously created {@link Log}instances | |
195 | * returned by this factory. This is useful in environments like servlet | |
196 | * containers, which implement application reloading by throwing away a | |
197 | * ClassLoader. Dangling references to objects in that class loader would | |
198 | * prevent garbage collection. | |
199 | */ | |
200 | public abstract void release(); | |
201 | ||
202 | /** | |
203 | * Remove any configuration attribute associated with the specified name. If | |
204 | * there is no such attribute, no action is taken. | |
205 | * | |
206 | * @param name | |
207 | * Name of the attribute to remove | |
208 | */ | |
209 | public abstract void removeAttribute(String name); | |
210 | ||
211 | /** | |
212 | * Set the configuration attribute with the specified name. Calling this with | |
213 | * a <code>null</code> value is equivalent to calling | |
214 | * <code>removeAttribute(name)</code>. | |
215 | * | |
216 | * @param name | |
217 | * Name of the attribute to set | |
218 | * @param value | |
219 | * Value of the attribute to set, or <code>null</code> to | |
220 | * remove any setting for this attribute | |
221 | */ | |
222 | public abstract void setAttribute(String name, Object value); | |
223 | ||
224 | // --------------------------------------------------------- Static Methods | |
225 | ||
226 | /** | |
227 | * <p> | |
228 | * Construct (if necessary) and return a <code>LogFactory</code> instance, | |
229 | * using the following ordered lookup procedure to determine the name of the | |
230 | * implementation class to be loaded. | |
231 | * </p> | |
232 | * <ul> | |
233 | * <li>The <code>org.apache.commons.logging.LogFactory</code> system | |
234 | * property.</li> | |
235 | * <li>The JDK 1.3 Service Discovery mechanism</li> | |
236 | * <li>Use the properties file <code>commons-logging.properties</code> | |
237 | * file, if found in the class path of this class. The configuration file is | |
238 | * in standard <code>java.util.Properties</code> format and contains the | |
239 | * fully qualified name of the implementation class with the key being the | |
240 | * system property defined above.</li> | |
241 | * <li>Fall back to a default implementation class ( | |
242 | * <code>org.apache.commons.logging.impl.SLF4FLogFactory</code>).</li> | |
243 | * </ul> | |
244 | * | |
245 | * <p> | |
246 | * <em>NOTE</em>- If the properties file method of identifying the | |
247 | * <code>LogFactory</code> implementation class is utilized, all of the | |
248 | * properties defined in this file will be set as configuration attributes on | |
249 | * the corresponding <code>LogFactory</code> instance. | |
250 | * </p> | |
251 | * | |
252 | * @exception LogConfigurationException | |
253 | * if the implementation class is not available or cannot | |
254 | * be instantiated. | |
255 | */ | |
256 | public static LogFactory getFactory() throws LogConfigurationException { | |
257 | return logFactory; | |
258 | } | |
259 | ||
260 | /** | |
261 | * Convenience method to return a named logger, without the application having | |
262 | * to care about factories. | |
263 | * | |
264 | * @param clazz | |
265 | * Class from which a log name will be derived | |
266 | * | |
267 | * @exception LogConfigurationException | |
268 | * if a suitable <code>Log</code> instance cannot be | |
269 | * returned | |
270 | */ | |
271 | public static Log getLog(Class clazz) throws LogConfigurationException { | |
272 | return (getFactory().getInstance(clazz)); | |
273 | } | |
274 | ||
275 | /** | |
276 | * Convenience method to return a named logger, without the application having | |
277 | * to care about factories. | |
278 | * | |
279 | * @param name | |
280 | * Logical name of the <code>Log</code> instance to be | |
281 | * returned (the meaning of this name is only known to the | |
282 | * underlying logging implementation that is being wrapped) | |
283 | * | |
284 | * @exception LogConfigurationException | |
285 | * if a suitable <code>Log</code> instance cannot be | |
286 | * returned | |
287 | */ | |
288 | public static Log getLog(String name) throws LogConfigurationException { | |
289 | return (getFactory().getInstance(name)); | |
290 | } | |
291 | ||
292 | /** | |
293 | * Release any internal references to previously created {@link LogFactory} | |
294 | * instances that have been associated with the specified class loader (if | |
295 | * any), after calling the instance method <code>release()</code> on each of | |
296 | * them. | |
297 | * | |
298 | * @param classLoader | |
299 | * ClassLoader for which to release the LogFactory | |
300 | */ | |
301 | public static void release(ClassLoader classLoader) { | |
302 | // since SLF4J based JCL does not make use of classloaders, there is nothing | |
303 | // to do here | |
304 | } | |
305 | ||
306 | /** | |
307 | * Release any internal references to previously created {@link LogFactory} | |
308 | * instances, after calling the instance method <code>release()</code> on | |
309 | * each of them. This is useful in environments like servlet containers, which | |
310 | * implement application reloading by throwing away a ClassLoader. Dangling | |
311 | * references to objects in that class loader would prevent garbage | |
312 | * collection. | |
313 | */ | |
314 | public static void releaseAll() { | |
315 | // since SLF4J based JCL does not make use of classloaders, there is nothing | |
316 | // to do here | |
317 | } | |
318 | ||
319 | /** | |
320 | * Returns a string that uniquely identifies the specified object, including | |
321 | * its class. | |
322 | * <p> | |
323 | * The returned string is of form "classname@hashcode", ie is the same as the | |
324 | * return value of the Object.toString() method, but works even when the | |
325 | * specified object's class has overidden the toString method. | |
326 | * | |
327 | * @param o | |
328 | * may be null. | |
329 | * @return a string of form classname@hashcode, or "null" if param o is null. | |
330 | * @since 1.1 | |
331 | */ | |
332 | public static String objectId(Object o) { | |
333 | if (o == null) { | |
334 | return "null"; | |
335 | } else { | |
336 | return o.getClass().getName() + "@" + System.identityHashCode(o); | |
337 | } | |
338 | } | |
339 | ||
340 | // protected methods which were added in JCL 1.1. These are not used | |
341 | // by SLF4JLogFactory | |
342 | ||
343 | /** | |
344 | * This method exists to ensure signature compatibility. | |
345 | */ | |
346 | protected static Object createFactory(String factoryClass, ClassLoader classLoader) { | |
347 | throw new UnsupportedOperationException("Operation [factoryClass] is not supported in jcl-over-slf4j. See also " | |
348 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
349 | } | |
350 | ||
351 | /** | |
352 | * This method exists to ensure signature compatibility. | |
353 | */ | |
354 | protected static ClassLoader directGetContextClassLoader() { | |
355 | throw new UnsupportedOperationException("Operation [directGetContextClassLoader] is not supported in jcl-over-slf4j. See also " | |
356 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
357 | } | |
358 | ||
359 | /** | |
360 | * This method exists to ensure signature compatibility. | |
361 | */ | |
362 | protected static ClassLoader getContextClassLoader() throws LogConfigurationException { | |
363 | throw new UnsupportedOperationException("Operation [getContextClassLoader] is not supported in jcl-over-slf4j. See also " | |
364 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
365 | } | |
366 | ||
367 | /** | |
368 | * This method exists to ensure signature compatibility. | |
369 | */ | |
370 | protected static ClassLoader getClassLoader(Class clazz) { | |
371 | throw new UnsupportedOperationException("Operation [getClassLoader] is not supported in jcl-over-slf4j. See also " | |
372 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
373 | } | |
374 | ||
375 | /** | |
376 | * This method exists to ensure signature compatibility. | |
377 | */ | |
378 | protected static boolean isDiagnosticsEnabled() { | |
379 | throw new UnsupportedOperationException("Operation [isDiagnosticsEnabled] is not supported in jcl-over-slf4j. See also " | |
380 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
381 | } | |
382 | ||
383 | /** | |
384 | * This method exists to ensure signature compatibility. | |
385 | */ | |
386 | protected static void logRawDiagnostic(String msg) { | |
387 | throw new UnsupportedOperationException("Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also " | |
388 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
389 | } | |
390 | ||
391 | /** | |
392 | * This method exists to ensure signature compatibility. | |
393 | */ | |
394 | protected static LogFactory newFactory(final String factoryClass, final ClassLoader classLoader, final ClassLoader contextClassLoader) { | |
395 | throw new UnsupportedOperationException("Operation [logRawDiagnostic] is not supported in jcl-over-slf4j. See also " | |
396 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
397 | } | |
398 | ||
399 | /** | |
400 | * This method exists to ensure signature compatibility. | |
401 | */ | |
402 | protected static LogFactory newFactory(final String factoryClass, final ClassLoader classLoader) { | |
403 | throw new UnsupportedOperationException("Operation [newFactory] is not supported in jcl-over-slf4j. See also " | |
404 | + UNSUPPORTED_OPERATION_IN_JCL_OVER_SLF4J); | |
405 | } | |
406 | ||
407 | }⏎ |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging.impl; | |
17 | ||
18 | import java.io.Serializable; | |
19 | import org.apache.commons.logging.Log; | |
20 | ||
21 | /** | |
22 | * <p> | |
23 | * Trivial implementation of Log that throws away all messages. No configurable | |
24 | * system properties are supported. | |
25 | * </p> | |
26 | * | |
27 | * @author <a href="mailto:sanders@apache.org">Scott Sanders</a> | |
28 | * @author Rod Waldhoff | |
29 | * @version $Id: NoOpLog.java,v 1.8 2004/06/06 21:13:12 rdonkin Exp $ | |
30 | */ | |
31 | public class NoOpLog implements Log, Serializable { | |
32 | private static final long serialVersionUID = 561423906191706148L; | |
33 | ||
34 | /** Convenience constructor */ | |
35 | public NoOpLog() { | |
36 | } | |
37 | ||
38 | /** Base constructor */ | |
39 | public NoOpLog(String name) { | |
40 | } | |
41 | ||
42 | /** Do nothing */ | |
43 | public void trace(Object message) { | |
44 | } | |
45 | ||
46 | /** Do nothing */ | |
47 | public void trace(Object message, Throwable t) { | |
48 | } | |
49 | ||
50 | /** Do nothing */ | |
51 | public void debug(Object message) { | |
52 | } | |
53 | ||
54 | /** Do nothing */ | |
55 | public void debug(Object message, Throwable t) { | |
56 | } | |
57 | ||
58 | /** Do nothing */ | |
59 | public void info(Object message) { | |
60 | } | |
61 | ||
62 | /** Do nothing */ | |
63 | public void info(Object message, Throwable t) { | |
64 | } | |
65 | ||
66 | /** Do nothing */ | |
67 | public void warn(Object message) { | |
68 | } | |
69 | ||
70 | /** Do nothing */ | |
71 | public void warn(Object message, Throwable t) { | |
72 | } | |
73 | ||
74 | /** Do nothing */ | |
75 | public void error(Object message) { | |
76 | } | |
77 | ||
78 | /** Do nothing */ | |
79 | public void error(Object message, Throwable t) { | |
80 | } | |
81 | ||
82 | /** Do nothing */ | |
83 | public void fatal(Object message) { | |
84 | } | |
85 | ||
86 | /** Do nothing */ | |
87 | public void fatal(Object message, Throwable t) { | |
88 | } | |
89 | ||
90 | /** | |
91 | * Debug is never enabled. | |
92 | * | |
93 | * @return false | |
94 | */ | |
95 | public final boolean isDebugEnabled() { | |
96 | return false; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Error is never enabled. | |
101 | * | |
102 | * @return false | |
103 | */ | |
104 | public final boolean isErrorEnabled() { | |
105 | return false; | |
106 | } | |
107 | ||
108 | /** | |
109 | * Fatal is never enabled. | |
110 | * | |
111 | * @return false | |
112 | */ | |
113 | public final boolean isFatalEnabled() { | |
114 | return false; | |
115 | } | |
116 | ||
117 | /** | |
118 | * Info is never enabled. | |
119 | * | |
120 | * @return false | |
121 | */ | |
122 | public final boolean isInfoEnabled() { | |
123 | return false; | |
124 | } | |
125 | ||
126 | /** | |
127 | * Trace is never enabled. | |
128 | * | |
129 | * @return false | |
130 | */ | |
131 | public final boolean isTraceEnabled() { | |
132 | return false; | |
133 | } | |
134 | ||
135 | /** | |
136 | * Warn is never enabled. | |
137 | * | |
138 | * @return false | |
139 | */ | |
140 | public final boolean isWarnEnabled() { | |
141 | return false; | |
142 | } | |
143 | ||
144 | } |
+254
-0
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging.impl; | |
17 | ||
18 | import java.io.ObjectStreamException; | |
19 | import java.io.Serializable; | |
20 | ||
21 | import org.apache.commons.logging.Log; | |
22 | import org.slf4j.Logger; | |
23 | import org.slf4j.LoggerFactory; | |
24 | import org.slf4j.spi.LocationAwareLogger; | |
25 | ||
26 | /** | |
27 | * Implementation of {@link Log org.apache.commons.logging.Log} interface which | |
28 | * delegates all processing to a wrapped {@link Logger org.slf4j.Logger} | |
29 | * instance. | |
30 | * | |
31 | * <p> | |
32 | * JCL's FATAL level is mapped to ERROR. All other levels map one to one. | |
33 | * | |
34 | * @author Ceki Gülcü | |
35 | */ | |
36 | public class SLF4JLocationAwareLog implements Log, Serializable { | |
37 | ||
38 | private static final long serialVersionUID = -2379157579039314822L; | |
39 | ||
40 | // used to store this logger's name to recreate it after serialization | |
41 | protected String name; | |
42 | ||
43 | // in both Log4jLogger and Jdk14Logger classes in the original JCL, the | |
44 | // logger instance is transient | |
45 | private transient LocationAwareLogger logger; | |
46 | ||
47 | private static final String FQCN = SLF4JLocationAwareLog.class.getName(); | |
48 | ||
49 | SLF4JLocationAwareLog(LocationAwareLogger logger) { | |
50 | this.logger = logger; | |
51 | this.name = logger.getName(); | |
52 | } | |
53 | ||
54 | /** | |
55 | * Delegates to the <code>isTraceEnabled<code> method of the wrapped | |
56 | * <code>org.slf4j.Logger</code> instance. | |
57 | */ | |
58 | public boolean isTraceEnabled() { | |
59 | return logger.isTraceEnabled(); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
64 | */ | |
65 | public boolean isDebugEnabled() { | |
66 | return logger.isDebugEnabled(); | |
67 | } | |
68 | ||
69 | /** | |
70 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
71 | */ | |
72 | public boolean isInfoEnabled() { | |
73 | return logger.isInfoEnabled(); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
78 | */ | |
79 | public boolean isWarnEnabled() { | |
80 | return logger.isWarnEnabled(); | |
81 | } | |
82 | ||
83 | /** | |
84 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
85 | */ | |
86 | public boolean isErrorEnabled() { | |
87 | return logger.isErrorEnabled(); | |
88 | } | |
89 | ||
90 | /** | |
91 | * Delegates to the <code>isErrorEnabled<code> method of the wrapped | |
92 | * <code>org.slf4j.Logger</code> instance. | |
93 | */ | |
94 | public boolean isFatalEnabled() { | |
95 | return logger.isErrorEnabled(); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Converts the input parameter to String and then delegates to the debug | |
100 | * method of the wrapped <code>org.slf4j.Logger</code> instance. | |
101 | * | |
102 | * @param message | |
103 | * the message to log. Converted to {@link String} | |
104 | */ | |
105 | public void trace(Object message) { | |
106 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, null); | |
107 | } | |
108 | ||
109 | /** | |
110 | * Converts the first input parameter to String and then delegates to the | |
111 | * debug method of the wrapped <code>org.slf4j.Logger</code> instance. | |
112 | * | |
113 | * @param message | |
114 | * the message to log. Converted to {@link String} | |
115 | * @param t | |
116 | * the exception to log | |
117 | */ | |
118 | public void trace(Object message, Throwable t) { | |
119 | logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String.valueOf(message), null, t); | |
120 | } | |
121 | ||
122 | /** | |
123 | * Converts the input parameter to String and then delegates to the wrapped | |
124 | * <code>org.slf4j.Logger</code> instance. | |
125 | * | |
126 | * @param message | |
127 | * the message to log. Converted to {@link String} | |
128 | */ | |
129 | public void debug(Object message) { | |
130 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, null); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Converts the first input parameter to String and then delegates to the | |
135 | * wrapped <code>org.slf4j.Logger</code> instance. | |
136 | * | |
137 | * @param message | |
138 | * the message to log. Converted to {@link String} | |
139 | * @param t | |
140 | * the exception to log | |
141 | */ | |
142 | public void debug(Object message, Throwable t) { | |
143 | logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String.valueOf(message), null, t); | |
144 | } | |
145 | ||
146 | /** | |
147 | * Converts the input parameter to String and then delegates to the wrapped | |
148 | * <code>org.slf4j.Logger</code> instance. | |
149 | * | |
150 | * @param message | |
151 | * the message to log. Converted to {@link String} | |
152 | */ | |
153 | public void info(Object message) { | |
154 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, null); | |
155 | } | |
156 | ||
157 | /** | |
158 | * Converts the first input parameter to String and then delegates to the | |
159 | * wrapped <code>org.slf4j.Logger</code> instance. | |
160 | * | |
161 | * @param message | |
162 | * the message to log. Converted to {@link String} | |
163 | * @param t | |
164 | * the exception to log | |
165 | */ | |
166 | public void info(Object message, Throwable t) { | |
167 | logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String.valueOf(message), null, t); | |
168 | } | |
169 | ||
170 | /** | |
171 | * Converts the input parameter to String and then delegates to the wrapped | |
172 | * <code>org.slf4j.Logger</code> instance. | |
173 | * | |
174 | * @param message | |
175 | * the message to log. Converted to {@link String} | |
176 | */ | |
177 | public void warn(Object message) { | |
178 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, null); | |
179 | } | |
180 | ||
181 | /** | |
182 | * Converts the first input parameter to String and then delegates to the | |
183 | * wrapped <code>org.slf4j.Logger</code> instance. | |
184 | * | |
185 | * @param message | |
186 | * the message to log. Converted to {@link String} | |
187 | * @param t | |
188 | * the exception to log | |
189 | */ | |
190 | public void warn(Object message, Throwable t) { | |
191 | logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String.valueOf(message), null, t); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Converts the input parameter to String and then delegates to the wrapped | |
196 | * <code>org.slf4j.Logger</code> instance. | |
197 | * | |
198 | * @param message | |
199 | * the message to log. Converted to {@link String} | |
200 | */ | |
201 | public void error(Object message) { | |
202 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
203 | } | |
204 | ||
205 | /** | |
206 | * Converts the first input parameter to String and then delegates to the | |
207 | * wrapped <code>org.slf4j.Logger</code> instance. | |
208 | * | |
209 | * @param message | |
210 | * the message to log. Converted to {@link String} | |
211 | * @param t | |
212 | * the exception to log | |
213 | */ | |
214 | public void error(Object message, Throwable t) { | |
215 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
216 | } | |
217 | ||
218 | /** | |
219 | * Converts the input parameter to String and then delegates to the error | |
220 | * method of the wrapped <code>org.slf4j.Logger</code> instance. | |
221 | * | |
222 | * @param message | |
223 | * the message to log. Converted to {@link String} | |
224 | */ | |
225 | public void fatal(Object message) { | |
226 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, null); | |
227 | } | |
228 | ||
229 | /** | |
230 | * Converts the first input parameter to String and then delegates to the | |
231 | * error method of the wrapped <code>org.slf4j.Logger</code> instance. | |
232 | * | |
233 | * @param message | |
234 | * the message to log. Converted to {@link String} | |
235 | * @param t | |
236 | * the exception to log | |
237 | */ | |
238 | public void fatal(Object message, Throwable t) { | |
239 | logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String.valueOf(message), null, t); | |
240 | } | |
241 | ||
242 | /** | |
243 | * Replace this instance with a homonymous (same name) logger returned by | |
244 | * LoggerFactory. Note that this method is only called during deserialization. | |
245 | * | |
246 | * @return logger with same name as returned by LoggerFactory | |
247 | * @throws ObjectStreamException | |
248 | */ | |
249 | protected Object readResolve() throws ObjectStreamException { | |
250 | Logger logger = LoggerFactory.getLogger(this.name); | |
251 | return new SLF4JLocationAwareLog((LocationAwareLogger) logger); | |
252 | } | |
253 | }⏎ |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging.impl; | |
17 | ||
18 | import java.io.ObjectStreamException; | |
19 | import java.io.Serializable; | |
20 | ||
21 | import org.apache.commons.logging.Log; | |
22 | import org.slf4j.Logger; | |
23 | import org.slf4j.LoggerFactory; | |
24 | ||
25 | /** | |
26 | * Implementation of {@link Log org.apache.commons.logging.Log} interface which | |
27 | * delegates all processing to a wrapped {@link Logger org.slf4j.Logger} | |
28 | * instance. | |
29 | * | |
30 | * <p> | |
31 | * JCL's FATAL level is mapped to ERROR. All other levels map one to one. | |
32 | * | |
33 | * @author Ceki Gülcü | |
34 | */ | |
35 | public class SLF4JLog implements Log, Serializable { | |
36 | ||
37 | private static final long serialVersionUID = 680728617011167209L; | |
38 | ||
39 | // used to store this logger's name to recreate it after serialization | |
40 | protected String name; | |
41 | ||
42 | // in both Log4jLogger and Jdk14Logger classes in the original JCL, the | |
43 | // logger instance is transient | |
44 | private transient Logger logger; | |
45 | ||
46 | SLF4JLog(Logger logger) { | |
47 | this.logger = logger; | |
48 | this.name = logger.getName(); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
53 | */ | |
54 | public boolean isDebugEnabled() { | |
55 | return logger.isDebugEnabled(); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
60 | */ | |
61 | public boolean isErrorEnabled() { | |
62 | return logger.isErrorEnabled(); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Delegates to the <code>isErrorEnabled<code> method of the wrapped | |
67 | * <code>org.slf4j.Logger</code> instance. | |
68 | */ | |
69 | public boolean isFatalEnabled() { | |
70 | return logger.isErrorEnabled(); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
75 | */ | |
76 | public boolean isInfoEnabled() { | |
77 | return logger.isInfoEnabled(); | |
78 | } | |
79 | ||
80 | /** | |
81 | * Delegates to the <code>isDebugEnabled<code> method of the wrapped | |
82 | * <code>org.slf4j.Logger</code> instance. | |
83 | */ | |
84 | public boolean isTraceEnabled() { | |
85 | return logger.isTraceEnabled(); | |
86 | } | |
87 | ||
88 | /** | |
89 | * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance. | |
90 | */ | |
91 | public boolean isWarnEnabled() { | |
92 | return logger.isWarnEnabled(); | |
93 | } | |
94 | ||
95 | /** | |
96 | * Converts the input parameter to String and then delegates to the debug | |
97 | * method of the wrapped <code>org.slf4j.Logger</code> instance. | |
98 | * | |
99 | * @param message | |
100 | * the message to log. Converted to {@link String} | |
101 | */ | |
102 | public void trace(Object message) { | |
103 | logger.trace(String.valueOf(message)); | |
104 | } | |
105 | ||
106 | /** | |
107 | * Converts the first input parameter to String and then delegates to the | |
108 | * debug method of the wrapped <code>org.slf4j.Logger</code> instance. | |
109 | * | |
110 | * @param message | |
111 | * the message to log. Converted to {@link String} | |
112 | * @param t | |
113 | * the exception to log | |
114 | */ | |
115 | public void trace(Object message, Throwable t) { | |
116 | logger.trace(String.valueOf(message), t); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Converts the input parameter to String and then delegates to the wrapped | |
121 | * <code>org.slf4j.Logger</code> instance. | |
122 | * | |
123 | * @param message | |
124 | * the message to log. Converted to {@link String} | |
125 | */ | |
126 | public void debug(Object message) { | |
127 | logger.debug(String.valueOf(message)); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Converts the first input parameter to String and then delegates to the | |
132 | * wrapped <code>org.slf4j.Logger</code> instance. | |
133 | * | |
134 | * @param message | |
135 | * the message to log. Converted to {@link String} | |
136 | * @param t | |
137 | * the exception to log | |
138 | */ | |
139 | public void debug(Object message, Throwable t) { | |
140 | logger.debug(String.valueOf(message), t); | |
141 | } | |
142 | ||
143 | /** | |
144 | * Converts the input parameter to String and then delegates to the wrapped | |
145 | * <code>org.slf4j.Logger</code> instance. | |
146 | * | |
147 | * @param message | |
148 | * the message to log. Converted to {@link String} | |
149 | */ | |
150 | public void info(Object message) { | |
151 | logger.info(String.valueOf(message)); | |
152 | } | |
153 | ||
154 | /** | |
155 | * Converts the first input parameter to String and then delegates to the | |
156 | * wrapped <code>org.slf4j.Logger</code> instance. | |
157 | * | |
158 | * @param message | |
159 | * the message to log. Converted to {@link String} | |
160 | * @param t | |
161 | * the exception to log | |
162 | */ | |
163 | public void info(Object message, Throwable t) { | |
164 | logger.info(String.valueOf(message), t); | |
165 | } | |
166 | ||
167 | /** | |
168 | * Converts the input parameter to String and then delegates to the wrapped | |
169 | * <code>org.slf4j.Logger</code> instance. | |
170 | * | |
171 | * @param message | |
172 | * the message to log. Converted to {@link String} | |
173 | */ | |
174 | public void warn(Object message) { | |
175 | logger.warn(String.valueOf(message)); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Converts the first input parameter to String and then delegates to the | |
180 | * wrapped <code>org.slf4j.Logger</code> instance. | |
181 | * | |
182 | * @param message | |
183 | * the message to log. Converted to {@link String} | |
184 | * @param t | |
185 | * the exception to log | |
186 | */ | |
187 | public void warn(Object message, Throwable t) { | |
188 | logger.warn(String.valueOf(message), t); | |
189 | } | |
190 | ||
191 | /** | |
192 | * Converts the input parameter to String and then delegates to the wrapped | |
193 | * <code>org.slf4j.Logger</code> instance. | |
194 | * | |
195 | * @param message | |
196 | * the message to log. Converted to {@link String} | |
197 | */ | |
198 | public void error(Object message) { | |
199 | logger.error(String.valueOf(message)); | |
200 | } | |
201 | ||
202 | /** | |
203 | * Converts the first input parameter to String and then delegates to the | |
204 | * wrapped <code>org.slf4j.Logger</code> instance. | |
205 | * | |
206 | * @param message | |
207 | * the message to log. Converted to {@link String} | |
208 | * @param t | |
209 | * the exception to log | |
210 | */ | |
211 | public void error(Object message, Throwable t) { | |
212 | logger.error(String.valueOf(message), t); | |
213 | } | |
214 | ||
215 | /** | |
216 | * Converts the input parameter to String and then delegates to the error | |
217 | * method of the wrapped <code>org.slf4j.Logger</code> instance. | |
218 | * | |
219 | * @param message | |
220 | * the message to log. Converted to {@link String} | |
221 | */ | |
222 | public void fatal(Object message) { | |
223 | logger.error(String.valueOf(message)); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Converts the first input parameter to String and then delegates to the | |
228 | * error method of the wrapped <code>org.slf4j.Logger</code> instance. | |
229 | * | |
230 | * @param message | |
231 | * the message to log. Converted to {@link String} | |
232 | * @param t | |
233 | * the exception to log | |
234 | */ | |
235 | public void fatal(Object message, Throwable t) { | |
236 | logger.error(String.valueOf(message), t); | |
237 | } | |
238 | ||
239 | /** | |
240 | * Replace this instance with a homonymous (same name) logger returned by | |
241 | * LoggerFactory. Note that this method is only called during deserialization. | |
242 | * | |
243 | * @return logger with same name as returned by LoggerFactory | |
244 | * @throws ObjectStreamException | |
245 | */ | |
246 | protected Object readResolve() throws ObjectStreamException { | |
247 | Logger logger = LoggerFactory.getLogger(this.name); | |
248 | return new SLF4JLog(logger); | |
249 | } | |
250 | }⏎ |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging.impl; | |
17 | ||
18 | import org.apache.commons.logging.Log; | |
19 | import org.apache.commons.logging.LogConfigurationException; | |
20 | import org.apache.commons.logging.LogFactory; | |
21 | import org.slf4j.Logger; | |
22 | import org.slf4j.LoggerFactory; | |
23 | import org.slf4j.spi.LocationAwareLogger; | |
24 | ||
25 | import java.util.ArrayList; | |
26 | import java.util.Enumeration; | |
27 | import java.util.Hashtable; | |
28 | import java.util.List; | |
29 | import java.util.concurrent.ConcurrentHashMap; | |
30 | import java.util.concurrent.ConcurrentMap; | |
31 | ||
32 | /** | |
33 | * <p> | |
34 | * Concrete subclass of {@link LogFactory} which always delegates to the | |
35 | * {@link LoggerFactory org.slf4j.LoggerFactory} class. | |
36 | * | |
37 | * <p> | |
38 | * This factory generates instances of {@link SLF4JLog}. It will remember | |
39 | * previously created instances for the same name, and will return them on | |
40 | * repeated requests to the <code>getInstance()</code> method. | |
41 | * | |
42 | * <p> | |
43 | * This implementation ignores any configured attributes. | |
44 | * </p> | |
45 | * | |
46 | * @author Rod Waldhoff | |
47 | * @author Craig R. McClanahan | |
48 | * @author Richard A. Sitze | |
49 | * @author Ceki Gülcü | |
50 | */ | |
51 | @SuppressWarnings("rawtypes") | |
52 | public class SLF4JLogFactory extends LogFactory { | |
53 | ||
54 | // ----------------------------------------------------------- Constructors | |
55 | ||
56 | /** | |
57 | * The {@link org.apache.commons.logging.Log}instances that have already been | |
58 | * created, keyed by logger name. | |
59 | */ | |
60 | ConcurrentMap<String, Log> loggerMap; | |
61 | ||
62 | /** | |
63 | * Public no-arguments constructor required by the lookup mechanism. | |
64 | */ | |
65 | public SLF4JLogFactory() { | |
66 | loggerMap = new ConcurrentHashMap<String, Log>(); | |
67 | } | |
68 | ||
69 | // ----------------------------------------------------- Manifest Constants | |
70 | ||
71 | /** | |
72 | * The name of the system property identifying our {@link Log}implementation | |
73 | * class. | |
74 | */ | |
75 | public static final String LOG_PROPERTY = "org.apache.commons.logging.Log"; | |
76 | ||
77 | // ----------------------------------------------------- Instance Variables | |
78 | ||
79 | /** | |
80 | * Configuration attributes. | |
81 | */ | |
82 | protected Hashtable attributes = new Hashtable(); | |
83 | ||
84 | // --------------------------------------------------------- Public Methods | |
85 | ||
86 | /** | |
87 | * Return the configuration attribute with the specified name (if any), or | |
88 | * <code>null</code> if there is no such attribute. | |
89 | * | |
90 | * @param name | |
91 | * Name of the attribute to return | |
92 | */ | |
93 | public Object getAttribute(String name) { | |
94 | ||
95 | return (attributes.get(name)); | |
96 | ||
97 | } | |
98 | ||
99 | /** | |
100 | * Return an array containing the names of all currently defined configuration | |
101 | * attributes. If there are no such attributes, a zero length array is | |
102 | * returned. | |
103 | */ | |
104 | @SuppressWarnings("unchecked") | |
105 | public String[] getAttributeNames() { | |
106 | ||
107 | List<String> names = new ArrayList<String>(); | |
108 | Enumeration<String> keys = attributes.keys(); | |
109 | while (keys.hasMoreElements()) { | |
110 | names.add((String) keys.nextElement()); | |
111 | } | |
112 | String results[] = new String[names.size()]; | |
113 | for (int i = 0; i < results.length; i++) { | |
114 | results[i] = (String) names.get(i); | |
115 | } | |
116 | return (results); | |
117 | ||
118 | } | |
119 | ||
120 | /** | |
121 | * Convenience method to derive a name from the specified class and call | |
122 | * <code>getInstance(String)</code> with it. | |
123 | * | |
124 | * @param clazz | |
125 | * Class for which a suitable Log name will be derived | |
126 | * | |
127 | * @exception LogConfigurationException | |
128 | * if a suitable <code>Log</code> instance cannot be returned | |
129 | */ | |
130 | public Log getInstance(Class clazz) throws LogConfigurationException { | |
131 | return (getInstance(clazz.getName())); | |
132 | } | |
133 | ||
134 | /** | |
135 | * <p> | |
136 | * Construct (if necessary) and return a <code>Log</code> instance, using | |
137 | * the factory's current set of configuration attributes. | |
138 | * </p> | |
139 | * | |
140 | * @param name | |
141 | * Logical name of the <code>Log</code> instance to be returned | |
142 | * (the meaning of this name is only known to the underlying logging | |
143 | * implementation that is being wrapped) | |
144 | * | |
145 | * @exception LogConfigurationException | |
146 | * if a suitable <code>Log</code> instance cannot be returned | |
147 | */ | |
148 | public Log getInstance(String name) throws LogConfigurationException { | |
149 | Log instance = loggerMap.get(name); | |
150 | if (instance != null) { | |
151 | return instance; | |
152 | } else { | |
153 | Log newInstance; | |
154 | Logger slf4jLogger = LoggerFactory.getLogger(name); | |
155 | if (slf4jLogger instanceof LocationAwareLogger) { | |
156 | newInstance = new SLF4JLocationAwareLog((LocationAwareLogger) slf4jLogger); | |
157 | } else { | |
158 | newInstance = new SLF4JLog(slf4jLogger); | |
159 | } | |
160 | Log oldInstance = loggerMap.putIfAbsent(name, newInstance); | |
161 | return oldInstance == null ? newInstance : oldInstance; | |
162 | } | |
163 | } | |
164 | ||
165 | /** | |
166 | * Release any internal references to previously created | |
167 | * {@link org.apache.commons.logging.Log}instances returned by this factory. | |
168 | * This is useful in environments like servlet containers, which implement | |
169 | * application reloading by throwing away a ClassLoader. Dangling references | |
170 | * to objects in that class loader would prevent garbage collection. | |
171 | */ | |
172 | public void release() { | |
173 | // This method is never called by jcl-over-slf4j classes. However, | |
174 | // in certain deployment scenarios, in particular if jcl-over-slf4j.jar | |
175 | // is | |
176 | // in the the web-app class loader and the official commons-logging.jar is | |
177 | // deployed in some parent class loader (e.g. commons/lib), then it is | |
178 | // possible | |
179 | // for the parent class loader to mask the classes shipping in | |
180 | // jcl-over-slf4j.jar. | |
181 | System.out.println("WARN: The method " + SLF4JLogFactory.class + "#release() was invoked."); | |
182 | System.out.println("WARN: Please see http://www.slf4j.org/codes.html#release for an explanation."); | |
183 | System.out.flush(); | |
184 | } | |
185 | ||
186 | /** | |
187 | * Remove any configuration attribute associated with the specified name. If | |
188 | * there is no such attribute, no action is taken. | |
189 | * | |
190 | * @param name | |
191 | * Name of the attribute to remove | |
192 | */ | |
193 | public void removeAttribute(String name) { | |
194 | attributes.remove(name); | |
195 | } | |
196 | ||
197 | /** | |
198 | * Set the configuration attribute with the specified name. Calling this with | |
199 | * a <code>null</code> value is equivalent to calling | |
200 | * <code>removeAttribute(name)</code>. | |
201 | * | |
202 | * @param name | |
203 | * Name of the attribute to set | |
204 | * @param value | |
205 | * Value of the attribute to set, or <code>null</code> to remove | |
206 | * any setting for this attribute | |
207 | */ | |
208 | @SuppressWarnings("unchecked") | |
209 | public void setAttribute(String name, Object value) { | |
210 | ||
211 | if (value == null) { | |
212 | attributes.remove(name); | |
213 | } else { | |
214 | attributes.put(name, value); | |
215 | } | |
216 | ||
217 | } | |
218 | }⏎ |
0 | /* | |
1 | * Copyright 2001-2004 The Apache Software Foundation. | |
2 | * | |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | * you may not use this file except in compliance with the License. | |
5 | * You may obtain a copy of the License at | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
9 | * Unless required by applicable law or agreed to in writing, software | |
10 | * distributed under the License is distributed on an "AS IS" BASIS, | |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | * See the License for the specific language governing permissions and | |
13 | * limitations under the License. | |
14 | */ | |
15 | ||
16 | package org.apache.commons.logging.impl; | |
17 | ||
18 | import java.io.InputStream; | |
19 | import java.io.Serializable; | |
20 | import java.lang.reflect.InvocationTargetException; | |
21 | import java.lang.reflect.Method; | |
22 | import java.security.AccessController; | |
23 | import java.security.PrivilegedAction; | |
24 | import java.text.DateFormat; | |
25 | import java.text.SimpleDateFormat; | |
26 | import java.util.Date; | |
27 | import java.util.Properties; | |
28 | ||
29 | import org.apache.commons.logging.Log; | |
30 | import org.apache.commons.logging.LogConfigurationException; | |
31 | ||
32 | /** | |
33 | * <p> | |
34 | * Simple implementation of Log that sends all enabled log messages, for all | |
35 | * defined loggers, to System.err. The following system properties are supported | |
36 | * to configure the behavior of this logger: | |
37 | * </p> | |
38 | * <ul> | |
39 | * <li><code>org.apache.commons.logging.simplelog.defaultlog</code> - Default | |
40 | * logging detail level for all instances of SimpleLog. Must be one of ("trace", | |
41 | * "debug", "info", "warn", "error", or "fatal"). If not specified, defaults to | |
42 | * "info".</li> | |
43 | * <li><code>org.apache.commons.logging.simplelog.log.xxxxx</code> - Logging | |
44 | * detail level for a SimpleLog instance named "xxxxx". Must be one of ("trace", | |
45 | * "debug", "info", "warn", "error", or "fatal"). If not specified, the default | |
46 | * logging detail level is used.</li> | |
47 | * <li><code>org.apache.commons.logging.simplelog.showlogname</code> - Set to | |
48 | * <code>true</code> if you want the Log instance name to be included in output | |
49 | * messages. Defaults to <code>false</code>.</li> | |
50 | * <li><code>org.apache.commons.logging.simplelog.showShortLogname</code> - Set | |
51 | * to <code>true</code> if you want the last component of the name to be | |
52 | * included in output messages. Defaults to <code>true</code>.</li> | |
53 | * <li><code>org.apache.commons.logging.simplelog.showdatetime</code> - Set to | |
54 | * <code>true</code> if you want the current date and time to be included in | |
55 | * output messages. Default is <code>false</code>.</li> | |
56 | * <li><code>org.apache.commons.logging.simplelog.dateTimeFormat</code> - The | |
57 | * date and time format to be used in the output messages. The pattern | |
58 | * describing the date and time format is the same that is used in | |
59 | * <code>java.text.SimpleDateFormat</code>. If the format is not specified or is | |
60 | * invalid, the default format is used. The default format is | |
61 | * <code>yyyy/MM/dd HH:mm:ss:SSS zzz</code>.</li> | |
62 | * </ul> | |
63 | * | |
64 | * <p> | |
65 | * In addition to looking for system properties with the names specified above, | |
66 | * this implementation also checks for a class loader resource named | |
67 | * <code>"simplelog.properties"</code>, and includes any matching definitions | |
68 | * from this resource (if it exists). | |
69 | * </p> | |
70 | * | |
71 | * @author <a href="mailto:sanders@apache.org">Scott Sanders</a> | |
72 | * @author Rod Waldhoff | |
73 | * @author Robert Burrell Donkin | |
74 | * | |
75 | * @version $Id: SimpleLog.java,v 1.21 2004/06/06 20:47:56 rdonkin Exp $ | |
76 | */ | |
77 | public class SimpleLog implements Log, Serializable { | |
78 | ||
79 | private static final long serialVersionUID = 136942970684951178L; | |
80 | ||
81 | // ------------------------------------------------------- Class Attributes | |
82 | ||
83 | /** All system properties used by <code>SimpleLog</code> start with this */ | |
84 | static protected final String systemPrefix = "org.apache.commons.logging.simplelog."; | |
85 | ||
86 | /** Properties loaded from simplelog.properties */ | |
87 | static protected final Properties simpleLogProps = new Properties(); | |
88 | ||
89 | /** The default format to use when formating dates */ | |
90 | static protected final String DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss:SSS zzz"; | |
91 | ||
92 | /** Include the instance name in the log message? */ | |
93 | static protected boolean showLogName = false; | |
94 | /** | |
95 | * Include the short name ( last component ) of the logger in the log message. | |
96 | * Defaults to true - otherwise we'll be lost in a flood of messages without | |
97 | * knowing who sends them. | |
98 | */ | |
99 | static protected boolean showShortName = true; | |
100 | /** Include the current time in the log message */ | |
101 | static protected boolean showDateTime = false; | |
102 | /** The date and time format to use in the log message */ | |
103 | static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT; | |
104 | /** Used to format times */ | |
105 | static protected DateFormat dateFormatter = null; | |
106 | ||
107 | // ---------------------------------------------------- Log Level Constants | |
108 | ||
109 | /** "Trace" level logging. */ | |
110 | public static final int LOG_LEVEL_TRACE = 1; | |
111 | /** "Debug" level logging. */ | |
112 | public static final int LOG_LEVEL_DEBUG = 2; | |
113 | /** "Info" level logging. */ | |
114 | public static final int LOG_LEVEL_INFO = 3; | |
115 | /** "Warn" level logging. */ | |
116 | public static final int LOG_LEVEL_WARN = 4; | |
117 | /** "Error" level logging. */ | |
118 | public static final int LOG_LEVEL_ERROR = 5; | |
119 | /** "Fatal" level logging. */ | |
120 | public static final int LOG_LEVEL_FATAL = 6; | |
121 | ||
122 | /** Enable all logging levels */ | |
123 | public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1); | |
124 | ||
125 | /** Enable no logging levels */ | |
126 | public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1); | |
127 | ||
128 | // ------------------------------------------------------------ Initializer | |