Java Code Examples for org.apache.log4j.PropertyConfigurator#configureAndWatch()
The following examples show how to use
org.apache.log4j.PropertyConfigurator#configureAndWatch() .
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
Source File: FreetextIK.java From ongdb-lab-apoc with Apache License 2.0 | 6 votes |
/** * @param text:待分词文本 * @param useSmart:true 用智能分词,false 细粒度分词 * @return * @Description: TODO(支持中英文本分词) */ @UserFunction(name = "zdr.index.iKAnalyzer") @Description("Fulltext index iKAnalyzer - RETURN zdr.index.iKAnalyzer({text},true) AS words") public List<String> iKAnalyzer(@Name("text") String text, @Name("useSmart") boolean useSmart) { PropertyConfigurator.configureAndWatch("dic" + File.separator + "log4j.properties"); Configuration cfg = new Configuration(useSmart); StringReader input = new StringReader(text.trim()); IKSegmenter ikSegmenter = new IKSegmenter(input, cfg); List<String> results = new ArrayList<>(); try { for (Lexeme lexeme = ikSegmenter.next(); lexeme != null; lexeme = ikSegmenter.next()) { results.add(lexeme.getLexemeText()); } } catch (IOException e) { e.printStackTrace(); } return results; }
Example 2
Source File: Server.java From hadoop with Apache License 2.0 | 6 votes |
/** * Initializes Log4j logging. * * @throws ServerException thrown if Log4j could not be initialized. */ protected void initLog() throws ServerException { verifyDir(logDir); LogManager.resetConfiguration(); File log4jFile = new File(configDir, name + "-log4j.properties"); if (log4jFile.exists()) { PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 * 1000); //every 10 secs log = LoggerFactory.getLogger(Server.class); } else { Properties props = new Properties(); try { InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES); try { props.load(is); } finally { is.close(); } } catch (IOException ex) { throw new ServerException(ServerException.ERROR.S03, DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex); } PropertyConfigurator.configure(props); log = LoggerFactory.getLogger(Server.class); log.warn("Log4j [{}] configuration file not found, using default configuration from classpath", log4jFile); } }
Example 3
Source File: KMSWebApp.java From hadoop with Apache License 2.0 | 6 votes |
private void initLogging(String confDir) { if (System.getProperty("log4j.configuration") == null) { System.setProperty("log4j.defaultInitOverride", "true"); boolean fromClasspath = true; File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile(); if (log4jConf.exists()) { PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000); fromClasspath = false; } else { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL log4jUrl = cl.getResource(LOG4J_PROPERTIES); if (log4jUrl != null) { PropertyConfigurator.configure(log4jUrl); } } LOG = LoggerFactory.getLogger(KMSWebApp.class); LOG.debug("KMS log starting"); if (fromClasspath) { LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES); LOG.warn("Logging with INFO level to standard output"); } } else { LOG = LoggerFactory.getLogger(KMSWebApp.class); } }
Example 4
Source File: Server.java From big-c with Apache License 2.0 | 6 votes |
/** * Initializes Log4j logging. * * @throws ServerException thrown if Log4j could not be initialized. */ protected void initLog() throws ServerException { verifyDir(logDir); LogManager.resetConfiguration(); File log4jFile = new File(configDir, name + "-log4j.properties"); if (log4jFile.exists()) { PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 * 1000); //every 10 secs log = LoggerFactory.getLogger(Server.class); } else { Properties props = new Properties(); try { InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES); try { props.load(is); } finally { is.close(); } } catch (IOException ex) { throw new ServerException(ServerException.ERROR.S03, DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex); } PropertyConfigurator.configure(props); log = LoggerFactory.getLogger(Server.class); log.warn("Log4j [{}] configuration file not found, using default configuration from classpath", log4jFile); } }
Example 5
Source File: KMSWebApp.java From big-c with Apache License 2.0 | 6 votes |
private void initLogging(String confDir) { if (System.getProperty("log4j.configuration") == null) { System.setProperty("log4j.defaultInitOverride", "true"); boolean fromClasspath = true; File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile(); if (log4jConf.exists()) { PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000); fromClasspath = false; } else { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL log4jUrl = cl.getResource(LOG4J_PROPERTIES); if (log4jUrl != null) { PropertyConfigurator.configure(log4jUrl); } } LOG = LoggerFactory.getLogger(KMSWebApp.class); LOG.debug("KMS log starting"); if (fromClasspath) { LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES); LOG.warn("Logging with INFO level to standard output"); } } else { LOG = LoggerFactory.getLogger(KMSWebApp.class); } }
Example 6
Source File: StartMigration.java From migration-tool with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000L); log.info("\r\n\t Migration-tool client instance start, [version 1.0-SNAPSHOT] " + "\r\n\t\t host=" + Config.getSetting("host") + " port=" + Config.getSetting("port") + " ability=" + Config.getSetting("ability") + " thread_num=" + Config.getSetting("thread_num") + "\r\n\t\t\t Copyright (C) 2015 JJF"); //提前加载驱动 Class.forName("com.mysql.jdbc.Driver"); // int nThreads = Integer.parseInt(Config.getSetting("thread_num")); ExecutorService threadPool = Executors.newFixedThreadPool(nThreads, new NamedThreadFactory("migration")); for(int i=0; i<nThreads; i++) { threadPool.execute(new MigrationTask()); try { //暂停1s是为了 能力值处理 Thread.sleep(1000); } catch (Exception e) { log.error("main thread sleep 1000ms error!",e); } } }
Example 7
Source File: KMSWebApp.java From ranger with Apache License 2.0 | 6 votes |
private void initLogging(String confDir) { if (System.getProperty("log4j.configuration") == null) { System.setProperty("log4j.defaultInitOverride", "true"); boolean fromClasspath = true; File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile(); if (log4jConf.exists()) { PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000); fromClasspath = false; } else { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL log4jUrl = cl.getResource(LOG4J_PROPERTIES); if (log4jUrl != null) { PropertyConfigurator.configure(log4jUrl); } } LOG = LoggerFactory.getLogger(KMSWebApp.class); LOG.debug("KMS log starting"); if (fromClasspath) { LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES); LOG.warn("Logging with INFO level to standard output"); } } else { LOG = LoggerFactory.getLogger(KMSWebApp.class); } }
Example 8
Source File: IKFulltextTest.java From ongdb-lab-apoc with Apache License 2.0 | 5 votes |
@Test public void queryWords() throws IOException { PropertyConfigurator.configureAndWatch("dic/log4j.properties"); String query = "复联终章快上映了好激动,据说知识图谱与人工智能技术应用到了那部电影!吖啶基氨基甲烷磺酰甲氧基苯胺是一种药嘛?"; // String query = "You are probably compiling (or using dependencies compiled) with java 9, but still using JDK 8.0 " + // "Install java 9 and change your OS environment settings to point to the new JDK. This should solve your problem."; // Environment env = new Environment(); // Settings settings = new Settings(); boolean useSmart = false; // true 用智能分词,false 细粒度 // new Configuration(env, settings).setUseSmart(useSmart); Configuration cfg = new Configuration(useSmart); // System.out.println(JSONArray.parseArray(JSON.toJSONString(cfg.getExtDictionarys()))); // System.out.println(JSONArray.parseArray(JSON.toJSONString(cfg.getExtStopWordDictionarys()))); // // System.out.println(cfg.getMainDictionary()); // 系统默认词库 // System.out.println(cfg.getQuantifierDicionary()); StringReader input = new StringReader(query.trim()); IKSegmenter ikSegmenter = new IKSegmenter(input, cfg); for (Lexeme lexeme = ikSegmenter.next(); lexeme != null; lexeme = ikSegmenter.next()) { System.out.print(lexeme.getLexemeText() + " | "); // System.out.print(lexeme.getLexemeTypeString() + " | "); } }
Example 9
Source File: LoggerFactory.java From development with Apache License 2.0 | 5 votes |
/** * Sets the log level for the given logger. If there is no property file to * be used, the log level will be set to the value as given in the level * parameter. * * @param logger * The logger to be modified. * @param level * The log level to be set if no property file can be found. */ private static void setLogLevel(Log4jLogger logger, Level level) { if (logConfigPath != null && new File(logConfigPath).exists()) { PropertyConfigurator.configureAndWatch(logConfigPath, 60000); } else { logger.systemLogger.setLevel(level); logger.auditLogger.setLevel(level); // used INFO log level as default for the reverse proxy logger logger.proxyLogger.setLevel(Level.INFO); // all access operations will be logged with info level logger.accessLogger.setLevel(Level.INFO); } }
Example 10
Source File: StartServer.java From migration-tool with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000L); log.info("\r\n\t Migration-tool instance start, port:" + Config.getInt("port") + " [version 1.0-SNAPSHOT] \r\n\t\t\t Copyright (C) 2015 JJF"); //insert db TableConstants.init(); //定时判断id段是否超时 ScheduledExecutorService scheduleExec = Executors.newScheduledThreadPool(1); scheduleExec.scheduleAtFixedRate(new SegementTimeoutTask(), 0, SegementManager.SEGEMENT_INTERVAL, TimeUnit.SECONDS); final NettyServer nettyServer = new NettyServer(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { nettyServer.stop(); log.info("shutdown server"); } catch (Exception e) { log.error("nettyServer stop error!", e); } } })); ThreadFactory tf = new NamedThreadFactory("BUSINESSTHREAEFACTORY"); ExecutorService threadPool = new ThreadPoolExecutor(20, 100, 30, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), tf); nettyServer.start(Config.getInt("port"), threadPool, Config.getLong("timeout")); }
Example 11
Source File: Log4jConfigurer.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
public static final void configureLogging(boolean doStartupStatsLogging) { String settingsFile = PropertyLoadingFactoryBean.getBaseProperty(KFSConstants.LOG4J_SETTINGS_FILE_KEY); String reloadMinutes = PropertyLoadingFactoryBean.getBaseProperty(KFSConstants.LOG4J_RELOAD_MINUTES_KEY); long reloadMilliseconds = 5 * MILLISECONDS_CONVERSION_MULTIPLIER; try { reloadMilliseconds = Long.parseLong(reloadMinutes) * MILLISECONDS_CONVERSION_MULTIPLIER; } catch (NumberFormatException ignored) { // default to 5 minutes } PropertyConfigurator.configureAndWatch(settingsFile, reloadMilliseconds); printClasspath(); }
Example 12
Source File: FulltextIndexTest.java From ongdb-lab-apoc with Apache License 2.0 | 4 votes |
@Test public void autoIndex() { PropertyConfigurator.configureAndWatch("dic/log4j.properties"); // given // create 90k nodes - this force 2 batches during indexing execute("UNWIND range(80000,90000) as x CREATE (n:Movie{name:'person'+x}) SET n.description='description'+x"); execute("UNWIND range(80000,90000) as x CREATE (n:Person{name:'person'+x}) SET n.description='description'+x"); // 操作属性忽略标签 // execute("CALL zdr.index.addChineseFulltextAutoIndex('people',['name','description'],'Movie',{autoUpdate:'true'})"); // then ResourceIterator<Node> iterator = search("people", "name:person89999"); try (Transaction tx = db.beginTx()) { while (iterator.hasNext()) { Node node = iterator.next(); Iterable<Label> labelIterable = node.getLabels(); StringBuilder builder = new StringBuilder(); labelIterable.forEach(v -> { builder.append(v + ":"); }); System.out.print(builder.toString()); Map<String, Object> mapObj = node.getAllProperties(); for (Map.Entry entry : mapObj.entrySet()) { System.out.print(entry.getKey() + ":" + entry.getValue() + " "); } System.out.println(); } tx.success(); } // // SECOND TEST // execute("UNWIND range(10000,20000) as x CREATE (n:Movie{name:'person'+x}) SET n.description='description'+x"); // // then //// ResourceIterator<Node> iterator2 = search("people", "name:person19999"); // ResourceIterator<Node> iterator2 = nodeSearch("people", "name:person19999"); // // try (Transaction tx = db.beginTx()) { // while (iterator2.hasNext()) { // Node node = iterator.next(); // // Iterable<Label> labelIterable = node.getLabels(); // StringBuilder builder = new StringBuilder(); // labelIterable.forEach(v -> { // builder.append(v + ":"); // }); // System.out.print(builder.toString()); // // Map<String, Object> mapObj = node.getAllProperties(); // for (Map.Entry entry : mapObj.entrySet()) { // System.out.print(entry.getKey() + ":" + entry.getValue() + " "); // } // System.out.println(); // } // tx.success(); // } }
Example 13
Source File: StartServer.java From fqueue with Apache License 2.0 | 4 votes |
/** * @param args */ public static void main(String[] args) { PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000); StartNewQueue.newQueueInstance(Integer.parseInt(Config.getSetting("port"))); log.info("running at port " + Config.getSetting("port")); }
Example 14
Source File: StartServer.java From fqueue with Apache License 2.0 | 4 votes |
/** * @param args */ public static void main(String[] args) { PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000); StartNewQueue.newQueueInstance(Integer.parseInt(Config.getSetting("port"))); log.info("running at port " + Config.getSetting("port")); }
Example 15
Source File: Log4jConfigurer.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Initialize log4j from the given location, with the given refresh interval * for the config file. Assumes an XML file in case of a ".xml" file extension, * and a properties file otherwise. * <p>Log4j's watchdog thread will asynchronously check whether the timestamp * of the config file has changed, using the given interval between checks. * A refresh interval of 1000 milliseconds (one second), which allows to * do on-demand log level changes with immediate effect, is not unfeasible. * <p><b>WARNING:</b> Log4j's watchdog thread does not terminate until VM shutdown; * in particular, it does not terminate on LogManager shutdown. Therefore, it is * recommended to <i>not</i> use config file refreshing in a production J2EE * environment; the watchdog thread would not stop on application shutdown there. * @param location the location of the config file: either a "classpath:" location * (e.g. "classpath:myLog4j.properties"), an absolute file URL * (e.g. "file:C:/log4j.properties), or a plain absolute path in the file system * (e.g. "C:/log4j.properties") * @param refreshInterval interval between config file refresh checks, in milliseconds * @throws FileNotFoundException if the location specifies an invalid file path */ public static void initLogging(String location, long refreshInterval) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); File file = ResourceUtils.getFile(resolvedLocation); if (!file.exists()) { throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found"); } if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { DOMConfigurator.configureAndWatch(file.getAbsolutePath(), refreshInterval); } else { PropertyConfigurator.configureAndWatch(file.getAbsolutePath(), refreshInterval); } }
Example 16
Source File: Log4jConfigurer.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Initialize log4j from the given location, with the given refresh interval * for the config file. Assumes an XML file in case of a ".xml" file extension, * and a properties file otherwise. * <p>Log4j's watchdog thread will asynchronously check whether the timestamp * of the config file has changed, using the given interval between checks. * A refresh interval of 1000 milliseconds (one second), which allows to * do on-demand log level changes with immediate effect, is not unfeasible. * <p><b>WARNING:</b> Log4j's watchdog thread does not terminate until VM shutdown; * in particular, it does not terminate on LogManager shutdown. Therefore, it is * recommended to <i>not</i> use config file refreshing in a production J2EE * environment; the watchdog thread would not stop on application shutdown there. * @param location the location of the config file: either a "classpath:" location * (e.g. "classpath:myLog4j.properties"), an absolute file URL * (e.g. "file:C:/log4j.properties), or a plain absolute path in the file system * (e.g. "C:/log4j.properties") * @param refreshInterval interval between config file refresh checks, in milliseconds * @throws FileNotFoundException if the location specifies an invalid file path */ public static void initLogging(String location, long refreshInterval) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); File file = ResourceUtils.getFile(resolvedLocation); if (!file.exists()) { throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found"); } if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { DOMConfigurator.configureAndWatch(file.getAbsolutePath(), refreshInterval); } else { PropertyConfigurator.configureAndWatch(file.getAbsolutePath(), refreshInterval); } }