Skip to content

Commit

Permalink
PAYARA-2512 Ensure formatter added to handler correctly on reading lo…
Browse files Browse the repository at this point in the history
…g config (#2418)

* PAYARA-2512 ensure root handlers are given the correct formatter

* PAYARA-2512 stop adding ANSI color to the bracket
  • Loading branch information
smillidge authored and arjantijms committed Feb 18, 2018
1 parent 32f07aa commit 0298983
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
Expand Up @@ -89,6 +89,8 @@
import fish.payara.nucleus.requesttracing.RequestTracingService;
import java.io.FileNotFoundException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -1532,11 +1534,21 @@ private void resetLogging() {
}

System.setProperty("java.util.logging.config.file", runtimeDir.getLoggingProperties().getAbsolutePath());
try {
LogManager.getLogManager().readConfiguration();
} catch (SecurityException | IOException ex) {
try (InputStream is = new FileInputStream(runtimeDir.getLoggingProperties())){
LogManager.getLogManager().readConfiguration(is);

// go through all root handlers and set formatters based on properties
Logger rootLogger = LogManager.getLogManager().getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
String formatter = LogManager.getLogManager().getProperty(handler.getClass().getCanonicalName()+".formatter");
if (formatter != null) {
handler.setFormatter((Formatter) Class.forName(formatter).newInstance());
}
}

} catch (SecurityException | IOException | ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
LOGGER.log(Level.SEVERE, "Unable to reset the log manager", ex);
}
}
} else { // system property was not set on the command line using the command option or via -D
// we are likely using our default properties file so see if we need to rewrite it
if (logToFile) {
Expand Down Expand Up @@ -1567,8 +1579,8 @@ private void resetLogging() {
}
}
System.setProperty("java.util.logging.config.file", runtimeDir.getLoggingProperties().getAbsolutePath());
try {
LogManager.getLogManager().readConfiguration();
try (InputStream is = new FileInputStream(runtimeDir.getLoggingProperties())){
LogManager.getLogManager().readConfiguration(is);

// reset the formatters on the two handlers
//Logger rootLogger = Logger.getLogger("");
Expand Down
Expand Up @@ -221,17 +221,16 @@ private String odlLogFormat(LogRecord record) {

// Adding messageType
Level logLevel = record.getLevel();
recordBuffer.append(FIELD_BEGIN_MARKER);
if (color()) {
recordBuffer.append(getColor(logLevel));
}
recordBuffer.append(FIELD_BEGIN_MARKER);
String odlLevel = logLevel.getLocalizedName();
} String odlLevel = logLevel.getLocalizedName();
logEvent.setLevel(odlLevel);
recordBuffer.append(odlLevel);
recordBuffer.append(FIELD_END_MARKER);
if (color()) {
recordBuffer.append(getReset());
}
recordBuffer.append(FIELD_END_MARKER);
recordBuffer.append(getRecordFieldSeparator() != null ? getRecordFieldSeparator() : FIELD_SEPARATOR);

// Adding message ID
Expand Down
@@ -1,20 +1,45 @@
/*
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2016 Payara Foundation. All rights reserved.
The contents of this file are subject to the terms of the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.
When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.
*/
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2017-2018 Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package fish.payara.enterprise.server.logging;

import com.sun.common.util.logging.GFLogRecord;
import com.sun.enterprise.server.logging.AnsiColorFormatter;
import com.sun.enterprise.server.logging.ExcludeFieldsSupport;
import com.sun.enterprise.server.logging.FormatterDelegate;
import com.sun.enterprise.server.logging.LogEvent;
Expand Down

0 comments on commit 0298983

Please sign in to comment.