use of java.util.logging.Handler in project hudson-2.x by hudson.
the class WeakLogHandler method setLevel.
@Override
public void setLevel(Level newLevel) throws SecurityException {
super.setLevel(newLevel);
Handler t = resolve();
if (t != null)
t.setLevel(newLevel);
}
use of java.util.logging.Handler in project cassandra-mesos-deprecated by mesosphere.
the class Main method main.
public static void main(final String[] args) {
int status;
try {
final Handler[] handlers = LogManager.getLogManager().getLogger("").getHandlers();
for (final Handler handler : handlers) {
handler.setLevel(Level.OFF);
}
org.slf4j.LoggerFactory.getLogger("slf4j-logging").debug("Installing SLF4JLogging");
SLF4JBridgeHandler.install();
status = _main();
} catch (final SystemExitException e) {
LOGGER.error(e.getMessage());
status = e.status;
} catch (final UnknownHostException e) {
LOGGER.error("Unable to resolve local interface for http server");
status = 6;
} catch (final Throwable e) {
LOGGER.error("Unhandled fatal exception", e);
status = 10;
}
System.exit(status);
}
use of java.util.logging.Handler in project cogtool by cogtool.
the class CogTool method enableLogging.
public static void enableLogging(boolean value) {
if (value) {
logger.setLevel(Level.ALL);
for (Handler h : logger.getHandlers()) {
if (h instanceof FileHandler) {
return;
}
}
FileHandler fh = null;
try {
fh = new FileHandler((CogToolPref.LOG_DIRECTORY.getString() + LOG_FILE_PATTERN), LOG_FILE_MAX_SIZE, LOG_FILES_MAX_COUNT, true);
} catch (IOException ex) {
logger.warning("Couldn't create log file: " + ex);
return;
}
fh.setFormatter(new Formatter() {
@Override
public String format(LogRecord r) {
long ms = r.getMillis();
return String.format("%tF %tT.%tL\t%s\n", ms, ms, ms, r.getMessage());
}
});
logger.addHandler(fh);
} else {
logger.setLevel(DEFAULT_LOG_LEVEL);
for (Handler h : logger.getHandlers()) {
if (!(h instanceof ConsoleHandler)) {
logger.removeHandler(h);
}
}
}
}
use of java.util.logging.Handler in project tomcat by apache.
the class ClassLoaderLogManager method addLogger.
// --------------------------------------------------------- Public Methods
/**
* Add the specified logger to the classloader local configuration.
*
* @param logger The logger to be added
*/
@Override
public synchronized boolean addLogger(final Logger logger) {
final String loggerName = logger.getName();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ClassLoaderLogInfo info = getClassLoaderInfo(classLoader);
if (info.loggers.containsKey(loggerName)) {
return false;
}
info.loggers.put(loggerName, logger);
// Apply initial level for new logger
final String levelString = getProperty(loggerName + ".level");
if (levelString != null) {
try {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
logger.setLevel(Level.parse(levelString.trim()));
return null;
}
});
} catch (IllegalArgumentException e) {
// Leave level set to null
}
}
// Always instantiate parent loggers so that
// we can control log categories even during runtime
int dotIndex = loggerName.lastIndexOf('.');
if (dotIndex >= 0) {
final String parentName = loggerName.substring(0, dotIndex);
Logger.getLogger(parentName);
}
// Find associated node
LogNode node = info.rootNode.findNode(loggerName);
node.logger = logger;
// Set parent logger
Logger parentLogger = node.findParentLogger();
if (parentLogger != null) {
doSetParentLogger(logger, parentLogger);
}
// Tell children we are their new parent
node.setParentLogger(logger);
// Add associated handlers, if any are defined using the .handlers property.
// In this case, handlers of the parent logger(s) will not be used
String handlers = getProperty(loggerName + ".handlers");
if (handlers != null) {
logger.setUseParentHandlers(false);
StringTokenizer tok = new StringTokenizer(handlers, ",");
while (tok.hasMoreTokens()) {
String handlerName = (tok.nextToken().trim());
Handler handler = null;
ClassLoader current = classLoader;
while (current != null) {
info = classLoaderLoggers.get(current);
if (info != null) {
handler = info.handlers.get(handlerName);
if (handler != null) {
break;
}
}
current = current.getParent();
}
if (handler != null) {
logger.addHandler(handler);
}
}
}
// Parse useParentHandlers to set if the logger should delegate to its parent.
// Unlike java.util.logging, the default is to not delegate if a list of handlers
// has been specified for the logger.
String useParentHandlersString = getProperty(loggerName + ".useParentHandlers");
if (Boolean.parseBoolean(useParentHandlersString)) {
logger.setUseParentHandlers(true);
}
return true;
}
use of java.util.logging.Handler in project tomcat by apache.
the class ClassLoaderLogManager method readConfiguration.
/**
* Load specified configuration.
*
* @param is InputStream to the properties file
* @param classLoader for which the configuration will be loaded
* @throws IOException If something wrong happens during loading
*/
protected synchronized void readConfiguration(InputStream is, ClassLoader classLoader) throws IOException {
ClassLoaderLogInfo info = classLoaderLoggers.get(classLoader);
try {
info.props.load(is);
} catch (IOException e) {
// Report error
System.err.println("Configuration error");
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// Ignore
}
}
// Create handlers for the root logger of this classloader
String rootHandlers = info.props.getProperty(".handlers");
String handlers = info.props.getProperty("handlers");
Logger localRootLogger = info.rootNode.logger;
if (handlers != null) {
StringTokenizer tok = new StringTokenizer(handlers, ",");
while (tok.hasMoreTokens()) {
String handlerName = (tok.nextToken().trim());
String handlerClassName = handlerName;
String prefix = "";
if (handlerClassName.length() <= 0) {
continue;
}
// "10WebappFooHandler.")
if (Character.isDigit(handlerClassName.charAt(0))) {
int pos = handlerClassName.indexOf('.');
if (pos >= 0) {
prefix = handlerClassName.substring(0, pos + 1);
handlerClassName = handlerClassName.substring(pos + 1);
}
}
try {
this.prefix.set(prefix);
Handler handler = (Handler) classLoader.loadClass(handlerClassName).newInstance();
// The specification strongly implies all configuration should be done
// during the creation of the handler object.
// This includes setting level, filter, formatter and encoding.
this.prefix.set(null);
info.handlers.put(handlerName, handler);
if (rootHandlers == null) {
localRootLogger.addHandler(handler);
}
} catch (Exception e) {
// Report error
System.err.println("Handler error");
e.printStackTrace();
}
}
}
}
Aggregations