From 1d238e646b0fcf72c9dfaabb83cb7923e82edbe7 Mon Sep 17 00:00:00 2001 From: Geremy Cohen Date: Mon, 29 Jul 2013 20:59:57 -0700 Subject: [PATCH] Update README.md Added logging details --- java/README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/java/README.md b/java/README.md index 28b8615af..aa828e94b 100644 --- a/java/README.md +++ b/java/README.md @@ -40,6 +40,73 @@ $ ant test $ ant clean build test ``` +###Configuring Logging +Pubnub implements swappable logging using SLF4J, which allows you to switch different logging frameworks easily. All the logging calls using SLF4J API will be delegated to the underlying logging framework. + +Before you enable logging, you need to create a "debug-build" version of the Pubnub-StandardEdition.jar. + +####To create a debug-build + +1. Go to Terminal on Mac/Linux or command-line on Windows +2. Change directory to the Java folder where you have cloned the git java repo of pubnub (https://github.com/pubnub/java.git) +3. Type "ant debug-build" +4. The debug version of Pubnub-StandardEdition jar file (e.g Pubnub-StandardEdition-3.x.x.jar) will be created. +5. Add this jar as a reference in your project. + +To implement logging using log4j you need to add the following references to the project. Using log4j you can log to console or a file or both. + +1. slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API +2. slf4j-log4j jar file (e.g. slf4j-log4j-1.7.5.jar or a latest version) which acts as a bridge between slf4j and log4j +3. log4j jar file (log4j-1.2.17.jar or a latest version), which provides the underlying logging framework +4. Along with these references you need to add the log4j.properties file in the CLASSPATH + +For example, in your log4j.properties file, configure it to write the logs to a log file: +```java +# Root logger option +log4j.rootLogger=ALL, FILE + +# Direct log messages to a log file +log4j.appender.FILE =org.apache.log4j.FileAppender +log4j.appender.FILE.File=/Users/rajat/Projects/eclipsews/log4jloging.log +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +``` + +More info can be found here http://www.tutorialspoint.com/log4j/log4j_configuration.htm + + +ii) To implement logging using simple slf4j you need to add the following references to the project +- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API +- slf4j-simple jar file (e.g. slf4j-simple-1.7.5.jar or a latest version) which provides the underlying logging framework +- Along with these references you need to add the simplelogger.properties file in the CLASSPATH + +iii) To implement logging using logback-classic you need to add the following references to the project +- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API +- logback-classic and logback-core jar files which provide the underlying logging framework + +iv) To implement logging using java.util.logging you need to add the following references to the project +- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API +- slf4j-jdk14 jar file which acts as a bridge between slf4j and java +- JVM runtime provides the underlying logging framework + +v) To implement logging using commons-logging you need to add the following references to the project +- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API +- slf4j-jcl jar file which acts as a bridge between slf4j and common-logging +- common-logging.jar file which acts as an abstraction layer +- The underlying logging framework is chosen dynamically by commons-logging + +vi) To implement no logging you have two options + +Option 1: +- Add the reference of slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API and nothing else. + +Option 2: +- Add the reference of slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API. +- And add a reference to slf4j-nop jar file (e.g. slf4j-nop-1.7.5.jar or a latest version). + + +More info on SLF4J can be found at http://stackoverflow.com/questions/8737204/how-slf4j-works-no-log-getting-created + ###To run the DemoConsole: ``` $ cd jars