Java Code Examples for org.apache.log4j.xml.DOMConfigurator#configureAndWatch()
The following examples show how to use
org.apache.log4j.xml.DOMConfigurator#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: Launcher.java From CapturePacket with MIT License | 6 votes |
public static void main(final String... args) { File log4jConfigurationFile = new File( "src/test/resources/log4j.xml"); if (log4jConfigurationFile.exists()) { DOMConfigurator.configureAndWatch( log4jConfigurationFile.getAbsolutePath(), 15); } try { final int port = 9090; System.out.println("About to start server on port: " + port); HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer .bootstrapFromFile("./littleproxy.properties") .withPort(port).withAllowLocalOnly(false); bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager()); System.out.println("About to start..."); bootstrap.start(); } catch (Exception e) { log.error(e.getMessage(), e); System.exit(1); } }
Example 2
Source File: Launcher.java From AndroidHttpCapture with MIT License | 6 votes |
public static void main(final String... args) { File log4jConfigurationFile = new File( "src/test/resources/log4j.xml"); if (log4jConfigurationFile.exists()) { DOMConfigurator.configureAndWatch( log4jConfigurationFile.getAbsolutePath(), 15); } try { final int port = 9090; System.out.println("About to start server on port: " + port); HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer .bootstrapFromFile("./littleproxy.properties") .withPort(port).withAllowLocalOnly(false); bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager()); System.out.println("About to start..."); bootstrap.start(); } catch (Exception e) { log.error(e.getMessage(), e); System.exit(1); } }
Example 3
Source File: Launcher.java From LittleProxy-mitm with Apache License 2.0 | 6 votes |
public static void main(final String... args) { File log4jConfigurationFile = new File( "src/test/resources/log4j.xml"); if (log4jConfigurationFile.exists()) { DOMConfigurator.configureAndWatch( log4jConfigurationFile.getAbsolutePath(), 15); } try { final int port = 9090; System.out.println("About to start server on port: " + port); HttpProxyServerBootstrap bootstrap = DefaultHttpProxyServer .bootstrapFromFile("./littleproxy.properties") .withPort(port).withAllowLocalOnly(false); bootstrap.withManInTheMiddle(new CertificateSniffingMitmManager()); System.out.println("About to start..."); bootstrap.start(); } catch (Exception e) { log.error(e.getMessage(), e); System.exit(1); } }
Example 4
Source File: Log4jEnabledTestCase.java From cloudstack with Apache License 2.0 | 6 votes |
@Override protected void setUp() { URL configUrl = System.class.getResource("/conf/log4j-cloud.xml"); if (configUrl != null) { System.out.println("Configure log4j using log4j-cloud.xml"); try { File file = new File(configUrl.toURI()); System.out.println("Log4j configuration from : " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); } catch (URISyntaxException e) { System.out.println("Unable to convert log4j configuration Url to URI"); } } else { System.out.println("Configure log4j with default properties"); } }
Example 5
Source File: SampleManagementServerApp.java From cloudstack with Apache License 2.0 | 6 votes |
private static void setupLog4j() { URL configUrl = System.class.getResource("/resources/log4j-cloud.xml"); if (configUrl != null) { System.out.println("Configure log4j using log4j-cloud.xml"); try { File file = new File(configUrl.toURI()); System.out.println("Log4j configuration from : " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); } catch (URISyntaxException e) { System.out.println("Unable to convert log4j configuration Url to URI"); } } else { System.out.println("Configure log4j with default properties"); } }
Example 6
Source File: LogConfig.java From megamek with GNU General Public License v2.0 | 5 votes |
public void enableSimplifiedLogging() { if (simpleLoggingConfigured.get()) { return; } simpleLoggingConfigured.set(true); DefaultMmLogger.getInstance().setLogLevel(CAT_MEGAMEK, LogLevel.INFO); // Check for updated logging properties every 30 seconds. DOMConfigurator.configureAndWatch(LOG_CONFIG_FILE_PATH, 30000); }
Example 7
Source File: Proxy.java From LittleProxy-mitm with Apache License 2.0 | 5 votes |
public static void main(final String... args) throws Exception{ File log4jConfigurationFile = new File("src/test/resources/log4j.xml"); if (log4jConfigurationFile.exists()) { DOMConfigurator.configureAndWatch( log4jConfigurationFile.getAbsolutePath(), 15); } new Proxy(9090).start(); Server.waitUntilInterupted(); }
Example 8
Source File: LittleProxyMitmProxy.java From LittleProxy-mitm with Apache License 2.0 | 5 votes |
public static void main(final String... args) throws Exception { File log4jConfigurationFile = new File("src/test/resources/log4j.xml"); if (log4jConfigurationFile.exists()) { DOMConfigurator.configureAndWatch( log4jConfigurationFile.getAbsolutePath(), 15); } new LittleProxyMitmProxy(9090).start(); Server.waitUntilInterupted(); }
Example 9
Source File: LogUtils.java From cloudstack with Apache License 2.0 | 5 votes |
public static void initLog4j(String log4jConfigFileName) { assert (log4jConfigFileName != null); File file = PropertiesUtil.findConfigFile(log4jConfigFileName); if (file != null) { s_logger.info("log4j configuration found at " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath()); } else { String nameWithoutExtension = log4jConfigFileName.substring(0, log4jConfigFileName.lastIndexOf('.')); file = PropertiesUtil.findConfigFile(nameWithoutExtension + ".properties"); if (file != null) { s_logger.info("log4j configuration found at " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath()); } } }
Example 10
Source File: ConsoleProxyMonitor.java From cloudstack with Apache License 2.0 | 5 votes |
private static void configLog4j() { URL configUrl = System.class.getResource("/conf/log4j-cloud.xml"); if (configUrl == null) configUrl = ClassLoader.getSystemResource("log4j-cloud.xml"); if (configUrl == null) configUrl = ClassLoader.getSystemResource("conf/log4j-cloud.xml"); if (configUrl != null) { try { System.out.println("Configure log4j using " + configUrl.toURI().toString()); } catch (URISyntaxException e1) { e1.printStackTrace(); } try { File file = new File(configUrl.toURI()); System.out.println("Log4j configuration from : " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); } catch (URISyntaxException e) { System.out.println("Unable to convert log4j configuration Url to URI"); } } else { System.out.println("Configure log4j with default properties"); } }
Example 11
Source File: ConsoleProxy.java From cloudstack with Apache License 2.0 | 5 votes |
private static void configLog4j() { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL configUrl = loader.getResource("/conf/log4j-cloud.xml"); if (configUrl == null) configUrl = ClassLoader.getSystemResource("log4j-cloud.xml"); if (configUrl == null) configUrl = ClassLoader.getSystemResource("conf/log4j-cloud.xml"); if (configUrl != null) { try { System.out.println("Configure log4j using " + configUrl.toURI().toString()); } catch (URISyntaxException e1) { e1.printStackTrace(); } try { File file = new File(configUrl.toURI()); System.out.println("Log4j configuration from : " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); } catch (URISyntaxException e) { System.out.println("Unable to convert log4j configuration Url to URI"); } // DOMConfigurator.configure(configUrl); } else { System.out.println("Configure log4j with default properties"); } }
Example 12
Source File: DatabaseConfig.java From cloudstack with Apache License 2.0 | 5 votes |
/** * @param args - name of server-setup.xml file which contains the bootstrap data */ public static void main(String[] args) { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); if (file != null) { System.out.println("Log4j configuration from : " + file.getAbsolutePath()); DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); } else { System.out.println("Configure log4j with default properties"); } if (args.length < 1) { s_logger.error("error starting database config, missing initial data file"); } else { try { DatabaseConfig config = ComponentContext.inject(DatabaseConfig.class); config.doVersionCheck(); config.doConfig(); System.exit(0); } catch (Exception ex) { System.out.print("Error Caught"); ex.printStackTrace(); s_logger.error("error", ex); } } }
Example 13
Source File: AgentShell.java From cloudstack with Apache License 2.0 | 4 votes |
public void init(String[] args) throws ConfigurationException { // PropertiesUtil is used both in management server and agent packages, // it searches path under class path and common J2EE containers // For KVM agent, do it specially here File file = new File("/etc/cloudstack/agent/log4j-cloud.xml"); if (!file.exists()) { file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); } if (null != file) { DOMConfigurator.configureAndWatch(file.getAbsolutePath()); s_logger.info("Agent started"); } else { s_logger.error("Could not start the Agent because the absolut path of the \"log4j-cloud.xml\" file cannot be determined."); } final Class<?> c = this.getClass(); _version = c.getPackage().getImplementationVersion(); if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); } s_logger.info("Implementation Version is " + _version); loadProperties(); parseCommand(args); if (s_logger.isDebugEnabled()) { List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames()); for (String property : properties) { s_logger.debug("Found property: " + property); } } s_logger.info("Defaulting to using properties file for storage"); _storage = new PropertiesStorage(); _storage.configure("Storage", new HashMap<String, Object>()); // merge with properties from command line to let resource access // command line parameters for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties().entrySet()) { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } s_logger.info("Defaulting to the constant time backoff algorithm"); _backoff = new ConstantTimeBackoff(); _backoff.configure("ConstantTimeBackoff", new HashMap<String, Object>()); }
Example 14
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 15
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); } }