SmoothCriminel
SmoothCriminel

Reputation: 367

Java Application + Logging

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

Upvotes: 2

Views: 5196

Answers (3)

Fernando Miguélez
Fernando Miguélez

Reputation: 11316

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.

Upvotes: 1

kostja
kostja

Reputation: 61538

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

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240860

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.

Upvotes: 1

Related Questions