Skip to content

Commit 3818d86

Browse files
committed
Logging now uses ocpsoft-common
1 parent 460e015 commit 3818d86

32 files changed

Lines changed: 228 additions & 450 deletions

File tree

core/pom.xml renamed to api/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
<relativePath>../</relativePath>
1919
</parent>
2020

21-
<artifactId>logging</artifactId>
21+
<artifactId>logging-api</artifactId>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.ocpsoft.common</groupId>
26+
<artifactId>common-api</artifactId>
27+
</dependency>
28+
</dependencies>
2229

2330
</project>

core/src/main/java/com/ocpsoft/logging/JDKLogAdapter.java renamed to api/src/main/java/com/ocpsoft/logging/JDKLogAdapter.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ocpsoft.rewrite.logging;
1+
package com.ocpsoft.logging;
22

33
import java.util.logging.LogRecord;
44

@@ -9,19 +9,18 @@
99
*/
1010
public class JDKLogAdapter extends Logger
1111
{
12-
1312
private final java.util.logging.Logger delegate;
1413

1514
private final String name;
1615

17-
public JDKLogAdapter(String name)
16+
public JDKLogAdapter(final String name)
1817
{
1918
this.name = name;
2019
this.delegate = java.util.logging.Logger.getLogger(name);
2120
}
2221

2322
@Override
24-
protected void log(Level level, String msg, Throwable t)
23+
protected void log(final Level level, final String msg, final Throwable t)
2524
{
2625
LogRecord r = new LogRecord(getJdkLogLevel(level), msg);
2726
r.setSourceClassName(name);
@@ -31,29 +30,29 @@ protected void log(Level level, String msg, Throwable t)
3130
}
3231

3332
@Override
34-
protected boolean isEnabled(Level level)
33+
protected boolean isEnabled(final Level level)
3534
{
3635
return delegate.isLoggable(getJdkLogLevel(level));
3736
}
3837

3938
/**
4039
* Translates the log level to JDK {@link java.util.logging.Level} class.
4140
*/
42-
protected final java.util.logging.Level getJdkLogLevel(Level level)
41+
protected final java.util.logging.Level getJdkLogLevel(final Level level)
4342
{
4443
switch (level)
45-
{
46-
case TRACE:
47-
return java.util.logging.Level.FINER;
48-
case DEBUG:
49-
return java.util.logging.Level.FINE;
50-
case INFO:
51-
return java.util.logging.Level.INFO;
52-
case WARN:
53-
return java.util.logging.Level.WARNING;
54-
case ERROR:
55-
return java.util.logging.Level.SEVERE;
56-
}
44+
{
45+
case TRACE:
46+
return java.util.logging.Level.FINER;
47+
case DEBUG:
48+
return java.util.logging.Level.FINE;
49+
case INFO:
50+
return java.util.logging.Level.INFO;
51+
case WARN:
52+
return java.util.logging.Level.WARNING;
53+
case ERROR:
54+
return java.util.logging.Level.SEVERE;
55+
}
5756
throw new IllegalArgumentException("Unsupported log level: " + level);
5857
}
5958

core/src/main/java/com/ocpsoft/logging/JDKLogAdapterFactory.java renamed to api/src/main/java/com/ocpsoft/logging/JDKLogAdapterFactory.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.ocpsoft.rewrite.logging;
1+
package com.ocpsoft.logging;
22

3-
import com.ocpsoft.rewrite.services.NonEnriching;
4-
import com.ocpsoft.rewrite.spi.LogAdapterFactory;
3+
import com.ocpsoft.common.services.NonEnriching;
4+
import com.ocpsoft.logging.spi.LogAdapterFactory;
55

66
/**
77
* Implementation of {@link LogAdapterFactory} for the JDK 1.4 logging API.
@@ -10,7 +10,6 @@
1010
*/
1111
public class JDKLogAdapterFactory implements LogAdapterFactory, NonEnriching
1212
{
13-
1413
@Override
1514
public int priority()
1615
{
@@ -22,5 +21,4 @@ public Logger createLogAdapter(final String logger)
2221
{
2322
return new JDKLogAdapter(logger);
2423
}
25-
2624
}

core/src/main/java/com/ocpsoft/logging/Logger.java renamed to api/src/main/java/com/ocpsoft/logging/Logger.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.ocpsoft.rewrite.logging;
1+
package com.ocpsoft.logging;
22

33
import java.util.Collections;
44
import java.util.List;
5-
import java.util.ServiceLoader;
65

7-
import com.ocpsoft.rewrite.services.WeightedComparator;
8-
import com.ocpsoft.rewrite.spi.LogAdapterFactory;
9-
import com.ocpsoft.rewrite.util.Iterators;
6+
import com.ocpsoft.common.pattern.WeightedComparator;
7+
import com.ocpsoft.common.services.ServiceLoader;
8+
import com.ocpsoft.common.util.Iterators;
9+
import com.ocpsoft.logging.spi.LogAdapterFactory;
1010

1111
/**
1212
* Class to create log messages.
@@ -244,6 +244,7 @@ private static LogAdapterFactory getAdapterFactory()
244244
/**
245245
* Called one by {@link #getAdapterFactory()} to obtain the {@link LogAdapterFactory} with the highest priority.
246246
*/
247+
@SuppressWarnings("unchecked")
247248
private static LogAdapterFactory createAdapterFactory()
248249
{
249250
List<LogAdapterFactory> factories = Iterators.asUniqueList(ServiceLoader.load(LogAdapterFactory.class));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.ocpsoft.logging.spi;
2+
3+
import com.ocpsoft.common.pattern.Weighted;
4+
import com.ocpsoft.logging.Logger;
5+
6+
/**
7+
* SPI for custom logging adapters
8+
*
9+
* @author Christian Kaltepoth <christian@kaltepoth.de>
10+
*/
11+
public interface LogAdapterFactory extends Weighted
12+
{
13+
14+
/**
15+
* Create a new log adapter for the given logger name.
16+
*
17+
* @param logger The name of the logger
18+
* @return A log adapter extending {@link Logger}
19+
*/
20+
Logger createLogAdapter(String logger);
21+
22+
}
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.ocpsoft.logging.logging.JDKLogAdapterFactory

core/src/test/java/com/ocpsoft/rewrite/Root.java renamed to api/src/test/java/com/ocpsoft/logging/Root.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.ocpsoft.rewrite;
16+
package com.ocpsoft.logging;
1717

1818
/**
1919
* Marker interface declaring the root package of this project.

core/src/test/java/com/ocpsoft/rewrite/logging/JDKLogAdapterFactoryTest.java renamed to api/src/test/java/com/ocpsoft/logging/logging/JDKLogAdapterFactoryTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
package com.ocpsoft.rewrite.logging;
1+
package com.ocpsoft.logging.logging;
22

33
import static junit.framework.Assert.assertEquals;
44

55
import org.junit.Test;
66

7+
import com.ocpsoft.logging.JDKLogAdapter;
8+
import com.ocpsoft.logging.JDKLogAdapterFactory;
9+
import com.ocpsoft.logging.Logger;
10+
711
public class JDKLogAdapterFactoryTest
812
{
913

0 commit comments

Comments
 (0)