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) { } }
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()))); }
/** * Initialize JUL logging with {@code logging-test.properties} file that is * accessible on classpath. * <p> * The purpose of this method is to add a conventional way of an easy override of the standard JUL * defaults. */ public static void initializeLogging() { if (System.getProperty("java.util.logging.config.file") == null) { try (InputStream stream = LoggingTestUtils.class.getResourceAsStream("/logging-test.properties")) { if (null != stream) { LogManager.getLogManager().readConfiguration(stream); } } catch (IOException e) { // ignored for now } } } }
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) { } }
public synchronized static void init() { if (loggingInitialized.get()) { return; } // Turn off unwanted loggers (evil libraries and such) disableUnwantedLoggers(); // Load logging.properties try { // Use file if exists, else use file embedded in JAR InputStream logConfigInputStream = Config.class.getResourceAsStream(LOG_PROPERTIES_JAR_RESOURCE); if (logConfigInputStream != null) { LogManager.getLogManager().readConfiguration(logConfigInputStream); } loggingInitialized.set(true); } catch (Exception e) { Logger.getAnonymousLogger().severe("Could not load logging.properties file from resource "+LOG_PROPERTIES_JAR_RESOURCE); Logger.getAnonymousLogger().severe(e.getMessage()); e.printStackTrace(); } }
public StreamRecording() throws IOException { // Clear and reload as the stream may have been cached. LogManager.getLogManager().reset(); LogManager.getLogManager().readConfiguration(); }
/** * 读取ClassPath下的logging.properties配置文件 */ private void readConfig() { //避免循环引用,Log初始化的时候不使用相关工具类 InputStream in = ResourceUtil.getStreamSafe("logging.properties"); if(null == in){ System.err.println("[WARN] Can not find [logging.properties], use [%JRE_HOME%/lib/logging.properties] as default!"); return; } try { LogManager.getLogManager().readConfiguration(in); } catch (Exception e) { Console.error(e, "Read [logging.properties] from classpath error!"); try { LogManager.getLogManager().readConfiguration(); } catch (Exception e1) { Console.error(e, "Read [logging.properties] from [%JRE_HOME%/lib/logging.properties] error!"); } } finally { IoUtil.close(in); } } }
/** * Reads default JUL configuration. */ private void defaultConfiguration() { final URL cfgUrl = U.resolveIgniteUrl(DFLT_CONFIG_PATH); if (cfgUrl == null) { warning("Failed to resolve default logging config file: " + DFLT_CONFIG_PATH); return; } try (InputStream in = cfgUrl.openStream()) { LogManager.getLogManager().readConfiguration(in); } catch (IOException e) { error("Failed to read logging configuration: " + cfgUrl, e); } cfg = cfgUrl.getPath(); }
/** * 读取ClassPath下的logging.properties配置文件 */ private void readConfig() { //避免循环引用,Log初始化的时候不使用相关工具类 InputStream in = ResourceUtil.getStreamSafe("logging.properties"); if(null == in){ System.err.println("[WARN] Can not find [logging.properties], use [%JRE_HOME%/lib/logging.properties] as default!"); return; } try { LogManager.getLogManager().readConfiguration(in); } catch (Exception e) { Console.error(e, "Read [logging.properties] from classpath error!"); try { LogManager.getLogManager().readConfiguration(); } catch (Exception e1) { Console.error(e, "Read [logging.properties] from [%JRE_HOME%/lib/logging.properties] error!"); } } finally { IoUtil.close(in); } } }
protected void loadConfiguration(String location, LogFile logFile) { Assert.notNull(location, "Location must not be null"); try { String configuration = FileCopyUtils.copyToString( new InputStreamReader(ResourceUtils.getURL(location).openStream())); if (logFile != null) { configuration = configuration.replace("${LOG_FILE}", StringUtils.cleanPath(logFile.toString())); } LogManager.getLogManager().readConfiguration( new ByteArrayInputStream(configuration.getBytes())); } catch (Exception ex) { throw new IllegalStateException( "Could not initialize Java logging from " + location, ex); } }
readConfiguration(new BufferedInputStream(input)); } finally { IoUtils.closeQuietly(input);
public static void main(String[] args) throws Exception { LogManager.getLogManager().readConfiguration(H264AACExample.class.getResourceAsStream("/log.properties"));
LogManager.getLogManager().readConfiguration(finp); finp.close();
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) { } }
String logFile = System.getProperty("java.util.logging.config.file"); if(logFile == null){ LogManager.getLogManager().readConfiguration(ReportGenerator.class.getClassLoader().getResourceAsStream("logging.properties")); } Logger logger = Logger.getLogger(ReportGenerator.class.getName()); logger.log(Level.INFO, "LOG THIS");
public StreamRecording() throws IOException { // Clear and reload as the stream may have been cached. LogManager.getLogManager().reset(); LogManager.getLogManager().readConfiguration(); }