Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated to use token logging

  • Loading branch information...
commit 444ccd37c8615d4e749fbcfc837f5b1188dcbdaf 1 parent 2e4c46b
Mark Lacomber MarkLC authored
26 README.md
View
@@ -23,12 +23,15 @@ Simple Usage Example
To configure log4j, you will need to perform the following:
- * (1) Obtain your Logentries account key.
+ * (1) Setup your Logentries account.
* (2) Setup Log4j (if you are not already using it).
* (3) Configure the Logentries Log4j plugin.
-You can obtain your Logentries account key on the Logentries UI, by clicking account in the top left cornercand then display account key on the right.
-
+Account Setup
+-------------
+You can sign up for a Logentries account simply by clicking Sign Up and entering your email address. Once you have your credentials and have logged in,
+create a new host in the UI with a name that represents your app. Then, select this host and create a new logfile with a name that represents what you're
+logging. Select 'TOKEN TCP' as the source_type and click Register to create the log.
log4j Setup
-----------
@@ -46,7 +49,7 @@ Then add it to the build path from within your project.
Logentries log4j Plugin Setup
-----------------------------
-The next file you need is logentries-1.1.4.jar which is the plugin for log4j. It is available from github at:
+The next file you need is logentries-1.1.5.jar which is the plugin for log4j. It is available from github at:
https://github.com/logentries/le_java/downloads
@@ -54,7 +57,7 @@ Place this in the `WEB-INF/lib` folder of your project and add it to the buildpa
The second file required is called log4j.xml and is available again on github on projects pages.
-Add this file to your project as it is the config which adds the plugin for log4j to send logs to Logentries. This file should be in `WEB-INF/classes`
+Add this file to your project as it is the config which adds the plugin for log4j to send logs to Logentries. This file should be in added to the classpath.
In this file, you will see the following:
@@ -62,12 +65,9 @@ In this file, you will see the following:
<!DOCTYPE log4j:configuration>
<log4j:configuration debug="true">
<appender name="le" class="com.logentries.log4j.LeAppender">
- <!-- Enter your Logentries account key, like bc0c4f90-a2d6-11e1-b3dd-0800200c9a66 -->
- <param name="Key" value="LOGENTRIES_ACCOUNT_KEY" />
- <!-- Enter log location, like servername/logname -->
- <param name="Location" value="LOGENTRIES_LOCATION" />
+ <!-- Enter your Logentries token, like bc0c4f90-a2d6-11e1-b3dd-0800200c9a66 -->
+ <param name="Token" value="LOGENTRIES_TOKEN" />
<param name="Debug" value="false" />
- <param name="SSL" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss ZZZ} %-5p (%F:%L) %m" />
@@ -82,11 +82,9 @@ In this file, you will see the following:
</root>
</log4j:configuration>
-Replace the value "LOGENTRIES_ACCOUNT_KEY" with your account-key obtained earlier. Also replace the "LOGENTRIES_LOCATION" value. This should be in the following format:
-
- `hostname/logname.log`
+Replace the value "LOGENTRIES_TOKEN" with the token UUID that appears beside your newly created logfile in grey.
-For debugging purposes set the debug parameter to true. The appender will display debug information on console. You can also activate SSL encryption when used in public networks. Note that SSL encryption may be expensive in terms of CPU usage.
+For debugging purposes set the debug parameter to true. The appender will display debug information on console.
Logging Messages
4 log4j.properties
View
@@ -2,7 +2,5 @@ log4j.rootLogger=DEBUG,le
log4j.appender.le=com.logentries.log4j.LeAppender
log4j.appender.le.layout=org.apache.log4j.PatternLayout
log4j.appender.le.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss ZZZ} %-5p: %F:%L %m
-log4j.appender.le.Key=LOGENTRIES_ACCOUNT_KEY
-log4j.appender.le.Location=LOGENTRIES_LOCATION
+log4j.appender.le.Token=LOGENTRIES_TOKEN
log4j.appender.le.Debug=False
-log4j.appender.le.SSL=False
7 log4j.xml
View
@@ -2,12 +2,9 @@
<!DOCTYPE log4j:configuration>
<log4j:configuration debug="true">
<appender name="le" class="com.logentries.log4j.LeAppender">
- <!-- Enter your Logentries account key, like bc0c4f90-a2d6-11e1-b3dd-0800200c9a66 -->
- <param name="Key" value="LOGENTRIES_ACCOUNT_KEY" />
- <!-- Enter log location, like servername/logname -->
- <param name="Location" value="LOGENTRIES_LOCATION" />
+ <!-- Enter your Logentries token, like bc0c4f90-a2d6-11e1-b3dd-0800200c9a66 -->
+ <param name="Token" value="LOGENTRIES_TOKEN" />
<param name="Debug" value="false" />
- <param name="SSL" value="false" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss ZZZ} %-5p (%F:%L) %m" />
119 src/com/logentries/log4j/LeAppender.java
View
@@ -10,8 +10,6 @@
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
-import javax.net.ssl.SSLSocket;
-import javax.net.ssl.SSLSocketFactory;
/**
* Logentries appender for log4j.
@@ -32,10 +30,8 @@
static final String LE_API = "api.logentries.com";
/** Logentries local API server address for testing. */
static final String LE_LOCAL_API = "localhost";
- /** Default port number for Logentries API server. */
- static final int LE_PORT = 80;
- /** Default SSL port number for Logentries API server. */
- static final int LE_SSL_PORT = 443;
+ /** Port number for Token logging on Logentries API server. */
+ static final int LE_PORT = 10000;
/** Local port number for testing. */
static final int LE_LOCAL_PORT = 8088;
/** UTF-8 output character set. */
@@ -48,22 +44,14 @@
static final int MAX_DELAY = 10000;
/** LE appender signature - used for debugging messages. */
static final String LE = "LE ";
- /** Error message displayed when wrong configuration has been detected. */
- static final String WRONG_CONFIG = "\n\nIt appears you forgot to customize your log4j.xml file!\n\n";
/** Error message displayed when invalid API key is detected. */
- static final String INVALID_KEY = "\n\nIt appears your LOGENTRIES_ACCOUNT_KEY parameter in log4j.xml is invalid!\n\n";
+ static final String INVALID_TOKEN = "\n\nIt appears your LOGENTRIES_TOKEN parameter in log4j.xml is incorrect!\n\n";
/*
* Fields
*/
- /** Factory for SSL connections. */
- final SSLSocketFactory ssl_factory;
- /** Account key. */
- String key;
- /** Log location. */
- String location;
- /** Use SSL indicator. */
- boolean ssl;
+ /** Destination Token. */
+ String token;
/** Debug flag. */
boolean debug;
/** Make local connection only. */
@@ -110,29 +98,16 @@
*/
void openConnection() throws IOException {
final String api_addr = local ? LE_LOCAL_API : LE_API;
- final int port = local ? LE_LOCAL_PORT : (ssl ? LE_SSL_PORT
- : LE_PORT);
+ final int port = local ? LE_LOCAL_PORT : LE_PORT;
dbg( "Reopening connection to Logentries API server " + api_addr
+ ":" + port);
// Open physical connection
- if (ssl) {
- SSLSocket s = (SSLSocket) ssl_factory.createSocket( api_addr,
- LE_SSL_PORT);
- s.setTcpNoDelay( true);
- s.startHandshake();
- socket = s;
- } else {
- socket = new Socket( api_addr, port);
- }
+ socket = new Socket( api_addr, port);
+
stream = socket.getOutputStream();
- // Send identification through HTTP PUT method
- final String f = "PUT /%s/hosts/%s/?realtime=1 HTTP/1.1\r\n\r\n";
- final String header = String.format( f, key, location);
- stream.write( header.getBytes( ASCII));
-
dbg( "Connection established");
}
@@ -237,7 +212,7 @@ public void run() {
*/
LeAppender( boolean local) {
this.local = local;
- ssl_factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
+
queue = new ArrayBlockingQueue<byte[]>( QUEUE_SIZE);
appender = new SocketAppender();
@@ -254,14 +229,14 @@ public LeAppender() {
* Checks that key and location are set.
*/
boolean checkCredentials() {
- if (key == null || location == null)
+ if (token == null)
return false;
- //Quick test to see if ACCOUNT_KEY is a valid UUID
- UUID u = UUID.fromString(key);
- if (!u.toString().equals(key))
+ //Quick test to see if LOGENTRIES_TOKEN is a valid UUID
+ UUID u = UUID.fromString(token);
+ if (!u.toString().equals(token))
{
- dbg(INVALID_KEY);
+ dbg(INVALID_TOKEN);
return false;
}
@@ -269,45 +244,22 @@ boolean checkCredentials() {
}
/**
- * Sets the account key.
+ * Sets the token
*
- * @param key account key
+ * @param token new token
*/
- public void setKey( String key) {
- this.key = key;
-
- dbg( "Setting account key to " + key);
- if (key.equals( "LOGENTRIES_ACCOUNT_KEY")) {
- System.err.println( WRONG_CONFIG);
- }
+ public void setToken( String token) {
+ this.token = token;
+ dbg( "Setting token to " + token);
}
/**
- * Returns the account key.
+ * Returns current token.
*
- * @return account key
+ * @return current token
*/
- public String getKey() {
- return key;
- }
-
- /**
- * Sets the location
- *
- * @param location new location
- */
- public void setLocation( String location) {
- this.location = location;
- dbg( "Setting location to " + location);
- }
-
- /**
- * Returns current location.
- *
- * @return current location
- */
- public String getLocation() {
- return location;
+ public String getToken() {
+ return token;
}
/**
@@ -331,25 +283,6 @@ public boolean getDebug() {
}
/**
- * Sets to use SSL for connection with API server.
- *
- * @param ssl true to enable SSL encryption
- */
- public void setSSL( boolean ssl) {
- this.ssl = ssl;
- dbg( "Setting SSL to " + ssl);
- }
-
- /**
- * Returns current state of SSL connection settings.
- *
- * @return true if SSL is set
- */
- public boolean getSSL() {
- return ssl;
- }
-
- /**
* Appends the data to internal queue to be send over the network.
*
* It does not block. If the queue is full, it removes latest event first to
@@ -361,7 +294,7 @@ void appendLine( String line) {
dbg( "Queueing " + line);
// Convert the line to byte data
- byte[] data = (line + '\n').getBytes( UTF8);
+ byte[] data = (token + line + '\n').getBytes( UTF8);
// Try to append data to queue
boolean is_full = !queue.offer( data);
@@ -384,7 +317,7 @@ protected void append( LoggingEvent event) {
if (!checkCredentials())
return;
if (!started) {
- dbg( "Starting asynchronous socket appender");
+ dbg( "Starting Logentries asynchronous socket appender");
appender.start();
started = true;
}
@@ -406,7 +339,7 @@ protected void append( LoggingEvent event) {
@Override
public void close() {
appender.interrupt();
- dbg( "Closing asynchronous socket appender");
+ dbg( "Closing Logentries asynchronous socket appender");
}
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.