Saturday, March 10, 2012

Using log4j for logging
My this post will show you, how to use "log4j" to do logging events happening inside your code. Log4j is the most simple and flexible logging framework I have ever used. Here we will  learn how to configure log4j for our applications. Let's get started first download the latest version of log4j ( latest log4j jar file download). I am using log4j version 1.2.16.
Steps
a) Set classpath for log4j-1.2.16.jar :-
   

    In this  example I am setting my workspace inside my C:\ drive. The full path for this application is "C:\log4j workspace". I am putting the log-jar file in this path and now setting the class path variable from the system's environmental, shown in the snap-shot attached. 

b) Writing the java class :-
    Inside my working space, I  am creating two sub-folders "src" and "class" to store java class and compiled class file respectively, to add package structure I am adding "com/sourav/java" sub-folder structure inside "src" folder.

  Now, we will write "HelloLogTest.java" class inside the "C:\log4j workspace\src\com\sourav\java" folder.



c) Compile and run the java class :-
    Now, I will show you how to run that simple java program using command-prompt. To run java program from the command prompt, we need to set the path variable up-to "bin" folder of the jdk installed in your system.

Now type "javac" command in your command-prompt and it will show you a list of help, if the java path variable is properly installed.

To compile and run the "HelloLogTest.java" file, follow the attached screen-shot.



 Hope you will love running this simple logging example, and will feel eager to dig more into log4j.






Saturday, December 12, 2009

My first blog post

hello, all my friend and foes...i have just created my blog. So, i am really very happy to do it, and i don't know what to do now..but don't worry i will come after a short time and will do something meaningful(at least i will try to do so.. :))..