2

I am bit confused so, thought to ask experts.

I have written small java application. I have function which reads properties files which contains the path of the directory where to write the log and exceptions. Lets say I get exception while reading the properties file since logger wouldn't have been initialized by that time, how can I know that there was an error or exception? If I have written e.printStackTrace() in catch block where it will be printed? I am running this application through windows scheduler.

Thanks for advice.

BR SC

3 Answers 3

1

Forget about Log4j. That was useful when logging capabilites were not embbeded inside JRE itself. You can configure the logging properties by a means of a logging.properties file (which is provided at JVM start point). Inside the application you can log messages with different levels of severity with or without nested exceptions.

Here is a useful page with example of basic configuration and logging capabilites use.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. I am already using java.util.logging. Will follow the link to implement at global level. So, there can be only ONE global log for all applications? Can I create separate log in particular for each different application. BR. SC
I got it... I can use java.util.logging.config.file=myLoggingConfigFilePath... it should contain the log file name as well? e.g. "d:\test\logging.properties". Thanks. SC.
# (The output file is placed in the directory # defined by the "user.home" System property.) java.util.logging.FileHandler.pattern=%h/java%u.log. Is it necessary to define the "user.home" system property? I want o have separate file in separate folder for different application. BR. SC.
No, you do not need to define a "user.home". By default is current directory of running JVM. If you run different applications I assume you run different JVMs, so there is no problem at all (you use different configuration files each time).
1

Use log4j configure it [here it will configure it self by using log4j.properties or .xml from the classpath ] , initialize it in app startup and use it app wide.

Comments

0

If you want to know for sure that the exception was thrown, don't catch it :)

The printStackTrace() writes to stderr. You could run your app though console to read it.

If you want to log no matter what without any config or extra libs, you can use java-util.logging which is bundled with the jdk and writes to stdout by default

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.