You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/09/28 23:44:17 UTC
[6/9] tomee git commit: PMD
PMD
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/68119e24
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/68119e24
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/68119e24
Branch: refs/heads/tomee-7.0.0-M1
Commit: 68119e241914de48eca92e2be9c0731170e24388
Parents: 94b4a96
Author: andygumbrecht@apache.org <an...@gmx.de>
Authored: Mon Sep 28 23:15:12 2015 +0200
Committer: andygumbrecht@apache.org <an...@gmx.de>
Committed: Mon Sep 28 23:15:12 2015 +0200
----------------------------------------------------------------------
.../jul/formatter/AsyncConsoleHandler.java | 125 +++----
.../jul/formatter/SimpleTomEEFormatter.java | 96 ++---
.../tomee/jul/formatter/log/JULLogger.java | 359 ++++++++++---------
.../tomee/jul/formatter/log/ReloadableLog.java | 232 ++++++------
.../handler/rotating/BackgroundTaskRunner.java | 2 +-
.../tomee/jul/handler/rotating/Duration.java | 158 +++++---
.../jul/handler/rotating/LocalFileHandler.java | 58 +--
.../apache/tomee/jul/handler/rotating/Size.java | 108 ++++--
.../jul/formatter/SimpleTomEEFormatterTest.java | 161 +++++----
.../jul/handler/rotating/ArchivingTest.java | 10 +-
.../handler/rotating/LocalFileHandlerTest.java | 4 +-
.../tomee/jul/handler/rotating/PerfRunner.java | 14 +-
12 files changed, 724 insertions(+), 603 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java
index c6724c0..e212428 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/AsyncConsoleHandler.java
@@ -1,62 +1,63 @@
-/*
- * 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.tomee.jul.formatter;
-
-import org.apache.juli.AsyncFileHandler;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Formatter;
-import java.util.logging.LogRecord;
-
-public class AsyncConsoleHandler extends AsyncFileHandler {
- private final ConsoleHandler delegate = new ConsoleHandler() {{
- setFormatter(new SingleLineFormatter()); // console -> dev. File uses plain old format
- }};
-
- protected void publishInternal(final LogRecord record) {
- delegate.publish(record);
- }
-
- // copy cause of classloading
- private static class SingleLineFormatter extends Formatter {
- private static final String SEP = System.getProperty("line.separator", "\n");
-
- @Override
- public synchronized String format(final LogRecord record) {
- final boolean exception = record.getThrown() != null;
- final StringBuilder sbuf = new StringBuilder();
- sbuf.append(record.getLevel().getLocalizedName());
- sbuf.append(" - ");
- sbuf.append(this.formatMessage(record));
- sbuf.append(SEP);
- if (exception) {
- try {
- final StringWriter sw = new StringWriter();
- final PrintWriter pw = new PrintWriter(sw);
- record.getThrown().printStackTrace(pw);
- pw.close();
- sbuf.append(sw.toString());
- } catch (final Exception ex) {
- // no-op
- }
- }
- return sbuf.toString();
- }
- }
-}
+/*
+ * 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.tomee.jul.formatter;
+
+import org.apache.juli.AsyncFileHandler;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+public class AsyncConsoleHandler extends AsyncFileHandler {
+ private final ConsoleHandler delegate = new ConsoleHandler() {{
+ setFormatter(new SingleLineFormatter()); // console -> dev. File uses plain old format
+ }};
+
+ protected void publishInternal(final LogRecord record) {
+ delegate.publish(record);
+ }
+
+ // copy cause of classloading
+ private static class SingleLineFormatter extends Formatter {
+ private static final String SEP = System.getProperty("line.separator", "\n");
+
+ @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+ @Override
+ public synchronized String format(final LogRecord record) {
+ final boolean exception = record.getThrown() != null;
+ final StringBuilder sbuf = new StringBuilder();
+ sbuf.append(record.getLevel().getLocalizedName());
+ sbuf.append(" - ");
+ sbuf.append(this.formatMessage(record));
+ sbuf.append(SEP);
+ if (exception) {
+ try {
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ record.getThrown().printStackTrace(pw);
+ pw.close();
+ sbuf.append(sw.toString());
+ } catch (final Exception ex) {
+ // no-op
+ }
+ }
+ return sbuf.toString();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java
index 9c49445..5ee3a39 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatter.java
@@ -1,48 +1,48 @@
-/**
- *
- * 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.tomee.jul.formatter;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.logging.LogRecord;
-
-public class SimpleTomEEFormatter extends java.util.logging.Formatter {
- private static final String LN = System.getProperty("line.separator");
-
- @Override
- public synchronized String format(final LogRecord record) {
- final Throwable thrown = record.getThrown();
- final StringBuilder sbuf = new StringBuilder();
- sbuf.append(record.getLevel().getLocalizedName());
- sbuf.append(" - ");
- sbuf.append(formatMessage(record));
- sbuf.append(LN);
- if (thrown != null) {
- try {
- final StringWriter sw = new StringWriter();
- final PrintWriter pw = new PrintWriter(sw);
- thrown.printStackTrace(pw);
- pw.close();
- sbuf.append(sw.toString());
- } catch (final Exception ex) {
- // no-op
- }
- }
- return sbuf.toString();
- }
-}
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.tomee.jul.formatter;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.LogRecord;
+
+public class SimpleTomEEFormatter extends java.util.logging.Formatter {
+ private static final String LN = System.getProperty("line.separator");
+
+ @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
+ @Override
+ public synchronized String format(final LogRecord record) {
+ final Throwable thrown = record.getThrown();
+ final StringBuilder sbuf = new StringBuilder();
+ sbuf.append(record.getLevel().getLocalizedName());
+ sbuf.append(" - ");
+ sbuf.append(formatMessage(record));
+ sbuf.append(LN);
+ if (thrown != null) {
+ try {
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw);
+ thrown.printStackTrace(pw);
+ pw.close();
+ sbuf.append(sw.toString());
+ } catch (final Exception ex) {
+ // no-op
+ }
+ }
+ return sbuf.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java
index 4e7e938..39f8b4d 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/JULLogger.java
@@ -1,179 +1,180 @@
-/*
- * 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.tomee.jul.formatter.log;
-
-import org.apache.juli.logging.Log;
-
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Formatter;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-// DirectJDKLog copy since it is now package scoped
-public class JULLogger implements Log {
- /** Alternate config reader and console format
- */
- private static final String SIMPLE_FMT="java.util.logging.SimpleFormatter";
- private static final String SIMPLE_CFG="org.apache.juli.JdkLoggerConfig"; //doesn't exist
- private static final String FORMATTER="org.apache.juli.formatter";
-
- static {
- if (System.getProperty("java.util.logging.config.class") == null &&
- System.getProperty("java.util.logging.config.file") == null) {
- // default configuration - it sucks. Let's override at least the
- // formatter for the console
- try {
- Class.forName(SIMPLE_CFG).newInstance();
- } catch(final Throwable t) {
- // no-op
- }
- try {
- final Formatter fmt=(Formatter)Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).newInstance();
- // it is also possible that the user modified jre/lib/logging.properties -
- // but that's really stupid in most cases
- final Logger root=Logger.getLogger("");
- final Handler[] handlers = root.getHandlers();
- for( int i=0; i< handlers.length; i++ ) {
- // I only care about console - that's what's used in default config anyway
- if( handlers[i] instanceof ConsoleHandler) {
- handlers[i].setFormatter(fmt);
- }
- }
- } catch( Throwable t ) {
- // no-op maybe it wasn't included - the ugly default will be used.
- }
- }
- }
-
- private final Logger logger;
-
- public JULLogger(final String name ) {
- logger= Logger.getLogger(name);
- }
-
- @Override
- public final boolean isErrorEnabled() {
- return logger.isLoggable(Level.SEVERE);
- }
-
- @Override
- public final boolean isWarnEnabled() {
- return logger.isLoggable(Level.WARNING);
- }
-
- @Override
- public final boolean isInfoEnabled() {
- return logger.isLoggable(Level.INFO);
- }
-
- @Override
- public final boolean isDebugEnabled() {
- return logger.isLoggable(Level.FINE);
- }
-
- @Override
- public final boolean isFatalEnabled() {
- return logger.isLoggable(Level.SEVERE);
- }
-
- @Override
- public final boolean isTraceEnabled() {
- return logger.isLoggable(Level.FINER);
- }
-
- @Override
- public final void debug(final Object message) {
- log(Level.FINE, String.valueOf(message), null);
- }
-
- @Override
- public final void debug(final Object message, final Throwable t) {
- log(Level.FINE, String.valueOf(message), t);
- }
-
- @Override
- public final void trace(final Object message) {
- log(Level.FINER, String.valueOf(message), null);
- }
-
- @Override
- public final void trace(final Object message, final Throwable t) {
- log(Level.FINER, String.valueOf(message), t);
- }
-
- @Override
- public final void info(final Object message) {
- log(Level.INFO, String.valueOf(message), null);
- }
-
- @Override
- public final void info(final Object message, final Throwable t) {
- log(Level.INFO, String.valueOf(message), t);
- }
-
- @Override
- public final void warn(final Object message) {
- log(Level.WARNING, String.valueOf(message), null);
- }
-
- @Override
- public final void warn(final Object message, final Throwable t) {
- log(Level.WARNING, String.valueOf(message), t);
- }
-
- @Override
- public final void error(final Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
- @Override
- public final void error(final Object message, final Throwable t) {
- log(Level.SEVERE, String.valueOf(message), t);
- }
-
- @Override
- public final void fatal(final Object message) {
- log(Level.SEVERE, String.valueOf(message), null);
- }
-
- @Override
- public final void fatal(final Object message, final Throwable t) {
- log(Level.SEVERE, String.valueOf(message), t);
- }
-
- private void log(final Level level, final String msg, final Throwable ex) {
- if (logger.isLoggable(level)) {
- // Hack (?) to get the stack trace.
- final Throwable dummyException=new Throwable();
- final StackTraceElement[] locations=dummyException.getStackTrace();
- // Caller will be the third element
- String cname = "unknown";
- String method = "unknown";
- if (locations != null && locations.length > 3) {
- final StackTraceElement caller = locations[3];
- cname = caller.getClassName();
- method = caller.getMethodName();
- }
- if (ex==null) {
- logger.logp(level, cname, method, msg);
- } else {
- logger.logp(level, cname, method, msg, ex);
- }
- }
- }
-}
+/*
+ * 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.tomee.jul.formatter.log;
+
+import org.apache.juli.logging.Log;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+// DirectJDKLog copy since it is now package scoped
+public class JULLogger implements Log {
+ /**
+ * Alternate config reader and console format
+ */
+ private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter";
+ private static final String SIMPLE_CFG = "org.apache.juli.JdkLoggerConfig"; //doesn't exist
+ private static final String FORMATTER = "org.apache.juli.formatter";
+
+ static {
+ if (System.getProperty("java.util.logging.config.class") == null &&
+ System.getProperty("java.util.logging.config.file") == null) {
+ // default configuration - it sucks. Let's override at least the
+ // formatter for the console
+ try {
+ Class.forName(SIMPLE_CFG).newInstance();
+ } catch (final Throwable t) {
+ // no-op
+ }
+ try {
+ final Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).newInstance();
+ // it is also possible that the user modified jre/lib/logging.properties -
+ // but that's really stupid in most cases
+ final Logger root = Logger.getLogger("");
+ final Handler[] handlers = root.getHandlers();
+ for (final Handler handler : handlers) {
+ // I only care about console - that's what's used in default config anyway
+ if (handler instanceof ConsoleHandler) {
+ handler.setFormatter(fmt);
+ }
+ }
+ } catch (final Throwable t) {
+ // no-op maybe it wasn't included - the ugly default will be used.
+ }
+ }
+ }
+
+ private final Logger logger;
+
+ public JULLogger(final String name) {
+ logger = Logger.getLogger(name);
+ }
+
+ @Override
+ public final boolean isErrorEnabled() {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ @Override
+ public final boolean isWarnEnabled() {
+ return logger.isLoggable(Level.WARNING);
+ }
+
+ @Override
+ public final boolean isInfoEnabled() {
+ return logger.isLoggable(Level.INFO);
+ }
+
+ @Override
+ public final boolean isDebugEnabled() {
+ return logger.isLoggable(Level.FINE);
+ }
+
+ @Override
+ public final boolean isFatalEnabled() {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ @Override
+ public final boolean isTraceEnabled() {
+ return logger.isLoggable(Level.FINER);
+ }
+
+ @Override
+ public final void debug(final Object message) {
+ log(Level.FINE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void debug(final Object message, final Throwable t) {
+ log(Level.FINE, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void trace(final Object message) {
+ log(Level.FINER, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void trace(final Object message, final Throwable t) {
+ log(Level.FINER, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void info(final Object message) {
+ log(Level.INFO, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void info(final Object message, final Throwable t) {
+ log(Level.INFO, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void warn(final Object message) {
+ log(Level.WARNING, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void warn(final Object message, final Throwable t) {
+ log(Level.WARNING, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void error(final Object message) {
+ log(Level.SEVERE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void error(final Object message, final Throwable t) {
+ log(Level.SEVERE, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void fatal(final Object message) {
+ log(Level.SEVERE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void fatal(final Object message, final Throwable t) {
+ log(Level.SEVERE, String.valueOf(message), t);
+ }
+
+ private void log(final Level level, final String msg, final Throwable ex) {
+ if (logger.isLoggable(level)) {
+ // Hack (?) to get the stack trace.
+ final Throwable dummyException = new Throwable();
+ final StackTraceElement[] locations = dummyException.getStackTrace();
+ // Caller will be the third element
+ String cname = "unknown";
+ String method = "unknown";
+ if (locations != null && locations.length > 3) {
+ final StackTraceElement caller = locations[3];
+ cname = caller.getClassName();
+ method = caller.getMethodName();
+ }
+ if (ex == null) {
+ logger.logp(level, cname, method, msg);
+ } else {
+ logger.logp(level, cname, method, msg, ex);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java
index fecee67..fe274f8 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/formatter/log/ReloadableLog.java
@@ -1,116 +1,116 @@
-/*
- * 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.tomee.jul.formatter.log;
-
-import org.apache.juli.logging.Log;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.concurrent.atomic.AtomicReference;
-
-public final class ReloadableLog {
-
- public static final Class<?>[] INTERFACES = new Class<?>[]{Log.class};
-
- private ReloadableLog() {
- // no-op
- }
-
- public static Log newLog(final String name, final String factory) {
- return Log.class.cast(Proxy.newProxyInstance(
- ReloadableLog.class.getClassLoader(), INTERFACES, new ReloadableLogHandler(factory, name)));
- }
-
- private static final class ReloadableLogHandler implements InvocationHandler {
- private static final String LOG4J_IMPL = "org.apache.tomee.loader.log.Log4jLog";
- private static final String LOG4J2_IMPL = "org.apache.tomee.loader.log.Log4j2Log";
- private static final String SLF4J_IMPL = "org.apache.tomee.loader.log.Slf4jLog";
- private static final String MAVEN_IMPL = "org.apache.openejb.maven.util.TomEEMavenLog";
-
- private volatile String factory;
- private final String name;
- private final AtomicReference<Log> delegate = new AtomicReference<>();
- private volatile boolean done = false;
-
- public ReloadableLogHandler(final String factory, final String name) {
- this.factory = factory;
- this.name = name;
- initDelegate();
- }
-
- private Log initDelegate() {
- if (done) {
- return delegate.get();
- }
-
- try {
- if (factory == null) {
- final String f = TomEELog.getLoggerClazz();
- if (f != null) {
- factory = f;
- }
-
- final Log log = delegate.get();
- if (factory == null && log != null) {
- return log;
- }
- }
- switch (factory) {
- case "org.apache.openejb.util.Log4jLogStreamFactory":
- delegate.set(newInstance(LOG4J_IMPL));
- break;
- case "org.apache.openejb.util.Log4j2LogStreamFactory":
- delegate.set(newInstance(LOG4J2_IMPL));
- break;
- case "org.apache.openejb.util.Slf4jLogStreamFactory":
- delegate.set(newInstance(SLF4J_IMPL));
- break;
- case "org.apache.openejb.maven.util.MavenLogStreamFactory":
- delegate.set(newInstance(MAVEN_IMPL));
- break;
- default:
- delegate.set(new JULLogger(name));
- }
- done = true;
- } catch (final Throwable the) {
- if (delegate.get() == null) {
- delegate.set(new JULLogger(name));
- }
- }
- return delegate.get();
- }
-
- private Log newInstance(final String impl) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
- return Log.class.cast(Thread.currentThread()
- .getContextClassLoader()
- .loadClass(impl)
- .getConstructor(String.class)
- .newInstance(name));
- }
-
- @Override
- public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- try {
- return method.invoke(initDelegate(), args);
- } catch (final InvocationTargetException ite) {
- throw ite.getCause();
- }
- }
- }
-}
+/*
+ * 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.tomee.jul.formatter.log;
+
+import org.apache.juli.logging.Log;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.concurrent.atomic.AtomicReference;
+
+public final class ReloadableLog {
+
+ public static final Class<?>[] INTERFACES = new Class<?>[]{Log.class};
+
+ private ReloadableLog() {
+ // no-op
+ }
+
+ public static Log newLog(final String name, final String factory) {
+ return Log.class.cast(Proxy.newProxyInstance(
+ ReloadableLog.class.getClassLoader(), INTERFACES, new ReloadableLogHandler(factory, name)));
+ }
+
+ private static final class ReloadableLogHandler implements InvocationHandler {
+ private static final String LOG4J_IMPL = "org.apache.tomee.loader.log.Log4jLog";
+ private static final String LOG4J2_IMPL = "org.apache.tomee.loader.log.Log4j2Log";
+ private static final String SLF4J_IMPL = "org.apache.tomee.loader.log.Slf4jLog";
+ private static final String MAVEN_IMPL = "org.apache.openejb.maven.util.TomEEMavenLog";
+
+ private volatile String factory;
+ private final String name;
+ private final AtomicReference<Log> delegate = new AtomicReference<>();
+ private volatile boolean done = false;
+
+ public ReloadableLogHandler(final String factory, final String name) {
+ this.factory = factory;
+ this.name = name;
+ initDelegate();
+ }
+
+ private Log initDelegate() {
+ if (done) {
+ return delegate.get();
+ }
+
+ try {
+ if (factory == null) {
+ final String f = TomEELog.getLoggerClazz();
+ if (f != null) {
+ factory = f;
+ }
+
+ final Log log = delegate.get();
+ if (factory == null && log != null) {
+ return log;
+ }
+ }
+ switch (factory) {
+ case "org.apache.openejb.util.Log4jLogStreamFactory":
+ delegate.set(newInstance(LOG4J_IMPL));
+ break;
+ case "org.apache.openejb.util.Log4j2LogStreamFactory":
+ delegate.set(newInstance(LOG4J2_IMPL));
+ break;
+ case "org.apache.openejb.util.Slf4jLogStreamFactory":
+ delegate.set(newInstance(SLF4J_IMPL));
+ break;
+ case "org.apache.openejb.maven.util.MavenLogStreamFactory":
+ delegate.set(newInstance(MAVEN_IMPL));
+ break;
+ default:
+ delegate.set(new JULLogger(name));
+ }
+ done = true;
+ } catch (final Throwable the) {
+ if (delegate.get() == null) {
+ delegate.set(new JULLogger(name));
+ }
+ }
+ return delegate.get();
+ }
+
+ private Log newInstance(final String impl) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
+ return Log.class.cast(Thread.currentThread()
+ .getContextClassLoader()
+ .loadClass(impl)
+ .getConstructor(String.class)
+ .newInstance(name));
+ }
+
+ @Override
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
+ try {
+ return method.invoke(initDelegate(), args);
+ } catch (final InvocationTargetException ite) {
+ throw ite.getCause();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/BackgroundTaskRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/BackgroundTaskRunner.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/BackgroundTaskRunner.java
index 5b88b5f..2b63ef0 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/BackgroundTaskRunner.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/BackgroundTaskRunner.java
@@ -45,7 +45,7 @@ class BackgroundTaskRunner {
private final String namePrefix = "com.tomitribe.logging.jul.handler.BackgroundTaskThread-";
{
- SecurityManager s = System.getSecurityManager();
+ final SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Duration.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Duration.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Duration.java
index 005f43a..feac41f 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Duration.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Duration.java
@@ -100,10 +100,10 @@ class Duration {
return unit.toMillis(time);
}
- private static class Normalize {
- private long a;
- private long b;
- private TimeUnit base;
+ private static final class Normalize {
+ private final long a;
+ private final long b;
+ private final TimeUnit base;
private Normalize(final Duration a, final Duration b) {
this.base = lowest(a, b);
@@ -112,10 +112,18 @@ class Duration {
}
private static TimeUnit lowest(final Duration a, final Duration b) {
- if (a.unit == null) return b.unit;
- if (b.unit == null) return a.unit;
- if (a.time == 0) return b.unit;
- if (b.time == 0) return a.unit;
+ if (a.unit == null) {
+ return b.unit;
+ }
+ if (b.unit == null) {
+ return a.unit;
+ }
+ if (a.time == 0) {
+ return b.unit;
+ }
+ if (b.time == 0) {
+ return a.unit;
+ }
return TimeUnit.values()[Math.min(a.unit.ordinal(), b.unit.ordinal())];
}
}
@@ -127,7 +135,7 @@ class Duration {
private static void invalidFormat(final String text) {
throw new IllegalArgumentException("Illegal duration format: '" + text +
- "'. Valid examples are '10s' or '10 seconds'.");
+ "'. Valid examples are '10s' or '10 seconds'.");
}
private static TimeUnit parseUnit(final String u) {
@@ -135,42 +143,102 @@ class Duration {
return null;
}
- if ("NANOSECONDS".equalsIgnoreCase(u)) return TimeUnit.NANOSECONDS;
- if ("NANOSECOND".equalsIgnoreCase(u)) return TimeUnit.NANOSECONDS;
- if ("NANOS".equalsIgnoreCase(u)) return TimeUnit.NANOSECONDS;
- if ("NANO".equalsIgnoreCase(u)) return TimeUnit.NANOSECONDS;
- if ("NS".equalsIgnoreCase(u)) return TimeUnit.NANOSECONDS;
-
- if ("MICROSECONDS".equalsIgnoreCase(u)) return TimeUnit.MICROSECONDS;
- if ("MICROSECOND".equalsIgnoreCase(u)) return TimeUnit.MICROSECONDS;
- if ("MICROS".equalsIgnoreCase(u)) return TimeUnit.MICROSECONDS;
- if ("MICRO".equalsIgnoreCase(u)) return TimeUnit.MICROSECONDS;
-
- if ("MILLISECONDS".equalsIgnoreCase(u)) return TimeUnit.MILLISECONDS;
- if ("MILLISECOND".equalsIgnoreCase(u)) return TimeUnit.MILLISECONDS;
- if ("MILLIS".equalsIgnoreCase(u)) return TimeUnit.MILLISECONDS;
- if ("MILLI".equalsIgnoreCase(u)) return TimeUnit.MILLISECONDS;
- if ("MS".equalsIgnoreCase(u)) return TimeUnit.MILLISECONDS;
-
- if ("SECONDS".equalsIgnoreCase(u)) return TimeUnit.SECONDS;
- if ("SECOND".equalsIgnoreCase(u)) return TimeUnit.SECONDS;
- if ("SEC".equalsIgnoreCase(u)) return TimeUnit.SECONDS;
- if ("S".equalsIgnoreCase(u)) return TimeUnit.SECONDS;
-
- if ("MINUTES".equalsIgnoreCase(u)) return TimeUnit.MINUTES;
- if ("MINUTE".equalsIgnoreCase(u)) return TimeUnit.MINUTES;
- if ("MIN".equalsIgnoreCase(u)) return TimeUnit.MINUTES;
- if ("M".equalsIgnoreCase(u)) return TimeUnit.MINUTES;
-
- if ("HOURS".equalsIgnoreCase(u)) return TimeUnit.HOURS;
- if ("HOUR".equalsIgnoreCase(u)) return TimeUnit.HOURS;
- if ("HRS".equalsIgnoreCase(u)) return TimeUnit.HOURS;
- if ("HR".equalsIgnoreCase(u)) return TimeUnit.HOURS;
- if ("H".equalsIgnoreCase(u)) return TimeUnit.HOURS;
-
- if ("DAYS".equalsIgnoreCase(u)) return TimeUnit.DAYS;
- if ("DAY".equalsIgnoreCase(u)) return TimeUnit.DAYS;
- if ("D".equalsIgnoreCase(u)) return TimeUnit.DAYS;
+ if ("NANOSECONDS".equalsIgnoreCase(u)) {
+ return TimeUnit.NANOSECONDS;
+ }
+ if ("NANOSECOND".equalsIgnoreCase(u)) {
+ return TimeUnit.NANOSECONDS;
+ }
+ if ("NANOS".equalsIgnoreCase(u)) {
+ return TimeUnit.NANOSECONDS;
+ }
+ if ("NANO".equalsIgnoreCase(u)) {
+ return TimeUnit.NANOSECONDS;
+ }
+ if ("NS".equalsIgnoreCase(u)) {
+ return TimeUnit.NANOSECONDS;
+ }
+
+ if ("MICROSECONDS".equalsIgnoreCase(u)) {
+ return TimeUnit.MICROSECONDS;
+ }
+ if ("MICROSECOND".equalsIgnoreCase(u)) {
+ return TimeUnit.MICROSECONDS;
+ }
+ if ("MICROS".equalsIgnoreCase(u)) {
+ return TimeUnit.MICROSECONDS;
+ }
+ if ("MICRO".equalsIgnoreCase(u)) {
+ return TimeUnit.MICROSECONDS;
+ }
+
+ if ("MILLISECONDS".equalsIgnoreCase(u)) {
+ return TimeUnit.MILLISECONDS;
+ }
+ if ("MILLISECOND".equalsIgnoreCase(u)) {
+ return TimeUnit.MILLISECONDS;
+ }
+ if ("MILLIS".equalsIgnoreCase(u)) {
+ return TimeUnit.MILLISECONDS;
+ }
+ if ("MILLI".equalsIgnoreCase(u)) {
+ return TimeUnit.MILLISECONDS;
+ }
+ if ("MS".equalsIgnoreCase(u)) {
+ return TimeUnit.MILLISECONDS;
+ }
+
+ if ("SECONDS".equalsIgnoreCase(u)) {
+ return TimeUnit.SECONDS;
+ }
+ if ("SECOND".equalsIgnoreCase(u)) {
+ return TimeUnit.SECONDS;
+ }
+ if ("SEC".equalsIgnoreCase(u)) {
+ return TimeUnit.SECONDS;
+ }
+ if ("S".equalsIgnoreCase(u)) {
+ return TimeUnit.SECONDS;
+ }
+
+ if ("MINUTES".equalsIgnoreCase(u)) {
+ return TimeUnit.MINUTES;
+ }
+ if ("MINUTE".equalsIgnoreCase(u)) {
+ return TimeUnit.MINUTES;
+ }
+ if ("MIN".equalsIgnoreCase(u)) {
+ return TimeUnit.MINUTES;
+ }
+ if ("M".equalsIgnoreCase(u)) {
+ return TimeUnit.MINUTES;
+ }
+
+ if ("HOURS".equalsIgnoreCase(u)) {
+ return TimeUnit.HOURS;
+ }
+ if ("HOUR".equalsIgnoreCase(u)) {
+ return TimeUnit.HOURS;
+ }
+ if ("HRS".equalsIgnoreCase(u)) {
+ return TimeUnit.HOURS;
+ }
+ if ("HR".equalsIgnoreCase(u)) {
+ return TimeUnit.HOURS;
+ }
+ if ("H".equalsIgnoreCase(u)) {
+ return TimeUnit.HOURS;
+ }
+
+ if ("DAYS".equalsIgnoreCase(u)) {
+ return TimeUnit.DAYS;
+ }
+ if ("DAY".equalsIgnoreCase(u)) {
+ return TimeUnit.DAYS;
+ }
+ if ("D".equalsIgnoreCase(u)) {
+ return TimeUnit.DAYS;
+ }
throw new IllegalArgumentException("Unknown time unit '" + u + "'");
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/LocalFileHandler.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/LocalFileHandler.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/LocalFileHandler.java
index 7656063..a3471e4 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/LocalFileHandler.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/LocalFileHandler.java
@@ -50,27 +50,27 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
- * NOTE: for simplicity the prefix `org.apache.tomee.jul.handler.rotating.LocalFileHandler.` has been removed of name columns.
- *
- * |===
- * | Name | Default Value | Description
- * | filenamePattern | ${catalina.base}/logs/logs.%s.%03d.log | where log files are created, it uses String.format() and gives you the date and file number - in this order.
- * | limit | 10 Megabytes | limit size indicating the file should be rotated
- * | dateCheckInterval | 5 seconds | how often the date should be computed to rotate the file (don't do it each time for performances reason, means you can get few records of next day in a file name with current day)
- * | bufferSize | -1 bytes | if positive the in memory buffer used to store data before flushing them to the disk
- * | encoding | - | file encoding
- * | level | ALL | level this handler accepts
- * | filter | - | filter used to check if the message should be logged
- * | formatter | java.util.logging.SimpleFormatter | formatter used to format messages
- * | archiveDirectory | ${catalina.base}/logs/archives/ | where compressed logs are put.
- * | archiveFormat | gzip | zip or gzip.
- * | archiveOlderThan | -1 days | how many days files are kept before being compressed
- * | purgeOlderThan | -1 days | how many days files are kept before being deleted, note: it applies on archives and not log files so 2 days of archiving and 3 days of purge makes it deleted after 5 days.
- * | compressionLevel | -1 | In case of zip archiving the zip compression level (-1 for off or 0-9).
- * |===
- *
- * NOTE: archiving and purging are done only when a file is rotated, it means it can be ignored during days if there is no logging activity.
- *
+ * NOTE: for simplicity the prefix `org.apache.tomee.jul.handler.rotating.LocalFileHandler.` has been removed of name columns.
+ * <p/>
+ * |===
+ * | Name | Default Value | Description
+ * | filenamePattern | ${catalina.base}/logs/logs.%s.%03d.log | where log files are created, it uses String.format() and gives you the date and file number - in this order.
+ * | limit | 10 Megabytes | limit size indicating the file should be rotated
+ * | dateCheckInterval | 5 seconds | how often the date should be computed to rotate the file (don't do it each time for performances reason, means you can get few records of next day in a file name with current day)
+ * | bufferSize | -1 bytes | if positive the in memory buffer used to store data before flushing them to the disk
+ * | encoding | - | file encoding
+ * | level | ALL | level this handler accepts
+ * | filter | - | filter used to check if the message should be logged
+ * | formatter | java.util.logging.SimpleFormatter | formatter used to format messages
+ * | archiveDirectory | ${catalina.base}/logs/archives/ | where compressed logs are put.
+ * | archiveFormat | gzip | zip or gzip.
+ * | archiveOlderThan | -1 days | how many days files are kept before being compressed
+ * | purgeOlderThan | -1 days | how many days files are kept before being deleted, note: it applies on archives and not log files so 2 days of archiving and 3 days of purge makes it deleted after 5 days.
+ * | compressionLevel | -1 | In case of zip archiving the zip compression level (-1 for off or 0-9).
+ * |===
+ * <p/>
+ * NOTE: archiving and purging are done only when a file is rotated, it means it can be ignored during days if there is no logging activity.
+ * <p/>
* NOTE: archiving and purging is done in a background thread pool, you can configure the number of threads in thanks to
* `org.apache.tomee.jul.handler.rotating.BackgroundTaskRunner.threads` property in `conf/logging.properties`.
* Default is 2 which should be fine for most applications.
@@ -207,7 +207,7 @@ public class LocalFileHandler extends Handler {
writerLock.readLock().lock();
rotateIfNeeded(tsDate);
- String result;
+ final String result;
try {
result = getFormatter().format(record);
} catch (final Exception e) {
@@ -392,12 +392,12 @@ public class LocalFileHandler extends Handler {
}
if (archiveExpiryDuration > 0) { // archiving log files
final File[] logs = new File(formatFilename(filenamePattern, "0000-00-00", 0)).getParentFile()
- .listFiles(new FilenameFilter() {
- @Override
- public boolean accept(final File dir, final String name) {
- return filenameRegex.matcher(name).matches();
- }
- });
+ .listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(final File dir, final String name) {
+ return filenameRegex.matcher(name).matches();
+ }
+ });
if (logs != null) {
for (final File file : logs) {
@@ -514,7 +514,7 @@ public class LocalFileHandler extends Handler {
return result;
}
- private class CountingStream extends OutputStream {
+ private final class CountingStream extends OutputStream {
private final OutputStream out;
private CountingStream(final OutputStream out) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Size.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Size.java b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Size.java
index be1b476..a7d9844 100644
--- a/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Size.java
+++ b/tomee/tomee-juli/src/main/java/org/apache/tomee/jul/handler/rotating/Size.java
@@ -111,10 +111,10 @@ class Size {
return unit.toBytes(size);
}
- private static class Normalize {
- private long a;
- private long b;
- private SizeUnit base;
+ private static final class Normalize {
+ private final long a;
+ private final long b;
+ private final SizeUnit base;
private Normalize(final Size a, final Size b) {
this.base = lowest(a, b);
@@ -123,10 +123,18 @@ class Size {
}
private static SizeUnit lowest(final Size a, final Size b) {
- if (a.unit == null) return b.unit;
- if (b.unit == null) return a.unit;
- if (a.size == 0) return b.unit;
- if (b.size == 0) return a.unit;
+ if (a.unit == null) {
+ return b.unit;
+ }
+ if (b.unit == null) {
+ return a.unit;
+ }
+ if (a.size == 0) {
+ return b.unit;
+ }
+ if (b.size == 0) {
+ return a.unit;
+ }
return SizeUnit.values()[Math.min(a.unit.ordinal(), b.unit.ordinal())];
}
}
@@ -141,29 +149,67 @@ class Size {
}
private static SizeUnit parseUnit(final String u) {
- if (u.length() == 0) return null;
-
- if ("BYTES".equalsIgnoreCase(u)) return SizeUnit.BYTES;
- if ("BYTE".equalsIgnoreCase(u)) return SizeUnit.BYTES;
- if ("B".equalsIgnoreCase(u)) return SizeUnit.BYTES;
-
- if ("KILOBYTES".equalsIgnoreCase(u)) return SizeUnit.KILOBYTES;
- if ("KILOBYTE".equalsIgnoreCase(u)) return SizeUnit.KILOBYTES;
- if ("KILO".equalsIgnoreCase(u)) return SizeUnit.KILOBYTES;
- if ("KB".equalsIgnoreCase(u)) return SizeUnit.KILOBYTES;
- if ("K".equalsIgnoreCase(u)) return SizeUnit.KILOBYTES;
-
- if ("MEGABYTES".equalsIgnoreCase(u)) return SizeUnit.MEGABYTES;
- if ("MEGABYTE".equalsIgnoreCase(u)) return SizeUnit.MEGABYTES;
- if ("MEGA".equalsIgnoreCase(u)) return SizeUnit.MEGABYTES;
- if ("MB".equalsIgnoreCase(u)) return SizeUnit.MEGABYTES;
- if ("M".equalsIgnoreCase(u)) return SizeUnit.MEGABYTES;
-
- if ("GIGABYTES".equalsIgnoreCase(u)) return SizeUnit.GIGABYTES;
- if ("GIGABYTE".equalsIgnoreCase(u)) return SizeUnit.GIGABYTES;
- if ("GIGA".equalsIgnoreCase(u)) return SizeUnit.GIGABYTES;
- if ("GB".equalsIgnoreCase(u)) return SizeUnit.GIGABYTES;
- if ("G".equalsIgnoreCase(u)) return SizeUnit.GIGABYTES;
+ if (u.length() == 0) {
+ return null;
+ }
+
+ if ("BYTES".equalsIgnoreCase(u)) {
+ return SizeUnit.BYTES;
+ }
+ if ("BYTE".equalsIgnoreCase(u)) {
+ return SizeUnit.BYTES;
+ }
+ if ("B".equalsIgnoreCase(u)) {
+ return SizeUnit.BYTES;
+ }
+
+ if ("KILOBYTES".equalsIgnoreCase(u)) {
+ return SizeUnit.KILOBYTES;
+ }
+ if ("KILOBYTE".equalsIgnoreCase(u)) {
+ return SizeUnit.KILOBYTES;
+ }
+ if ("KILO".equalsIgnoreCase(u)) {
+ return SizeUnit.KILOBYTES;
+ }
+ if ("KB".equalsIgnoreCase(u)) {
+ return SizeUnit.KILOBYTES;
+ }
+ if ("K".equalsIgnoreCase(u)) {
+ return SizeUnit.KILOBYTES;
+ }
+
+ if ("MEGABYTES".equalsIgnoreCase(u)) {
+ return SizeUnit.MEGABYTES;
+ }
+ if ("MEGABYTE".equalsIgnoreCase(u)) {
+ return SizeUnit.MEGABYTES;
+ }
+ if ("MEGA".equalsIgnoreCase(u)) {
+ return SizeUnit.MEGABYTES;
+ }
+ if ("MB".equalsIgnoreCase(u)) {
+ return SizeUnit.MEGABYTES;
+ }
+ if ("M".equalsIgnoreCase(u)) {
+ return SizeUnit.MEGABYTES;
+ }
+
+ if ("GIGABYTES".equalsIgnoreCase(u)) {
+ return SizeUnit.GIGABYTES;
+ }
+ if ("GIGABYTE".equalsIgnoreCase(u)) {
+ return SizeUnit.GIGABYTES;
+ }
+ if ("GIGA".equalsIgnoreCase(u)) {
+ return SizeUnit.GIGABYTES;
+ }
+ if ("GB".equalsIgnoreCase(u)) {
+ return SizeUnit.GIGABYTES;
+ }
+ if ("G".equalsIgnoreCase(u)) {
+ return SizeUnit.GIGABYTES;
+ }
throw new IllegalArgumentException("Unknown size unit '" + u + "'");
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java
index 9a2fccd..91ff914 100644
--- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java
+++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/formatter/SimpleTomEEFormatterTest.java
@@ -1,81 +1,80 @@
-/**
- *
- * 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.tomee.jul.formatter;
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.junit.Test;
-
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-import static org.junit.Assert.assertEquals;
-
-public class SimpleTomEEFormatterTest {
- private static final String LINE_SEPARATOR_KEY = "line.separator";
-
- @Test
- public void formatNullThrown() throws Exception {
- final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
- try {
- final String lineSeparatorValue = "\n";
- final String logMessage = "An example log record";
- final Level level = Level.FINEST;
-
- System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
- final LogRecord logRecordInput = new LogRecord(level, logMessage);
- logRecordInput.setThrown(null);
-
- final Formatter formatter = new SimpleTomEEFormatter();
- final String actualFormatOutput = formatter.format(logRecordInput);
-
- final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n";
-
- assertEquals(expectedFormatOutput, actualFormatOutput);
- } finally {
- System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
- }
- }
-
- @Test
- public void formatNotNullThrown() throws Exception {
- final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
-
- try {
- final String lineSeparatorValue = "\n";
- final String logMessage = "An example log record";
- final Level level = Level.CONFIG;
- final String exceptionMessage = "An example exception";
- final Throwable thrown = new Exception(exceptionMessage);
-
- System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
- final LogRecord logRecordInput = new LogRecord(level, logMessage);
- logRecordInput.setThrown(thrown);
-
- final Formatter formatter = new SimpleTomEEFormatter();
- final String actualFormatOutput = formatter.format(logRecordInput);
-
- final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + lineSeparatorValue + ExceptionUtils.getStackTrace(thrown);
-
- assertEquals(expectedFormatOutput, actualFormatOutput);
- } finally {
- System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
- }
- }
-
-}
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.tomee.jul.formatter;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.junit.Test;
+
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import static org.junit.Assert.assertEquals;
+
+public class SimpleTomEEFormatterTest {
+ private static final String LINE_SEPARATOR_KEY = "line.separator";
+
+ @Test
+ public void formatNullThrown() throws Exception {
+ final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
+ try {
+ final String lineSeparatorValue = "\n";
+ final String logMessage = "An example log record";
+ final Level level = Level.FINEST;
+
+ System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
+ final LogRecord logRecordInput = new LogRecord(level, logMessage);
+ logRecordInput.setThrown(null);
+
+ final Formatter formatter = new SimpleTomEEFormatter();
+ final String actualFormatOutput = formatter.format(logRecordInput);
+
+ final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + "\n";
+
+ assertEquals(expectedFormatOutput, actualFormatOutput);
+ } finally {
+ System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
+ }
+ }
+
+ @Test
+ public void formatNotNullThrown() throws Exception {
+ final String previousLineSeparatorProperty = System.getProperty(LINE_SEPARATOR_KEY);
+
+ try {
+ final String lineSeparatorValue = "\n";
+ final String logMessage = "An example log record";
+ final Level level = Level.CONFIG;
+ final String exceptionMessage = "An example exception";
+ final Throwable thrown = new Exception(exceptionMessage);
+
+ System.setProperty(LINE_SEPARATOR_KEY, lineSeparatorValue);
+ final LogRecord logRecordInput = new LogRecord(level, logMessage);
+ logRecordInput.setThrown(thrown);
+
+ final Formatter formatter = new SimpleTomEEFormatter();
+ final String actualFormatOutput = formatter.format(logRecordInput);
+
+ final String expectedFormatOutput = level.getLocalizedName() + " - " + logMessage + lineSeparatorValue + ExceptionUtils.getStackTrace(thrown);
+
+ assertEquals(expectedFormatOutput, actualFormatOutput);
+ } finally {
+ System.setProperty(LINE_SEPARATOR_KEY, previousLineSeparatorProperty);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java
index 77da90b..ea78857 100644
--- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java
+++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/ArchivingTest.java
@@ -43,7 +43,7 @@ import static org.junit.Assert.assertTrue;
public class ArchivingTest {
@Parameterized.Parameters(name = "{0}")
public static String[][] formats() {
- return new String[][] { { "zip" }, { "gzip" } };
+ return new String[][]{{"zip"}, {"gzip"}};
}
@Parameterized.Parameter(0)
@@ -194,7 +194,9 @@ public class ArchivingTest {
return pathname.getName().startsWith("test");
}
}))) {
- file.delete();
+ if (!file.delete()) {
+ file.deleteOnExit();
+ }
}
}
}
@@ -207,7 +209,9 @@ public class ArchivingTest {
return pathname.getName().startsWith("test");
}
}))) {
- file.delete();
+ if (!file.delete()) {
+ file.deleteOnExit();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/LocalFileHandlerTest.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/LocalFileHandlerTest.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/LocalFileHandlerTest.java
index e17740d..2af3675 100644
--- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/LocalFileHandlerTest.java
+++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/LocalFileHandlerTest.java
@@ -50,7 +50,9 @@ public class LocalFileHandlerTest {
return pathname.getName().startsWith("test");
}
}))) {
- file.delete();
+ if(!file.delete()){
+ file.deleteOnExit();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/68119e24/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/PerfRunner.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/PerfRunner.java b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/PerfRunner.java
index 8ef6644..c4fd956 100644
--- a/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/PerfRunner.java
+++ b/tomee/tomee-juli/src/test/java/org/apache/tomee/jul/handler/rotating/PerfRunner.java
@@ -98,12 +98,12 @@ public class PerfRunner {
public static void main(final String[] args) throws RunnerException {
new Runner(new OptionsBuilder()
- .include(PerfRunner.class.getSimpleName())
- .forks(0)
- .warmupIterations(5)
- .measurementIterations(5)
- .threads(1)
- .build())
- .run();
+ .include(PerfRunner.class.getSimpleName())
+ .forks(0)
+ .warmupIterations(5)
+ .measurementIterations(5)
+ .threads(1)
+ .build())
+ .run();
}
}