aspose file tools*
The moose likes Other Java Products and Servers and the fly likes Slf4j Logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Slf4j Logger" Watch "Slf4j Logger" New topic
Author

Slf4j Logger

Pawan Singh
Greenhorn

Joined: Jun 05, 2012
Posts: 9

I want to add Logger in my Application. I want every description of application or flow in my XXX.log file.
but since I am very new to it, I don't know anythink about it.
I added slf4j-api.jar + slf4j-simple.jar in my lib folder .... now after that what should I do for proper working of logger.

I also used in my classes as following code.

Logger logger=LoggerFactory.getLogger(HelloWorldAction.class);
logger.debug("ncjkdfbvkb");

other than this I don't know any think, please guide me.
please help me.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8963
    
    9

Have you read the documentation? If so, what specific problem or question do you have?


[How To Ask Questions On JavaRanch]
Pawan Singh
Greenhorn

Joined: Jun 05, 2012
Posts: 9
First of all Thanks for your quick reply.
I already read the documentation. ok, here is what I have done.

added
1- slf4j-api-1.6.6.jar, slf4j-simple-1.6.6.jar in my lib folder of WEB-INF/lib
2- log4j.properties file under src folder. ie inside classes foder. "src\log4j.properties"
log4j.properties consist of:
# [
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.rootLogger=DEBUG, stdout, R
#log4j.rootLogger=ERROR, stdout, R
log4j.appender.R.File=D:\\Projects\\SimpleJAVA\\Struts_Hibernate\\log4j.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxBackupIndex=100
log4j.appender.R.layout.ConversionPattern=%d %p %t %c - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender
# ]
3- I used it as in my code like:
[
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HelloWorld {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World");
logger.debug("In debug"); } }
]

4- What I want: whole logging output should be write to log4j.log file as mentioned in log4j.properties file
5- What's Happening whole logging out is visible in ide console, but not in log4j.log file. In log4j.log file only a very small output is there about 30-40 lines..which is meaningless.

Please help me , I think there is some mistake in log4j.properties file.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8963
    
    9

Pawan Singh wrote:First of all Thanks for your quick reply.
I already read the documentation. ok, here is what I have done.


You must have missed the line:


As mentioned previously, SLF4J supports various logging frameworks. The SLF4J distribution ships with several jar files referred to as "SLF4J bindings", with each binding corresponding to a supported framework.

slf4j-log4j12-1.6.6.jar
Binding for log4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.


I assume this is how one would tell SLF4J to use Log4j.
Harish Onkarappa
Greenhorn

Joined: Oct 31, 2012
Posts: 1
log4j.appender.stdout=org.apache.log4j.ConsoleAppender

change it to

log4j.appender.stdout=org.apache.log4j.RollingFileAppender


and use the log4j version greater than 1.2.12. it wont support if the version is less then that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Slf4j Logger