public static void loadConfig() { try (InputStream is = JULLogDelegateFactory.class.getClassLoader().getResourceAsStream("vertx-default-jul-logging.properties")) { if (is != null) { LogManager.getLogManager().readConfiguration(is); } } catch (IOException ignore) { } }
public JdkLoggerAdapter() { try { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("logging.properties"); if (in != null) { LogManager.getLogManager().readConfiguration(in); } else { System.err.println("No such logging.properties in classpath for jdk logging config!"); } } catch (Throwable t) { System.err.println("Failed to load logging.properties in classpath for jdk logging config, cause: " + t.getMessage()); } try { Handler[] handlers = java.util.logging.Logger.getLogger(GLOBAL_LOGGER_NAME).getHandlers(); for (Handler handler : handlers) { if (handler instanceof FileHandler) { FileHandler fileHandler = (FileHandler) handler; Field field = fileHandler.getClass().getField("files"); File[] files = (File[]) field.get(fileHandler); if (files != null && files.length > 0) { file = files[0]; } } } } catch (Throwable t) { } }
public JdkLoggerAdapter() { try { InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("logging.properties"); if (in != null) { LogManager.getLogManager().readConfiguration(in); } else { System.err.println("No such logging.properties in classpath for jdk logging config!"); } } catch (Throwable t) { System.err.println("Failed to load logging.properties in classpath for jdk logging config, cause: " + t.getMessage()); } try { Handler[] handlers = java.util.logging.Logger.getLogger(GLOBAL_LOGGER_NAME).getHandlers(); for (Handler handler : handlers) { if (handler instanceof FileHandler) { FileHandler fileHandler = (FileHandler) handler; Field field = fileHandler.getClass().getField("files"); File[] files = (File[]) field.get(fileHandler); if (files != null && files.length > 0) { file = files[0]; } } } } catch (Throwable t) { } }
/** * Work around for bug 6935026. */ public List<String> getLoggerNames() { while (true) { try { List<String> r = new ArrayList<String>(); Enumeration<String> e = LogManager.getLogManager().getLoggerNames(); while (e.hasMoreElements()) r.add(e.nextElement()); return r; } catch (ConcurrentModificationException e) { // retry } } }
public static void resetJUL() { LogManager.getLogManager().reset(); }
private static java.util.logging.Logger rootJULLogger() { return LogManager.getLogManager().getLogger( "" ); }
final InputStream inputStream = Main.class.getResourceAsStream("/logging.properties"); try { LogManager.getLogManager().readConfiguration(inputStream); } catch (final IOException e) { Logger.getAnonymousLogger().severe("Could not load default logging.properties file"); Logger.getAnonymousLogger().severe(e.getMessage()); }
private static void configLogger(String out) throws IOException { File outDir = new File(out); if (!outDir.exists()) { outDir.mkdirs(); } StringBuilder sb = new StringBuilder(); sb.append("handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler\n"); sb.append(".level=SEVERE\n"); sb.append("edu.stanford.nlp.level=INFO\n"); sb.append("java.util.logging.ConsoleHandler.level=SEVERE\n"); sb.append("java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter\n"); sb.append("java.util.logging.FileHandler.level=INFO\n"); sb.append("java.util.logging.FileHandler.pattern=" + out + "/err.log" + "\n"); LogManager.getLogManager().readConfiguration(new ReaderInputStream(new StringReader(sb.toString()))); }
private static int loggerIntProperty(String name, int def) { String val = LogManager.getLogManager().getProperty(name); if (val == null) { return def; } try { return Integer.parseInt(val); } catch (NumberFormatException e) { return def; } }
public void resetJULLevels() { LogManager lm = LogManager.getLogManager(); Enumeration<String> e = lm.getLoggerNames(); while (e.hasMoreElements()) { String loggerName = e.nextElement(); java.util.logging.Logger julLogger = lm.getLogger(loggerName); if (JULHelper.isRegularNonRootLogger(julLogger) && julLogger.getLevel() != null) { addInfo("Setting level of jul logger [" + loggerName + "] to null"); julLogger.setLevel(null); } } }
private static LoggerProvider tryJBossLogManager(final ClassLoader cl, final String via) throws ClassNotFoundException { final Class<? extends LogManager> logManagerClass = LogManager.getLogManager().getClass(); if (logManagerClass == Class.forName("org.jboss.logmanager.LogManager", false, cl) && Class.forName("org.jboss.logmanager.Logger$AttachmentKey", true, cl).getClassLoader() == logManagerClass.getClassLoader()) { final LoggerProvider provider = new JBossLogManagerProvider(); logProvider(provider, via); return provider; } throw new IllegalStateException(); }
public StreamRecording() throws IOException { // Clear and reload as the stream may have been cached. LogManager.getLogManager().reset(); LogManager.getLogManager().readConfiguration(); }
private void initLogger() { java.util.logging.Logger rootLogger = java.util.logging.LogManager.getLogManager().getLogger(""); for (java.util.logging.Handler h : rootLogger.getHandlers()) rootLogger.removeHandler(h); SLF4JBridgeHandler.install(); }
@Restricted(NoExternalUse.class) public AutoCompletionCandidates doAutoCompleteLoggerName(@QueryParameter String value) { if (value == null) { return new AutoCompletionCandidates(); } // get names of all actual loggers known to Jenkins Set<String> candidateNames = new LinkedHashSet<>(getAutoCompletionCandidates(Collections.list(LogManager.getLogManager().getLoggerNames()))); for (String part : value.split("[ ]+")) { HashSet<String> partCandidates = new HashSet<>(); String lowercaseValue = part.toLowerCase(Locale.ENGLISH); for (String loggerName : candidateNames) { if (loggerName.toLowerCase(Locale.ENGLISH).contains(lowercaseValue)) { partCandidates.add(loggerName); } } candidateNames.retainAll(partCandidates); } AutoCompletionCandidates candidates = new AutoCompletionCandidates(); candidates.add(candidateNames.toArray(MemoryReductionUtil.EMPTY_STRING_ARRAY)); return candidates; }
/** * Adds a SLF4JBridgeHandler instance to jul's root logger. * <p/> * <p/> * This handler will redirect j.u.l. logging to SLF4J. However, only logs enabled * in j.u.l. will be redirected. For example, if a log statement invoking a * j.u.l. logger is disabled, then the corresponding non-event will <em>not</em> * reach SLF4JBridgeHandler and cannot be redirected. */ public static void install() { LogManager.getLogManager().getLogger("").addHandler(new SLF4JBridgeHandler()); }
/** * Closes this handler. The tail string of the formatter associated with * this handler is written out. A flush operation and a subsequent close * operation is then performed upon the output stream. Client applications * should not use a handler after closing it. */ @Override public void close() { LogManager.getLogManager().checkAccess(); close(true); }
/** * Sets the formatter to be used by this handler. * * @param newFormatter * the formatter to set. * @throws NullPointerException * if {@code newFormatter} is {@code null}. */ public void setFormatter(Formatter newFormatter) { LogManager.getLogManager().checkAccess(); internalSetFormatter(newFormatter); }
private void init(String p, Boolean a, Integer l, Integer c) throws IOException { // check access manager = LogManager.getLogManager(); manager.checkAccess(); initProperties(p, a, l, c); initOutputFiles(); }
@Before public void setUp() throws IOException { cli = new VertxCommandLauncher(); output = new ByteArrayOutputStream(); error = new ByteArrayOutputStream(); // We need to reset the log configuration to recreate the logger // Indeed print stream may have been cached. LogManager.getLogManager().reset(); JULLogDelegateFactory.loadConfig(); }
public LoggerContextListener enableJulChangePropagation(LoggerContext loggerContext) { LogManager.getLogManager().reset(); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); LevelChangePropagator propagator = new LevelChangePropagator(); propagator.setContext(loggerContext); propagator.setResetJUL(true); propagator.start(); loggerContext.addListener(propagator); return propagator; }