Java Code Examples for org.springframework.util.Log4jConfigurer

The following examples show how to use org.springframework.util.Log4jConfigurer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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);
}
 
Example 2
@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();
}
 
Example 3
public void makeWorkingDir(File repoFolder) throws IOException {
	repoFolder.mkdirs();
	repoFolder.mkdir();

	File dbDir = new File(repoFolder, "db");
	FileUtils.forceMkdir(dbDir);

	// build phisically the working directory
	// and change settings config
	String docDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/docs/");
	FileUtils.forceMkdir(new File(docDir));
	String indexDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/index/");
	FileUtils.forceMkdir(new File(indexDir));
	String userDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/users/");
	FileUtils.forceMkdir(new File(userDir));
	String pluginDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/plugins/");
	FileUtils.forceMkdir(new File(pluginDir));
	String importDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/impex/in/");
	FileUtils.forceMkdir(new File(importDir));
	String exportDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/impex/out/");
	FileUtils.forceMkdir(new File(exportDir));
	String logDir = FilenameUtils.separatorsToUnix(repoFolder.getPath() + "/logs/");
	FileUtils.forceMkdir(new File(logDir));
	String dbDirectory = FilenameUtils.separatorsToSystem(repoFolder.getPath() + "/db/");

	ContextProperties pbean = Context.get().getProperties();
	pbean.setProperty("store.1.dir", docDir);
	pbean.setProperty("store.write", "1");
	pbean.setProperty("index.dir", indexDir);
	pbean.setProperty("conf.userdir", userDir);
	pbean.setProperty("conf.plugindir", pluginDir);
	pbean.setProperty("conf.importdir", importDir);
	pbean.setProperty("conf.exportdir", exportDir);
	pbean.setProperty("conf.logdir", logDir);
	pbean.setProperty("conf.dbdir", dbDirectory);
	pbean.write();

	// Refresh the current logging location
	try {
		String log4jPath = URLDecoder.decode(this.getClass().getResource("/log.xml").getPath(), "UTF-8");
		System.err.println("log4jPath = " + log4jPath);
		Log4jConfigurer.initLogging(log4jPath);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}

	reloadContext();
}
 
Example 4
Source Project: tddl5   Source File: Simba2Sample.java    License: Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 5
Source Project: rice   Source File: Log4jLifeCycle.java    License: Educational Community License v2.0 4 votes vote down vote up
@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();
}