• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Slf4j Logger

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you read the documentation? If so, what specific problem or question do you have?
 
Pawan Singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic