Skip to content

Commit 1d238e6

Browse files
author
Geremy Cohen
committed
Update README.md
Added logging details
1 parent d1021df commit 1d238e6

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

‎java/README.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,73 @@ $ ant test
4040
$ ant clean build test
4141
```
4242

43+
###Configuring Logging
44+
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.
45+
46+
Before you enable logging, you need to create a "debug-build" version of the Pubnub-StandardEdition.jar.
47+
48+
####To create a debug-build
49+
50+
1. Go to Terminal on Mac/Linux or command-line on Windows
51+
2. Change directory to the Java folder where you have cloned the git java repo of pubnub (https://github.com/pubnub/java.git)
52+
3. Type "ant debug-build"
53+
4. The debug version of Pubnub-StandardEdition jar file (e.g Pubnub-StandardEdition-3.x.x.jar) will be created.
54+
5. Add this jar as a reference in your project.
55+
56+
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.
57+
58+
1. slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
59+
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
60+
3. log4j jar file (log4j-1.2.17.jar or a latest version), which provides the underlying logging framework
61+
4. Along with these references you need to add the log4j.properties file in the CLASSPATH
62+
63+
For example, in your log4j.properties file, configure it to write the logs to a log file:
64+
```java
65+
# Root logger option
66+
log4j.rootLogger=ALL, FILE
67+
68+
# Direct log messages to a log file
69+
log4j.appender.FILE =org.apache.log4j.FileAppender
70+
log4j.appender.FILE.File=/Users/rajat/Projects/eclipsews/log4jloging.log
71+
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
72+
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
73+
```
74+
75+
More info can be found here http://www.tutorialspoint.com/log4j/log4j_configuration.htm
76+
77+
78+
ii) To implement logging using simple slf4j you need to add the following references to the project
79+
- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
80+
- slf4j-simple jar file (e.g. slf4j-simple-1.7.5.jar or a latest version) which provides the underlying logging framework
81+
- Along with these references you need to add the simplelogger.properties file in the CLASSPATH
82+
83+
iii) To implement logging using logback-classic you need to add the following references to the project
84+
- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
85+
- logback-classic and logback-core jar files which provide the underlying logging framework
86+
87+
iv) To implement logging using java.util.logging you need to add the following references to the project
88+
- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
89+
- slf4j-jdk14 jar file which acts as a bridge between slf4j and java
90+
- JVM runtime provides the underlying logging framework
91+
92+
v) To implement logging using commons-logging you need to add the following references to the project
93+
- slf4j-api jar file (e.g. slf4j-api-1.7.5.jar or a latest version) which is the SLF4J API
94+
- slf4j-jcl jar file which acts as a bridge between slf4j and common-logging
95+
- common-logging.jar file which acts as an abstraction layer
96+
- The underlying logging framework is chosen dynamically by commons-logging
97+
98+
vi) To implement no logging you have two options
99+
100+
Option 1:
101+
- 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.
102+
103+
Option 2:
104+
- 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.
105+
- And add a reference to slf4j-nop jar file (e.g. slf4j-nop-1.7.5.jar or a latest version).
106+
107+
108+
More info on SLF4J can be found at http://stackoverflow.com/questions/8737204/how-slf4j-works-no-log-getting-created
109+
43110
###To run the DemoConsole:
44111
```
45112
$ cd jars

0 commit comments

Comments
 (0)