use of com.sun.enterprise.server.logging.ODLLogFormatter in project Payara by payara.
the class GFLauncherLogger method addLogFileHandler.
/**
* IMPORTANT! The server's logfile is added to the *local* logger. But it is
* never removed. The files are kept open by the logger. One really bad
* result is that Windows will not be able to delete that server after
* stopping it. Solution: remove the file handler when done.
*
* @param logFile The logfile
* @throws GFLauncherException if the info object has not been setup
*/
static synchronized void addLogFileHandler(String logFile, GFLauncherInfo info) throws GFLauncherException {
try {
if (logFile == null || logfileHandler != null) {
return;
}
logfileHandler = new FileHandler(logFile, true);
logfileHandler.setFormatter(new ODLLogFormatter());
logfileHandler.setLevel(Level.INFO);
logger.addHandler(logfileHandler);
} catch (IOException e) {
// should be seen in verbose and watchdog modes for debugging
e.printStackTrace();
}
}
use of com.sun.enterprise.server.logging.ODLLogFormatter in project Payara by payara.
the class PayaraMicroImpl method resetLogging.
private void resetLogging() {
String loggingProperty = System.getProperty("java.util.logging.config.file");
if (loggingProperty != null) {
// we need to copy into the unpacked domain the specified logging.properties file
File file = new File(loggingProperty);
if (file.canRead()) {
try {
runtimeDir.setLoggingProperties(file);
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Could not copy over logging properties file", ex);
}
}
if (logToFile) {
LOGGER.log(Level.WARNING, "logToFile command line option ignored as a logging.properties file has been provided");
}
System.setProperty("java.util.logging.config.file", runtimeDir.getLoggingProperties().getAbsolutePath());
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 {
// we are likely using our default properties file so see if we need to rewrite it
if (logToFile) {
// we need to reset our logging properties to use the file handler as well
// read the default properties and then add the file handler properties
Properties currentProps = new Properties();
try (InputStream is = new FileInputStream(runtimeDir.getLoggingProperties())) {
currentProps.load(is);
// add file handler properties
currentProps.setProperty("java.util.logging.FileHandler.pattern", userLogFile);
currentProps.setProperty("handlers", "java.util.logging.FileHandler, java.util.logging.ConsoleHandler");
currentProps.setProperty("java.util.logging.FileHandler.limit", "1024000");
currentProps.setProperty("java.util.logging.FileHandler.count", "10");
currentProps.setProperty("java.util.logging.FileHandler.level", "INFO");
currentProps.setProperty("java.util.logging.FileHandler.formatter", "java.util.logging.SimpleFormatter");
currentProps.setProperty("java.util.logging.FileHandler.append", "true");
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load the logging properties from the runtime directory", ex);
}
// now write them back
try (OutputStream os = new FileOutputStream(runtimeDir.getLoggingProperties())) {
currentProps.store(os, "Generated Logging properties file from Payara Micro log to file option");
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to load the logging properties from the runtime directory", ex);
}
}
System.setProperty("java.util.logging.config.file", runtimeDir.getLoggingProperties().getAbsolutePath());
try (InputStream is = new FileInputStream(runtimeDir.getLoggingProperties())) {
LogManager.getLogManager().readConfiguration(is);
// reset the formatters on the two handlers
// Logger rootLogger = Logger.getLogger("");
String formatter = LogManager.getLogManager().getProperty("java.util.logging.ConsoleHandler.formatter");
Formatter formatterClass = new ODLLogFormatter();
try {
formatterClass = (Formatter) Class.forName(formatter).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
LOGGER.log(Level.SEVERE, "Specified Formatter class could not be loaded " + formatter, ex);
}
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
handler.setFormatter(formatterClass);
}
} catch (SecurityException | IOException ex) {
LOGGER.log(Level.SEVERE, "Unable to reset the log manager", ex);
}
}
}
Aggregations