-
1. Re: Write into log file
jtahlborn Jun 28, 2013 5:58 PM (in response to senthilmca)you are instantiating LOGGER before you are configuring log4j. i would imagine that isn't going to work very well. (and your logging config is apparently problematic as well).
-
2. Re: Write into log file
senthilmca Jun 29, 2013 6:27 AM (in response to jtahlborn)thanks,
could you pls share the code sample (working version)
-
3. Re: Write into log file
836548 Jul 2, 2013 1:25 PM (in response to senthilmca)don't expect for ready answers. earlier it is already pointed why the program is giving error.
-
4. Re: Write into log file
senthilmca Jul 2, 2013 1:49 PM (in response to 836548)@836548,
I tried the way jtahlborn suggested.
Still problem is there.
If you have solution provide and dont comment on other posts.
-
5. Re: Write into log file
836548 Jul 3, 2013 12:53 PM (in response to senthilmca)what i said earlier was correct, unless you want to try your self on the given pointers .
Below is the working program:
logging.propertieslog4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=D:/testLogger.log
log4j.appender.R.MaxFileSize=220KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout //Layout is required, hence added
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout //Layout is required, hence added
Main Program
[code]
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;class TestLogger
{
static {
PropertyConfigurator.configure("logging.properties");
}
public static void main(String[] args) {
final Logger LOGGER = Logger.getLogger(TestLogger.class.getName());
try {
LOGGER.info("The log message.");
LOGGER.info("My first log");
} catch (SecurityException e) {
e.printStackTrace();
}
LOGGER.info("Hi How r u?");
}
}[code]
command to compile and run
javac -cp .;log4j-1.2.13.jar TestLogger.java
java -cp .;log4j-1.2.13.jar TestLogger