/** * Initialize log4j, including setting the web app root system property. * * @param servletContext * the current ServletContext * @see WebUtils#setWebAppRootSystemProperty */ public static void initLogging(ServletContext servletContext, Resource resource) { // Perform actual log4j initialization; else rely on log4j's default // initialization. try { String path = resource.getFile().getAbsolutePath(); // Write log message to server log. servletContext.log("Initializing log4j from [" + path + "]"); Log4jConfigurer.initLogging(path, LOG4J_REFRESH_MS); } catch (FileNotFoundException ex) { throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage()); } catch (IOException ioEx) { throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ioEx.getMessage()); } }
public void contextInitialized(ServletContextEvent sce) { try { Log4jConfigurer.initLogging("classpath:log4j.properties"); } catch (FileNotFoundException e) { throw new RuntimeException("Failed to start sample application.", e); } Object o = sce.getServletContext().getAttribute("JETTYSERVER_TESTMODE"); boolean testMode = false; if (o != null) { testMode = Boolean.valueOf((String) o); } LOG.info("Travel webapp starting up in " + (testMode ? "test" : "normal") + " mode"); // this loads up the Spring context TravelServiceLocator.initialize(testMode); }
private void _init_logging() { // allow for local file config final File loggingConfig = new File(startupDir, "logging.properties"); final String loggingPath; if (loggingConfig.exists()) { loggingPath = "file:" + loggingConfig.getAbsolutePath(); } else { loggingPath = "classpath:org/signalml/app/logging/log4j_app.properties"; } try { Log4jConfigurer.initLogging(loggingPath); } catch (FileNotFoundException ex) { System.err.println("Critical error: no logging configuration"); System.exit(1); } }
/** * 快速重新启动Application * @see 通常用Main函数启动JettyServer后,若改动项目的代码,那就需要停止再启动Jetty * @see 虽免去了Tomcat重新打包几十兆的消耗,但比起PHP完全不用重启来说还是慢,特别是关闭,启动一个新的JVM,消耗不小 * @see 所以我们可以在Main()中捕捉到回车后调用此函数,即可重新载入应用(包括Spring配置文件) * @param server 当前运行的JettyServer实例 * @param classPath 当前运行的Web应用的classpath */ @SuppressWarnings("unused") private static /*synchronized*/ void reloadContext(Server server, String classPath) throws Exception{ WebAppContext context = (WebAppContext)server.getHandler(); System.out.println("Application reloading..开始"); context.stop(); WebAppClassLoader classLoader = new WebAppClassLoader(context); classLoader.addClassPath(classPath); context.setClassLoader(classLoader); //根据给定的配置文件初始化日志配置(否则应用重载后日志输出组件就会失效) Log4jConfigurer.initLogging(classPath + "/log4j.properties"); context.start(); System.out.println("Application reloading..完毕"); }
/** * Shut down log4j, properly releasing all file locks * and resetting the web app root system property. * @param servletContext the current ServletContext * @see WebUtils#removeWebAppRootSystemProperty */ public static void shutdownLogging(ServletContext servletContext) { servletContext.log("Shutting down log4j"); try { Log4jConfigurer.shutdownLogging(); } finally { // Remove the web app root system property. if (exposeWebAppRoot(servletContext)) { WebUtils.removeWebAppRootSystemProperty(servletContext); } } }
public void init() { try { Log4jConfigurer.initLogging(location, refreshInterval); } catch (FileNotFoundException e) { e.printStackTrace(); } }
@Bean(name = "log4jInitialization") public MethodInvoker log4j() { MethodInvokingFactoryBean methodInvoker = new MethodInvokingFactoryBean(); methodInvoker.setTargetClass(Log4jConfigurer.class); methodInvoker.setTargetMethod("initLogging"); methodInvoker.setArguments(getLog4jArgs()); return methodInvoker; }
public void setLog4jConfigLocation(String log4jConfigLocation) { this.log4jConfigLocation = log4jConfigLocation; try { Log4jConfigurer.initLogging(log4jConfigLocation); } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
@Override public void contextDestroyed(ServletContextEvent sce) { LOG.info("Shutting down Kuali Rice..."); if (context != null) { context.close(); } LOG.info("...completed shutdown of Kuali Rice."); Log4jConfigurer.shutdownLogging(); }
protected void loadConfiguration(String location, LogFile logFile) { Assert.notNull(location, "Location must not be null"); if (logFile != null) { logFile.applyToSystemProperties(); } try { Log4jConfigurer.initLogging(location); } catch (Exception ex) { throw new IllegalStateException( "Could not initialize Log4J logging from " + location, ex); } }
/** * 无参构造方法,初始化log4j */ public AbstractTestng() { try { Log4jConfigurer.initLogging("classpath:log/log4j.xml", 60000); } catch (FileNotFoundException e) { LOGGER.info(ExceptionUtils.getStackTrace(e)); } }
/** * constructor */ public AbstractTestng() { try { Log4jConfigurer.initLogging("classpath:log/log4j.xml", 60000); } catch (FileNotFoundException e) { LOGGER.info(ExceptionUtils.getStackTrace(e)); } }
/** * construct */ public AbstractTestng() { try { Log4jConfigurer.initLogging("classpath:log/log4j.xml", 60000); } catch (FileNotFoundException e) { LOGGER.info(ExceptionUtils.getStackTrace(e)); } }
public static void restoreDefaults() throws Exception { registryManager.removeAllRegistryEntries(); LogManager.resetConfiguration(); try { String logFile = CarbonUtils.getCarbonConfigDirPath() + RegistryConstants.PATH_SEPARATOR + "log4j.properties"; Log4jConfigurer.initLogging(logFile); } catch (FileNotFoundException e) { String msg = "Cannot restore default logging configuration." + " log4j.properties file is not found in the classpath"; throw new LogViewerException(msg, e); } }
public static void loadConfig(String filename) throws FileNotFoundException { if (filename != null) { LogManager.resetConfiguration(); Log4jConfigurer.initLogging(filename); } }
public static void loadConfig(String filename, long refreshInterval) throws FileNotFoundException { if (filename != null) { LogManager.resetConfiguration(); Log4jConfigurer.initLogging(filename,refreshInterval); } }
/** * 初始化log4j和Spring配置 */ public final synchronized static void init() { try { Log4jConfigurer.initLogging(RmPathHelper.getWarName() + "/WEB-INF/config/log4j/log4j.properties"); } catch (FileNotFoundException e) { throw new RuntimeException(e); } RmBeanFactory.getBeanFactory(); }
public void destroy() { Log4jConfigurer.shutdownLogging(); }
/** * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Properties properties = new Properties(); System.setProperty("project.home", ConfigUtil.filter("${project.home:.}", System.getProperties())); String projectHome = System.getProperty("project.home"); properties.load(new FileInputStream(new File(ConfigUtil.filter("${project.home:.}", System.getProperties()), "application.properties"))); ConfigUtil.addProperties(properties); __INIT_LOG: { String logbackConf = System.getProperty("logback.configurationFile", "${project.home}/conf/logback.xml"); logbackConf = ConfigUtil.filter(logbackConf, System.getProperties()); File logbackFile = new File(logbackConf); if (logbackFile.exists()) { System.out.println("Log system load configuration form " + logbackConf); System.setProperty("logback.configurationFile", logbackConf); break __INIT_LOG; } String log4jConf = System.getProperty("log4j.configuration", "${project.home}/conf/log4j.xml"); log4jConf = ConfigUtil.filter(log4jConf, System.getProperties()); File log4jFile = new File(log4jConf); if (!log4jFile.exists()) { log4jConf = System.getProperty("log4j.configuration", "${project.home}/conf/log4j.properties"); log4jConf = ConfigUtil.filter(log4jConf, System.getProperties()); log4jFile = new File(log4jConf); } if (log4jFile.exists()) { try { System.setProperty("log4j.configuration", log4jConf); System.out.println("Log system load configuration form " + log4jConf); Log4jConfigurer.initLogging(log4jConf, 30 * 1000); try { Thread.sleep(2000); } catch (InterruptedException e) { } break __INIT_LOG; } catch (FileNotFoundException e1) { // INGORE } } } VenusJettyServer server = new VenusJettyServer(); server.setContextPath(ConfigUtil.filter("${webapp.context:/}").toString()); server.setWebapp(ConfigUtil.filter("${webapp.dir:" + projectHome + "/webapp}").toString()); server.setPort(Integer.parseInt(ConfigUtil.filter("${webapp.port:8080}").toString())); server.start(); }
@Override public void start() throws Exception { // obtain the root workflow config Config config = ConfigContext.getCurrentContextConfig(); boolean log4jFileExists = checkPropertiesFileExists(config.getProperty(Config.LOG4J_SETTINGS_PATH)); // first check for in-line xml configuration String log4jconfig = config.getProperty(Config.LOG4J_SETTINGS_XML); if (log4jconfig != null) { try { DocumentBuilder b = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = b.parse(new ByteArrayInputStream(log4jconfig.getBytes())); DOMConfigurator.configure(doc.getDocumentElement()); // now get the reconfigured log instance log = Logger.getLogger(getClass()); } catch (Exception e) { log.error("Error parsing Log4J configuration settings: " + log4jconfig, e); } // next check for in-line properties configuration } else if ((log4jconfig = config.getProperty(Config.LOG4J_SETTINGS_PROPS)) != null) { Properties p = new Properties(config.getProperties()); try { p.load(new ByteArrayInputStream(log4jconfig.getBytes())); PropertyConfigurator.configure(p); log = Logger.getLogger(getClass()); } catch (IOException ioe) { log.error("Error loading Log4J configuration settings: " + log4jconfig, ioe); } // check for an external file location specification } else if (log4jFileExists) { log.info("Configuring Log4J logging."); log4jconfig = config.getProperty(Config.LOG4J_SETTINGS_PATH); int reloadInterval = DEFAULT_RELOAD_INTERVAL; String log4jReloadInterval = config.getProperty(Config.LOG4J_SETTINGS_RELOADINTERVAL_MINS); if (log4jReloadInterval != null) { try { reloadInterval = Integer.parseInt(log4jReloadInterval) * MINUTE; } catch (NumberFormatException nfe) { log.warn("Invalid reload interval: " + log4jReloadInterval + ", using default: " + DEFAULT_RELOAD_INTERVAL + " milliseconds"); } } Log4jConfigurer.initLogging(log4jconfig, reloadInterval); log = Logger.getLogger(getClass()); } else { Log4jConfigurer.initLogging(AUTOMATIC_LOGGING_CONFIG_URL); log = Logger.getLogger(getClass()); } super.start(); }
public static void main(String[] args) throws TddlException, SQLException, FileNotFoundException { Log4jConfigurer.initLogging("src/main/resources/log4j.properties"); TDataSource ds = new TDataSource(); // 设置默认db(ob) ds.setAppName("DEV_DPS_APP"); ds.setTopologyFile("tddl-topology-dps.xml"); ds.setRuleFile("tddl-rule-dps-nonmysql.xml"); // 设置simba2的mysql App subApp = new App(); subApp.setAppName("DAILY_SOLAR_MERCURY_APP"); subApp.setRuleFile("tddl-rule-dps-simba2-mysql.xml"); ds.addSubApp(subApp); // 添加subway的mysql subApp = new App(); subApp.setAppName("DEV_SUBWAY_MYSQL"); subApp.setRuleFile("tddl-rule-dps-subway-mysql.xml"); ds.addSubApp(subApp); Map cp = new HashMap(); cp.put("ALLOW_TEMPORARY_TABLE", "True"); cp.put(ConnectionProperties.TEMP_TABLE_DIR, ".\\temp\\"); cp.put(ConnectionProperties.TEMP_TABLE_CUT_ROWS, false); cp.put(ConnectionProperties.TEMP_TABLE_MAX_ROWS, 1000); ds.setConnectionProperties(cp); ds.init(); System.out.println("init done"); // subway_adgroup_list.sql // solar_adgroup_list.sql String sql = SqlFileUtil.getSql("replace.txt"); // sql = SqlFileUtil.getSql("solar_adgroup_list.sql"); Connection conn = ds.getConnection(); { PreparedStatement ps = conn.prepareStatement(sql); long start = System.currentTimeMillis(); ResultSet rs = ps.executeQuery(); while (rs.next()) { StringBuilder sb = new StringBuilder(); int count = rs.getMetaData().getColumnCount(); for (int i = 1; i <= count; i++) { String key = rs.getMetaData().getColumnLabel(i); Object val = rs.getObject(i); sb.append("[" + rs.getMetaData().getTableName(i) + "." + key + "->" + val + "]"); } System.out.println(sb.toString()); } System.out.println("done " + (System.currentTimeMillis() - start)); rs.close(); ps.close(); } conn.close(); }
/** * Shut down log4j, properly releasing all file locks and resetting the web * app root system property. * * @param servletContext * the current ServletContext * @see WebUtils#removeWebAppRootSystemProperty */ public static void shutdownLogging(ServletContext servletContext) { servletContext.log("Shutting down log4j"); Log4jConfigurer.shutdownLogging(); }