General discussion

Locked

Java Logger config file system property

By djn ·
I have a Java Logger config file where I specify the location of output files as in java.util.logging.FileHandler.pattern = "${APP_LOG}/service%u.log.%g"
This does not work as it does not appear to resolve ${APP_LOG} as a system property. Is there a way specify a variable into the Logger config file?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by javed.beg In reply to Java Logger config file s ...

1. Pass the config file name with the exact path while executing your code (A.java):

java A 'C:\boom.cfg'

In side the code, read this arg

fileName = args[0].trim();

2. Read the properties from the config file
File f = new File(fileName);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
Properties prop = new Properties();
prop.load(bis);

3. Read the required property you would have defined in this file

String appLog = aceProperties.getProperty("APP_LOG").trim();

Collapse -

by sbockelman In reply to Java Logger config file s ...

Use your build tool/script (e.g., ant) to substitute the real path when the app is deployed.

Collapse -

by mjremijan In reply to Java Logger config file s ...

Remember, in Java there is no API specification to see system environment variables. To get an environment variable you either need to pass them to the JVM on the command line (java -DAPP_LOG=/var/log/app" or you need to write a piece of wrapper code to call a system-dependent binary or function. So the short answer to your question is no, I don't think so.

Collapse -

by georgehsnyder In reply to Java Logger config file s ...

Download the API and look at :System.
System.getProperty("APP_LOG") should return the system value stored in APP_LOG.

Collapse -

by xitx In reply to Java Logger config file s ...

I did it in this way.

I implemented a log configuration which tells us what handlers are associated with this logger.

In the class which is using the logger, just do it:

Logger myLogger = Logger.getLogger("myName");

In the configuration:

String logFile = "${APP_LOG}/service...";
..getLogger("myName").addHandler( new FileHandler( logFile,... ) );

You can call the configuration somewhere in your system

Wish it helps.
Tianxiao

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums