use of java.util.logging.Handler in project simple-java by angryziber.
the class JavaUtilLoggerRedirector method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// remove default handlers
Logger rootLogger = LogManager.getLogManager().getLogger("");
for (Handler handler : rootLogger.getHandlers()) {
rootLogger.removeHandler(handler);
}
// install redirecting handler
SLF4JBridgeHandler.install();
}
use of java.util.logging.Handler in project gfm_viewer by satyagraha.
the class LogManager method configChanged.
@EventSubscriber(eventClass = Config.Changed.class)
public void configChanged(Config.Changed configChanged) {
Level level = debugging || config.useEclipseConsole() ? Level.FINE : Level.INFO;
logger.setLevel(level);
if (consoleHandler == null) {
consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(formatter);
logger.addHandler(consoleHandler);
}
if (logConsoleHandler == null && config.useEclipseConsole()) {
LogConsole.start(GFM_CONSOLE);
logConsoleHandler = LogConsole.getInstance().createHandler(formatter);
logger.addHandler(logConsoleHandler);
}
for (Handler handler : logger.getHandlers()) {
handler.setLevel(level);
}
}
use of java.util.logging.Handler in project mysql_perf_analyzer by yahoo.
the class MyPerfContext method configureLogging.
private void configureLogging() {
Logger logger = Logger.getLogger("");
try {
logger.setLevel(Level.parse(getLogLevel()));
} catch (Exception ex) {
logger.setLevel(Level.INFO);
}
try {
for (Handler h : logger.getHandlers()) {
if (h instanceof java.util.logging.ConsoleHandler)
h.setLevel(Level.SEVERE);
}
String logRoot = System.getProperty("logPath", ".");
java.util.logging.FileHandler fileHandler = new java.util.logging.FileHandler(logRoot + File.separatorChar + getLogPath(), this.logFileSize, this.logFileCount);
fileHandler.setLevel(logger.getLevel());
fileHandler.setFormatter(new SimpleFormatter());
logger.addHandler(fileHandler);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class ClientLogManager method addRemoteHandler.
/**
* Attaches a remote log handler to the given logger, if remote logging has not been suppressed.
*
* Note that this method does not require <code>logger</code> to be
* already registered in {@linkplain #loggers}, but if it is,
* then the new AcsLoggingHandler is set in the map's AcsLoggerInfo as well.
*
* @param logger logger to be set up for remote logging
* @return the remote handler that was added to the logger.
*/
private AcsLoggingHandler addRemoteHandler(AcsLogger logger) {
AcsLoggingHandler remoteHandler = null;
synchronized (loggers) {
String loggerName = logger.getLoggerName();
AcsLoggerInfo loggerInfo = loggers.get(loggerName);
// logQueue == null serves as indicator for remote log suppression
if (logQueue != null) {
// try to find an existing handler
for (Handler handler : logger.getHandlers()) {
if (handler instanceof AcsLoggingHandler) {
remoteHandler = (AcsLoggingHandler) handler;
if (loggerInfo != null && !remoteHandler.equals(loggerInfo.remoteHandler)) {
logger.info("Remote logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
}
break;
}
}
if (remoteHandler == null) {
// subscribes to sharedLogConfig
remoteHandler = new AcsLoggingHandler(logQueue, sharedLogConfig, loggerName, logThrottle);
logger.addHandler(remoteHandler);
if (loggerInfo != null && loggerInfo.remoteHandler != null) {
logger.info("Logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
}
}
}
if (loggerInfo != null) {
loggerInfo.remoteHandler = remoteHandler;
}
}
return remoteHandler;
}
use of java.util.logging.Handler in project ACS by ACS-Community.
the class ClientLogManager method addLocalHandler.
/**
* Adds a local logging handler to the provided logger. Unlike with remote handlers in
* {@link #prepareRemoteLogging()}, for local handlers we don't allow removing and re-adding the handlers later.
* <p>
* Note that this method does not require <code>logger</code> to be already registered in {@linkplain #loggers}, but
* if it is, then the new StdOutConsoleHandler is set in the map's AcsLoggerInfo as well.
*
* @param logger
* logger to be set up for local logging
* @return the local handler that was added to the logger.
*/
protected StdOutConsoleHandler addLocalHandler(AcsLogger logger) {
StdOutConsoleHandler localHandler = null;
synchronized (loggers) {
String loggerName = logger.getLoggerName();
AcsLoggerInfo loggerInfo = loggers.get(loggerName);
// try to find an existing handler (should not happen)
for (Handler handler : logger.getHandlers()) {
if (handler instanceof StdOutConsoleHandler) {
localHandler = (StdOutConsoleHandler) handler;
if (loggerInfo != null && !localHandler.equals(loggerInfo.localHandler)) {
logger.info("Stdout logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
}
break;
}
}
if (localHandler == null) {
localHandler = createStdOutConsoleHandlerWithFormatter(sharedLogConfig, loggerName, logThrottle);
logger.addHandler(localHandler);
if (loggerInfo != null && loggerInfo.localHandler != null) {
logger.info("Logging handler mismatch resolved for '" + loggerName + "'. Should be reported to ACS developers");
}
}
if (loggerInfo != null) {
loggerInfo.localHandler = localHandler;
}
}
return localHandler;
}
Aggregations