You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@batchee.apache.org by rm...@apache.org on 2015/03/26 19:20:28 UTC

incubator-batchee git commit: BATCHEE-63 OneLineFormatter for cli by default

Repository: incubator-batchee
Updated Branches:
  refs/heads/master d3dd38e9f -> c6f4fdf85


BATCHEE-63 OneLineFormatter for cli by default


Project: http://git-wip-us.apache.org/repos/asf/incubator-batchee/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-batchee/commit/c6f4fdf8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-batchee/tree/c6f4fdf8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-batchee/diff/c6f4fdf8

Branch: refs/heads/master
Commit: c6f4fdf85b6af8c80b1c6ac4e11ada568755a10b
Parents: d3dd38e
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Thu Mar 26 19:20:19 2015 +0100
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Thu Mar 26 19:20:19 2015 +0100

----------------------------------------------------------------------
 tools/cli/pom.xml                               |  1 +
 tools/cli/src/main/assembly/bin-openejb.xml     |  8 ++
 tools/cli/src/main/assembly/bin.xml             |  8 ++
 .../batchee/cli/jul/OneLineFormatter.java       | 94 ++++++++++++++++++++
 tools/cli/src/main/resources/logging.properties | 18 ++++
 5 files changed, 129 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/c6f4fdf8/tools/cli/pom.xml
----------------------------------------------------------------------
diff --git a/tools/cli/pom.xml b/tools/cli/pom.xml
index 2ddc71c..369595f 100644
--- a/tools/cli/pom.xml
+++ b/tools/cli/pom.xml
@@ -127,6 +127,7 @@
             </goals>
             <configuration>
               <includes>
+                <include>**/jul/*</include>
                 <include>**/bootstrap/*</include>
                 <include>**/classloader/*</include>
               </includes>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/c6f4fdf8/tools/cli/src/main/assembly/bin-openejb.xml
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/assembly/bin-openejb.xml b/tools/cli/src/main/assembly/bin-openejb.xml
index 4f0758f..e6daf87 100644
--- a/tools/cli/src/main/assembly/bin-openejb.xml
+++ b/tools/cli/src/main/assembly/bin-openejb.xml
@@ -41,6 +41,14 @@
       <fileMode>0755</fileMode>
     </fileSet>
     <fileSet>
+      <directory>${project.build.outputDirectory}</directory>
+      <outputDirectory>conf/</outputDirectory>
+      <includes>
+        <include>logging.properties</include>
+      </includes>
+      <lineEnding>unix</lineEnding>
+    </fileSet>
+    <fileSet>
       <directory>${project.build.directory}/</directory>
       <outputDirectory>bin/</outputDirectory>
       <includes>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/c6f4fdf8/tools/cli/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/assembly/bin.xml b/tools/cli/src/main/assembly/bin.xml
index c451983..8420401 100644
--- a/tools/cli/src/main/assembly/bin.xml
+++ b/tools/cli/src/main/assembly/bin.xml
@@ -41,6 +41,14 @@
       <fileMode>0755</fileMode>
     </fileSet>
     <fileSet>
+      <directory>${project.build.outputDirectory}</directory>
+      <outputDirectory>conf/</outputDirectory>
+      <includes>
+        <include>logging.properties</include>
+      </includes>
+      <lineEnding>unix</lineEnding>
+    </fileSet>
+    <fileSet>
       <directory>${project.build.directory}/</directory>
       <outputDirectory>bin/</outputDirectory>
       <includes>

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/c6f4fdf8/tools/cli/src/main/java/org/apache/batchee/cli/jul/OneLineFormatter.java
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/java/org/apache/batchee/cli/jul/OneLineFormatter.java b/tools/cli/src/main/java/org/apache/batchee/cli/jul/OneLineFormatter.java
new file mode 100644
index 0000000..9693919
--- /dev/null
+++ b/tools/cli/src/main/java/org/apache/batchee/cli/jul/OneLineFormatter.java
@@ -0,0 +1,94 @@
+/*
+ * 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.batchee.cli.jul;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+// taken from tomcat and simplified a bit (no async handler for us)
+public class OneLineFormatter extends Formatter {
+    private static final String ST_SEP = System.lineSeparator() + " ";
+    private static final String TIME_FORMAT = "dd-MMM-yyyy HH:mm:ss";
+    private static final ThreadLocal<DateFormat> LOCAL_DATE_CACHE =
+            new ThreadLocal<DateFormat>() {
+                @Override
+                protected DateFormat initialValue() {
+                    return new SimpleDateFormat(TIME_FORMAT);
+                }
+            };
+
+    @Override
+    public String format(final LogRecord record) {
+        final StringBuilder sb = new StringBuilder();
+
+        // Timestamp
+        addTimestamp(sb, record.getMillis());
+
+        // Severity
+        sb.append(' ');
+        sb.append(record.getLevel());
+
+        // Thread
+        sb.append(' ');
+        sb.append('[');
+        sb.append(Thread.currentThread().getName());
+        sb.append(']');
+
+        // Source
+        sb.append(' ');
+        sb.append(record.getSourceClassName());
+        sb.append('.');
+        sb.append(record.getSourceMethodName());
+
+        // Message
+        sb.append(' ');
+        sb.append(formatMessage(record));
+
+        // Stack trace
+        if (record.getThrown() != null) {
+            sb.append(ST_SEP);
+            final StringWriter sw = new StringWriter();
+            final PrintWriter pw = new PrintWriter(sw);
+            record.getThrown().printStackTrace(pw);
+            pw.close();
+            sb.append(sw.getBuffer());
+        }
+
+        sb.append(System.lineSeparator());
+        return sb.toString();
+    }
+
+    protected void addTimestamp(final StringBuilder buf, final long timestamp) {
+        buf.append(LOCAL_DATE_CACHE.get().format(new Date(timestamp)));
+        final long frac = timestamp % 1000;
+        buf.append('.');
+        if (frac < 100) {
+            if (frac < 10) {
+                buf.append('0');
+                buf.append('0');
+            } else {
+                buf.append('0');
+            }
+        }
+        buf.append(frac);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-batchee/blob/c6f4fdf8/tools/cli/src/main/resources/logging.properties
----------------------------------------------------------------------
diff --git a/tools/cli/src/main/resources/logging.properties b/tools/cli/src/main/resources/logging.properties
new file mode 100644
index 0000000..dafb2f2
--- /dev/null
+++ b/tools/cli/src/main/resources/logging.properties
@@ -0,0 +1,18 @@
+#
+# 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.
+handlers = java.util.logging.ConsoleHandler
+java.util.logging.ConsoleHandler.level = FINE
+java.util.logging.ConsoleHandler.formatter = org.apache.batchee.cli.jul.OneLineFormatter