org.apache.log4j.PropertyConfigurator Java Examples
The following examples show how to use
org.apache.log4j.PropertyConfigurator.
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: PDLog.java From openprodoc with GNU Affero General Public License v3.0 | 6 votes |
/** * @return the log4j */ public static Logger getLogger() { if (log4j==null) { PropertyConfigurator.configure(getPropFile()); FileOutputStream f; // try // { // f = new FileOutputStream("log4j.prop"); // f.close(); // } catch (Exception ex) // { // System.out.println(ex.getLocalizedMessage()); // } log4j = Logger.getLogger("OpenProdoc"); if (Debug) log4j.setLevel(Level.DEBUG); else if (Info) log4j.setLevel(Level.INFO); else if(Error) log4j.setLevel(Level.ERROR); } return log4j; }
Example #2
Source File: RiceTestCase.java From rice with Educational Community License v2.0 | 6 votes |
/** * configures logging using custom properties file if specified, or the default one. * Log4j also uses any file called log4.properties in the classpath * * <p>To configure a custom logging file, set a JVM system property on using -D. For example * -Dalt.log4j.config.location=file:/home/me/kuali/test/dev/log4j.properties * </p> * * <p>The above option can also be set in the run configuration for the unit test in the IDE. * To avoid log4j using files called log4j.properties that are defined in the classpath, add the following system property: * -Dlog4j.defaultInitOverride=true * </p> * @throws IOException */ protected void configureLogging() throws IOException { ResourceLoader resourceLoader = new FileSystemResourceLoader(); String altLog4jConfigLocation = System.getProperty(ALT_LOG4J_CONFIG_LOCATION_PROP); Resource log4jConfigResource = null; if (!StringUtils.isEmpty(altLog4jConfigLocation)) { log4jConfigResource = resourceLoader.getResource(altLog4jConfigLocation); } if (log4jConfigResource == null || !log4jConfigResource.exists()) { System.out.println("Alternate Log4j config resource does not exist! " + altLog4jConfigLocation); System.out.println("Using default log4j configuration: " + DEFAULT_LOG4J_CONFIG); log4jConfigResource = resourceLoader.getResource(DEFAULT_LOG4J_CONFIG); } else { System.out.println("Using alternate log4j configuration at: " + altLog4jConfigLocation); } Properties p = new Properties(); p.load(log4jConfigResource.getInputStream()); PropertyConfigurator.configure(p); }
Example #3
Source File: SarosComponent.java From saros with GNU General Public License v2.0 | 6 votes |
private void loadLoggers() { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { // change the context class loader so Log4J will find // the SarosLogFileAppender Thread.currentThread().setContextClassLoader(SarosComponent.class.getClassLoader()); PropertyConfigurator.configure( SarosComponent.class.getClassLoader().getResource("saros.log4j.properties")); } catch (RuntimeException e) { LogLog.error("initializing loggers failed", e); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); } }
Example #4
Source File: OfflineAdminApp.java From chvote-1-0 with GNU Affero General Public License v3.0 | 6 votes |
@Override public void start(Stage primaryStage) throws Exception { PropertyConfigurator.configure(getLog4jProperties()); ResourceBundle resourceBundle = getBundle(); initializeDefaultExceptionHandler(resourceBundle); primaryStage.setTitle(resourceBundle.getString("primaryStage.title")); primaryStage.getIcons().add(new Image(OfflineAdminApp.class.getResourceAsStream("images/icon.gif"))); BorderPane rootLayout = initRootLayout(resourceBundle); Scene mainScene = new Scene(rootLayout); mainScene.getStylesheets().add(getStyleSheet().toExternalForm()); primaryStage.setScene(mainScene); primaryStage.show(); }
Example #5
Source File: Main.java From MET-CS665 with Apache License 2.0 | 6 votes |
/** * This main method runs an example. * * @param args not used */ public static void main(String[] args) { // It should be passed better by the JVM arguments. // Like -Dlog4j.configuration={path to the log4j.properties config file} PropertyConfigurator.configure("log4j.properties"); TaxpayerBundle bundleCpa = TaxpayerFactory.createTaxpayerInstance("CPA", "Joe Smith"); logger.info(bundleCpa.getTaxpayerDetails().getTaxpayerType() + " bundle is created"); logger.info("Tax Returns Count: " + bundleCpa.getTaxReturns().size()); TaxpayerBundle bundleTrustee = TaxpayerFactory.createTaxpayerInstance("Trustee", "Jeff Jones"); logger.info(bundleTrustee.getTaxpayerDetails().getTaxpayerType() + " bundle is created"); logger.info("Tax Returns Count: " + bundleTrustee.getTaxReturns().size()); // This line should generate an ERROR in Log TaxpayerBundle bundleUnknown = TaxpayerFactory.createTaxpayerInstance("Unknown", "Smith J"); if (bundleUnknown == null) { logger.error("Bunder Account is null!");; } }
Example #6
Source File: PreLaunchUpdateApplication.java From bigtable-sql with Apache License 2.0 | 6 votes |
private static void initializeLogger() throws IOException { String logConfigFileName = ApplicationArguments.getInstance().getLoggingConfigFileName(); if (logConfigFileName != null) { PropertyConfigurator.configure(logConfigFileName); } else { ApplicationFiles appFiles = new ApplicationFiles(); String logMessagePattern = "%-4r [%t] %-5p %c %x - %m%n"; Layout layout = new PatternLayout(logMessagePattern); File logsDir = new File(appFiles.getUserSettingsDirectory(), "logs"); File updateLogFile = new File(logsDir, "updater.log"); FileAppender appender = new FileAppender(layout, updateLogFile.getAbsolutePath()); LoggerController.registerLoggerFactory(new SquirrelLoggerFactory(appender, false)); } }
Example #7
Source File: DatabaseTaskBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Initializes the logging. */ private void initLogging() { if (_simpleLogging) { // For Ant, we're forcing DdlUtils to do logging via log4j to the console Properties props = new Properties(); String level = (_verbosity == null ? Level.INFO.toString() : _verbosity.getValue()).toUpperCase(); props.setProperty("log4j.rootCategory", level + ",A"); props.setProperty("log4j.appender.A", "org.apache.log4j.ConsoleAppender"); props.setProperty("log4j.appender.A.layout", "org.apache.log4j.PatternLayout"); props.setProperty("log4j.appender.A.layout.ConversionPattern", "%m%n"); // we don't want debug logging from Digester props.setProperty("log4j.logger.org.apache.commons", "WARN"); LogManager.resetConfiguration(); PropertyConfigurator.configure(props); } _log = LogFactory.getLog(getClass()); }
Example #8
Source File: Logger.java From smslib-v3 with Apache License 2.0 | 6 votes |
protected Logger() { if (System.getProperties().getProperty("java.vm.name").equalsIgnoreCase("ikvm.net")) { File f = new File("log4j.properties"); if (!f.exists()) log4jLogger = null; else { log4jLogger = org.apache.log4j.Logger.getLogger("smslib"); PropertyConfigurator.configure("log4j.properties"); } } else { log4jLogger = org.apache.log4j.Logger.getLogger("smslib"); //PropertyConfigurator.configure("log4j.properties"); } }
Example #9
Source File: Main.java From MET-CS665 with Apache License 2.0 | 6 votes |
/** * This main method runs an example. * * @param args not used */ public static void main(String[] args) { // TODO // NOTE: Setting the log4j property should not be here. // It should be passed better by the JVM arguments. // Like -Dlog4j.configuration={path to the log4j.properties config file} PropertyConfigurator.configure("log4j.properties"); // creating a different type of order but declaring them from their abstract type OrderProcessTemplate onlineOrder = new OnlineOrder(); OrderProcessTemplate inStoreOrder = new InStoreOrder(); OrderProcessTemplate cryptoOrder = new CryptoOrder(); // executing the template method for each order object with their unique implementations. onlineOrder.processOrder(19, "debit"); inStoreOrder.processOrder(7, "cash"); cryptoOrder.processOrder(2,"bitcoin"); }
Example #10
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 #11
Source File: AsyncHttpClient.java From happor with MIT License | 6 votes |
public static void main(String[] args) { PropertyConfigurator.configure("conf/log4j.properties"); AsyncHttpClient client = new AsyncHttpClient(); DefaultFullHttpRequest request = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, "/AsyncHttpClient"); client.sendRequest("127.0.0.1", 8888, request, new Callback() { public void onResponse(FullHttpResponse response) { // TODO Auto-generated method stub System.out.println("AsyncHttpClient onResponse"); } public void onTimeout() { // TODO Auto-generated method stub System.out.println("AsyncHttpClient onTimeout"); } public void onConnectFail() { // TODO Auto-generated method stub System.out.println("AsyncHttpClient onConnectFail"); } }); }
Example #12
Source File: JdbmQueueTest.java From knox with Apache License 2.0 | 6 votes |
@After public void tearDown() throws IOException { if( queue != null ) { queue.close(); queue = null; } LogManager.shutdown(); String absolutePath = "target/audit"; File db = new File( absolutePath + ".db" ); if( db.exists() ) { assertThat( "Failed to delete audit store db file.", db.delete(), is( true ) ); } File lg = new File( absolutePath + ".lg" ); if( lg.exists() ) { assertThat( "Failed to delete audit store lg file.", lg.delete(), is( true ) ); } PropertyConfigurator.configure( ClassLoader.getSystemResourceAsStream( "audit-log4j.properties" ) ); }
Example #13
Source File: QueryInstantiator.java From Touchstone with Apache License 2.0 | 6 votes |
public static void main(String[] args) { PropertyConfigurator.configure(".//test//lib//log4j.properties"); System.setProperty("com.wolfram.jlink.libdir", "C://Program Files//Wolfram Research//Mathematica//10.0//SystemFiles//Links//JLink"); // SchemaReader schemaReader = new SchemaReader(); // List<Table> tables = schemaReader.read(".//test//input//tpch_schema_sf_1.txt"); // ConstraintChainsReader constraintChainsReader = new ConstraintChainsReader(); // List<ConstraintChain> constraintChains = constraintChainsReader.read(".//test//input//tpch_cardinality_constraints_sf_1.txt"); // ComputingThreadPool computingThreadPool = new ComputingThreadPool(2, 20, 0.00001); // QueryInstantiator queryInstantiator = new QueryInstantiator(tables, constraintChains, null, 20, 0.00001, computingThreadPool); // queryInstantiator.iterate(); SchemaReader schemaReader = new SchemaReader(); List<Table> tables = schemaReader.read(".//test//input//function_test_schema_0.txt"); ConstraintChainsReader constraintChainsReader = new ConstraintChainsReader(); List<ConstraintChain> constraintChains = constraintChainsReader.read(".//test//input//function_test_cardinality_constraints_0.txt"); NonEquiJoinConstraintsReader nonEquiJoinConstraintsReader = new NonEquiJoinConstraintsReader(); List<NonEquiJoinConstraint> nonEquiJoinConstraints = nonEquiJoinConstraintsReader.read(".//test//input//function_test_non_equi_join_0.txt"); // ComputingThreadPool computingThreadPool = new ComputingThreadPool(1, 20, 0.00001); ComputingThreadPool computingThreadPool = new ComputingThreadPool(4, 20, 0.00001); QueryInstantiator queryInstantiator = new QueryInstantiator(tables, constraintChains, nonEquiJoinConstraints, 20, 0.00001, computingThreadPool); queryInstantiator.iterate(); }
Example #14
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 #15
Source File: WrapperSavingAsiaTest.java From SEAL with Apache License 2.0 | 5 votes |
@BeforeClass public static void initLog() throws FileNotFoundException, IOException { Properties logging = new Properties(); logging.load(new FileInputStream(new File("config/log4j.properties"))); PropertyConfigurator.configure(logging); Logger.getLogger(BingAPISearcher.class).debug("Testing debug log"); }
Example #16
Source File: ParseJSONMessagesTest.java From Cardshifter with Apache License 2.0 | 5 votes |
@Test(expected = IOException.class) public void parseUnknownData() throws IOException { PropertyConfigurator.configure(ServerMain.class.getResourceAsStream("log4j.properties")); Server server = new Server(); server.getIncomingHandler().parse("{ \"command\": \"use\", \"jibberishId\": 1, \"id\": 12 }"); }
Example #17
Source File: ConfigLoaderTest.java From Mario with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() { System.setProperty("default.config.path", "./"); PropertyConfigurator .configure(System.getProperty("user.dir") + File.separator + "conf" + File.separator + "log4j.properties"); }
Example #18
Source File: DiameterServer.java From SigFW with GNU Affero General Public License v3.0 | 5 votes |
private static void configLog4j() { InputStream inStreamLog4j = DiameterServer.class.getClassLoader().getResourceAsStream("log4j.properties"); Properties propertiesLog4j = new Properties(); try { propertiesLog4j.load(inStreamLog4j); PropertyConfigurator.configure(propertiesLog4j); } catch (Exception e) { e.printStackTrace(); } log.debug("log4j configured"); }
Example #19
Source File: ZKServerTest.java From TakinRPC with Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { PropertyConfigurator.configure("conf/log4j.properties"); ZkServer zk = new ZkServer("D:/zk/data", "D:/zk/log", 2181); zk.start(); } catch (Exception e) { e.printStackTrace(); } }
Example #20
Source File: MyLoggerTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** When called wihtout arguments, this program will just print <pre> DEBUG [main] some.cat - Hello world. </pre> and exit. <b>However, it can be called with a configuration file in XML or properties format. */ static public void main(String[] args) { if(args.length == 0) { // Note that the appender is added to root but that the log // request is made to an instance of MyLogger. The output still // goes to System.out. Logger root = Logger.getRootLogger(); Layout layout = new PatternLayout("%p [%t] %c (%F:%L) - %m%n"); root.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT)); } else if(args.length == 1) { if(args[0].endsWith("xml")) { DOMConfigurator.configure(args[0]); } else { PropertyConfigurator.configure(args[0]); } } else { usage("Incorrect number of parameters."); } try { MyLogger c = (MyLogger) MyLogger.getLogger("some.cat"); c.trace("Hello"); c.debug("Hello"); } catch(ClassCastException e) { LogLog.error("Did you forget to set the factory in the config file?", e); } }
Example #21
Source File: Log4jConfigurer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Initialize log4j from the given file location, with no config file refreshing. * Assumes an XML file in case of a ".xml" file extension, and a properties file * otherwise. * @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") * @throws FileNotFoundException if the location specifies an invalid file path */ public static void initLogging(String location) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); if (ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()) && !ResourceUtils.getFile(url).exists()) { throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found"); } if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { DOMConfigurator.configure(url); } else { PropertyConfigurator.configure(url); } }
Example #22
Source File: TestLog4jAppender.java From mt-flume with Apache License 2.0 | 5 votes |
@Test(expected = EventDeliveryException.class) public void testLog4jAppenderFailureNotUnsafeMode() throws Throwable { configureSource(); PropertyConfigurator.configure(props); Logger logger = LogManager.getLogger(TestLog4jAppender.class); source.stop(); sendAndAssertFail(logger); }
Example #23
Source File: EPSTestCase.java From sailfish-core with Apache License 2.0 | 5 votes |
public EPSTestCase() { synchronized ( EPSTestCase.class ) { if ( isLoggingAlreadyConfigured == false ) { String configFile = getBaseDir() + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "log.properties"; PropertyConfigurator.configure(configFile); isLoggingAlreadyConfigured = true; } } }
Example #24
Source File: LogConfigurator.java From maestro-java with Apache License 2.0 | 5 votes |
/** * Configure the output to be as silent as possible */ public static void silent() { Properties properties = new Properties(); configureCommon(properties); configureSilent(properties); PropertyConfigurator.configure(properties); }
Example #25
Source File: Log4jConfigurer.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Initialize log4j from the given file location, with no config file refreshing. * Assumes an XML file in case of a ".xml" file extension, and a properties file * otherwise. * @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") * @throws FileNotFoundException if the location specifies an invalid file path */ public static void initLogging(String location) throws FileNotFoundException { String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location); URL url = ResourceUtils.getURL(resolvedLocation); if (ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()) && !ResourceUtils.getFile(url).exists()) { throw new FileNotFoundException("Log4j config file [" + resolvedLocation + "] not found"); } if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) { DOMConfigurator.configure(url); } else { PropertyConfigurator.configure(url); } }
Example #26
Source File: Activator.java From hana-native-adapters with Apache License 2.0 | 5 votes |
@Override public void start(BundleContext bundleContext) throws Exception { PropertyConfigurator.configure("log4j.properties"); logger.info("### BQAdapter start"); Activator.context = bundleContext; BQAdapterFactory srv = new BQAdapterFactory(); adapterRegistration = context.registerService(AdapterFactory.class.getName(),srv ,null); }
Example #27
Source File: ParseJSONMessagesTest.java From Cardshifter with Apache License 2.0 | 5 votes |
@Test public void parse() throws IOException { PropertyConfigurator.configure(ServerMain.class.getResourceAsStream("log4j.properties")); Server server = new Server(); UseAbilityMessage message = server.getIncomingHandler().parse("{ \"command\": \"use\", \"gameId\": 1, \"action\": \"Play\", \"id\": \"2\", \"targets\": [4,2] }"); assertEquals(2, message.getId()); assertArrayEquals(new int[]{ 4, 2 }, message.getTargets()); assertEquals("use", message.getCommand()); assertEquals(1, message.getGameId()); assertEquals("Play", message.getAction()); }
Example #28
Source File: Shell.java From knox with Apache License 2.0 | 5 votes |
@SuppressWarnings("PMD.DoNotUseThreads") // we need to define a Thread to be able to register a shutdown hook public static void main( String... args ) throws Exception { PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) ); if( args.length > 0 ) { if (NON_INTERACTIVE_COMMANDS.contains(args[0])) { final String[] arguments = new String[args.length == 1 ? 1:3]; arguments[0] = args[0]; if (args.length > 1) { arguments[1] = "--gateway"; arguments[2] = args[1]; } KnoxSh.main(arguments); } else { GroovyMain.main( args ); } } else { Groovysh shell = new Groovysh(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Closing any open connections ..."); AbstractSQLCommandSupport sqlcmd = (AbstractSQLCommandSupport) shell.getRegistry().getProperty(":ds"); sqlcmd.closeConnections(); sqlcmd = (AbstractSQLCommandSupport) shell.getRegistry().getProperty(":sql"); sqlcmd.closeConnections(); } }); for( String name : IMPORTS ) { shell.execute( "import " + name ); } // register custom groovysh commands shell.register(new SelectCommand(shell)); shell.register(new DataSourceCommand(shell)); shell.register(new CSVCommand(shell)); shell.register(new WebHDFSCommand(shell)); shell.run( null ); } }
Example #29
Source File: RunDataGenerator.java From Touchstone with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Configurations configurations = new Configurations(args[0]); PropertyConfigurator.configure(configurations.getLog4jConfFile()); int generatorId = Integer.parseInt(args[1]); new Thread(new DataGenerator(configurations, generatorId)).start(); }
Example #30
Source File: Main.java From kite with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // reconfigure logging with the kite minicluster configuration PropertyConfigurator.configure(MiniCluster.class .getResource("/kite-minicluster-logging.properties")); Logger console = LoggerFactory.getLogger(MiniCluster.class); int rc = ToolRunner.run(new Configuration(), new Main(console), args); System.exit(rc); }