use of java.util.logging.Handler in project tomee by apache.
the class LoggingJAXRSCommons method configureLoggin.
protected void configureLoggin() throws Exception {
msgs = new LinkedList<>();
final java.util.logging.Logger looger = getLooger();
looger.addHandler(new Handler() {
@Override
public void publish(final LogRecord record) {
synchronized (LoggingJAXRSCommons.this) {
msgs.add(record.getMessage());
}
}
@Override
public void flush() {
// no-op
}
@Override
public void close() throws SecurityException {
// no-op
}
public Collection getMsg() {
synchronized (LoggingJAXRSCommons.this) {
return msgs;
}
}
});
}
use of java.util.logging.Handler in project BKCommonLib by bergerhealer.
the class ModuleLogger method createDefaultLogger.
private static Logger createDefaultLogger() {
if (Bukkit.getServer() != null && Bukkit.getLogger() != MountiplexUtil.LOGGER)
return Bukkit.getLogger();
Logger log = Logger.getLogger("");
log.setUseParentHandlers(false);
CustomRecordFormatter formatter = new CustomRecordFormatter();
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(formatter);
for (Handler iHandler : log.getHandlers()) {
log.removeHandler(iHandler);
}
log.addHandler(consoleHandler);
return log;
}
use of java.util.logging.Handler in project MyPet by xXKeyleXx.
the class MyPetLogger method disableDebugLogger.
public void disableDebugLogger() {
for (Handler h : getHandlers()) {
if (h.toString().equals("MyPet-Debug-Logger-FileHandler")) {
removeHandler(h);
h.close();
}
}
}
use of java.util.logging.Handler in project cxf by apache.
the class Log4jLogger method getHandlers.
public synchronized Handler[] getHandlers() {
List<Handler> ret = new ArrayList<>();
Enumeration<?> en = log.getAllAppenders();
while (en.hasMoreElements()) {
Appender ap = (Appender) en.nextElement();
if (ap instanceof HandlerWrapper) {
ret.add(((HandlerWrapper) ap).getHandler());
}
}
return ret.toArray(new Handler[ret.size()]);
}
use of java.util.logging.Handler in project cxf by apache.
the class Slf4jLogger method internalLogFormatted.
@Override
protected void internalLogFormatted(String msg, LogRecord record) {
Level level = record.getLevel();
Throwable t = record.getThrown();
Handler[] targets = getHandlers();
if (targets != null) {
for (Handler h : targets) {
h.publish(record);
}
}
if (!getUseParentHandlers()) {
return;
}
/*
* As we can not use a "switch ... case" block but only a "if ... else if ..." block, the order of the
* comparisons is important. We first try log level FINE then INFO, WARN, FINER, etc
*/
if (Level.FINE.equals(level)) {
if (locationAwareLogger == null) {
logger.debug(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
}
} else if (Level.INFO.equals(level)) {
if (locationAwareLogger == null) {
logger.info(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.INFO_INT, msg, null, t);
}
} else if (Level.WARNING.equals(level)) {
if (locationAwareLogger == null) {
logger.warn(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.WARN_INT, msg, null, t);
}
} else if (Level.FINER.equals(level)) {
if (locationAwareLogger == null) {
logger.trace(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
}
} else if (Level.FINEST.equals(level)) {
if (locationAwareLogger == null) {
logger.trace(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.TRACE_INT, msg, null, t);
}
} else if (Level.ALL.equals(level)) {
// but not accessible by the API Logger.xxx() API
if (locationAwareLogger == null) {
logger.error(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
}
} else if (Level.SEVERE.equals(level)) {
if (locationAwareLogger == null) {
logger.error(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.ERROR_INT, msg, null, t);
}
} else if (Level.CONFIG.equals(level)) {
if (locationAwareLogger == null) {
logger.debug(msg, t);
} else {
locationAwareLogger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, msg, null, t);
}
} else if (Level.OFF.equals(level)) {
// don't log
}
}
Aggregations