This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Not able to save logs into .log file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Not able to save logs into .log file" Watch "Not able to save logs into .log file" New topic
Author

Not able to save logs into .log file

Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
I am using SLF4J and as per requirement i have to store the logs into the .log file. But when i run the program the log are not written into thelog file.

Here is the code







i want to store the log into the C:\checkLog.log.

does anyone help me to solve this problem.

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Is your log4j properties in the CLASSPATH?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Hi Martijn Verburg,

Thanks for your quick response..!!

But how can i put log4j.properties into CLASSPATH..?? As this is not a jar file.

Any suggestion for store the log4j.properties into classpath.?

Thanks ,
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

You can drop it into any directory that is on your CLASSPATH, so for example in the directory that has your .class files (or your .jar file) or say where your third party libs are (log4j.jar).
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
I have added ths log4j.properties into the classpath..

here is the .classpath now..!!




But now if i run the program ..still the debug values are not saved into the C:\checkLog.log file..

does i am missing something.??
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Ah, I see you are using Eclipse . You almost had the right idea! You can't actually add the log4.properties file as a library, so you'll want to remove that line to start with.

All you need to do is to put the log4j.properties file into one of your src directories. When Eclipse compiles for you it will make a copy of that file into the target directory, which means it's automatically on the CLASSPATH.
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Hi,

here is the project structure.


Yes you are right...if i put log4j.properties file into the src directory,the eclipse load that file into CLASSPATH automatically.

But still the debug statement value is not stord into the file (C:\checkLog.log).

For storing that log,does i need to do some extra configuration into the Eclipse.??


Thanks,
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK, good stuff! Now you need to look at the Threshold value you have set in your properties file, see how it's set to INFO? That's too high for your debug messages....
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Here is modified log4j.properties.



when i run the program i get following output on console.

In main method i have added following code for showing all values.




I can see following output on console



but i am not able to see debug value on console as well as in log file..!!

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Try DEBUG as opposed to debug in your properties config.
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Hi,

I tried with DEBUG Value. Still debug value is not stored into the file as well as on console

I tried with isDebugEnabled() method which always return false result..

Do i need do some configuration for isDebugEnabled() to set true.???

I am using SLF4J.

Thanks
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you show your logger configuration for the console appender? I only se the file one there
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
log4j.property file:
I have done some modification with log4j.property file.
here is complete log4j.property file.



Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

TRy setting a threshold on your CA appender.
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Still it is not working..

Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Hi..

I think this is problem of SLF4J. Because i tried with Log4J I am able to store the log into the log file.

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I'm not overly familiar with SLF4J, I was pretty much steering you in the direction that Log4J would take (I understand they have similar configuration). Have you tried the how to examples on the slf4j website?
Arvind Porlekar
Ranch Hand

Joined: Dec 31, 2008
Posts: 38
Hi Martijn Verburg

I am able to run the application with storing the log into log files.
I have added 3 jars into CLASSPATH as
1. log4j-1.2.12.jar
2. slf4j-api-1.6.1.jar
3. slf4j-log4j12-1.6.1.jar

Thanks for your quick response.

Regards
Arvind
Geeta Puttappanavar
Ranch Hand

Joined: Jan 18, 2012
Posts: 43
Arvind Porlekar wrote:Hi Martijn Verburg

I am able to run the application with storing the log into log files.
I have added 3 jars into CLASSPATH as
1. log4j-1.2.12.jar
2. slf4j-api-1.6.1.jar
3. slf4j-log4j12-1.6.1.jar

Thanks for your quick response.

Regards
Arvind


Hi Martin,

Even I’m facing the same problem. I tried with simple java application, that’s working fine.

But for web application ‘m not at all getting the logs both in log file & console.

If you share your web application log4j example. Really that helps me a lot.

Thanks,
Geeta
Panikiran Venkatesh Periyapatna
Greenhorn

Joined: Aug 05, 2009
Posts: 1
Even i am facing the same issue. As soon as the application boots up. It reads the properties file and creates the log file. But nothing gets logged into the file.

Any solution found?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to save logs into .log file
 
Similar Threads
Can Log4j read two properties?
Log4J created two log files but should have only done one
Can Logger be protected?
Difference between Static and Instance Methods
Help Please -log4j:WARN No appenders could be found for logger