You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2011/07/19 14:16:17 UTC

svn commit: r1148294 - in /openejb/trunk/openejb3/assembly/openejb-logging: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/openejb/ src/main/java/org/apache/openejb/logging/

Author: rmannibucau
Date: Tue Jul 19 12:16:16 2011
New Revision: 1148294

URL: http://svn.apache.org/viewvc?rev=1148294&view=rev
Log:
adding openejb-logging

Added:
    openejb/trunk/openejb3/assembly/openejb-logging/
    openejb/trunk/openejb3/assembly/openejb-logging/pom.xml
    openejb/trunk/openejb3/assembly/openejb-logging/src/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/Converter.java
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleJULLikeLayout.java
    openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleLog4jLikeFormatter.java

Added: openejb/trunk/openejb3/assembly/openejb-logging/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-logging/pom.xml?rev=1148294&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-logging/pom.xml (added)
+++ openejb/trunk/openejb3/assembly/openejb-logging/pom.xml Tue Jul 19 12:16:16 2011
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>assembly</artifactId>
+    <groupId>org.apache.openejb</groupId>
+    <version>4.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>openejb-logging</artifactId>
+  <name>OpenEJB :: Assembly :: Logging</name>
+  <description>
+    A simple jar to translate log format between libraries.
+    It can be used for example to unify logs between tomcat (jul) and OpenEJB (log4j).
+  </description>
+  <dependencies>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+  </dependencies>
+</project>

Added: openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/Converter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/Converter.java?rev=1148294&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/Converter.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/Converter.java Tue Jul 19 12:16:16 2011
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.apache.openejb.logging;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.apache.log4j.spi.LoggingEvent;
+
+import java.util.logging.LogRecord;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+public final class Converter {
+    private Converter() {
+        // no-op
+    }
+
+    public static LoggingEvent toLoggingEvent(LogRecord record) {
+        return new LoggingEvent(
+            record.getSourceClassName(),
+            Logger.getLogger(record.getLoggerName()),
+            record.getMillis(),
+            getPriority(record.getLevel()),
+            record.getMessage(),
+            record.getThrown());
+    }
+
+    public static LogRecord toLogRecord(LoggingEvent event) {
+        LogRecord record = new LogRecord(getJULLevel(event.getLevel()), event.getMessage().toString());
+        record.setMillis(event.getTimeStamp());
+        record.setLoggerName(event.getLoggerName());
+        return record;
+    }
+
+    private static java.util.logging.Level getJULLevel(Level level) {
+        switch (level.toInt()) {
+            case Priority.OFF_INT:
+                return java.util.logging.Level.OFF;
+            case Priority.FATAL_INT:
+            case Priority.ERROR_INT:
+                return java.util.logging.Level.SEVERE;
+            case Priority.WARN_INT:
+                return java.util.logging.Level.WARNING;
+            case Priority.DEBUG_INT:
+                return java.util.logging.Level.FINE;
+            case Priority.INFO_INT:
+            default:
+                return java.util.logging.Level.INFO;
+        }
+    }
+
+    private static Priority getPriority(java.util.logging.Level level) {
+        switch (level.intValue()) {
+            case Integer.MAX_VALUE: // OFF
+                return Level.OFF;
+            case 1000: // SEVERE:
+                return Level.ERROR;
+            case 900: // WARNING
+                return Level.WARN;
+            case 700: // CONFIG
+                return Level.INFO;
+            case 500: // FINE
+            case 400: // FINER
+            case 300: // FINEST
+                return Level.DEBUG;
+            case 800: // INFO
+            default:
+                return Level.INFO;
+        }
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleJULLikeLayout.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleJULLikeLayout.java?rev=1148294&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleJULLikeLayout.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleJULLikeLayout.java Tue Jul 19 12:16:16 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.apache.openejb.logging;
+
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.spi.LoggingEvent;
+
+import java.util.logging.SimpleFormatter;
+
+import static org.apache.openejb.logging.Converter.toLogRecord;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+public class SimpleJULLikeLayout extends SimpleLayout {
+    private static final SimpleFormatter formatter = new SimpleFormatter();
+
+    public String format(LoggingEvent event) {
+        return formatter.format(toLogRecord(event));
+    }
+}

Added: openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleLog4jLikeFormatter.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleLog4jLikeFormatter.java?rev=1148294&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleLog4jLikeFormatter.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-logging/src/main/java/org/apache/openejb/logging/SimpleLog4jLikeFormatter.java Tue Jul 19 12:16:16 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *     contributor license agreements.  See the NOTICE file distributed with
+ *     this work for additional information regarding copyright ownership.
+ *     The ASF licenses this file to You under the Apache License, Version 2.0
+ *     (the "License"); you may not use this file except in compliance with
+ *     the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *     Unless required by applicable law or agreed to in writing, software
+ *     distributed under the License is distributed on an "AS IS" BASIS,
+ *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *     See the License for the specific language governing permissions and
+ *     limitations under the License.
+ */
+
+package org.apache.openejb.logging;
+
+import org.apache.log4j.SimpleLayout;
+
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+import static org.apache.openejb.logging.Converter.toLoggingEvent;
+
+/**
+ * @author Romain Manni-Bucau
+ */
+public class SimpleLog4jLikeFormatter extends Formatter {
+    private static final SimpleLayout layout = new SimpleLayout();
+
+    public synchronized String format(LogRecord record) {
+        return layout.format(toLoggingEvent(record));
+    }
+}