Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #55 from StephenHynes7/send-raw-log-message
Browse files Browse the repository at this point in the history
Add ability to send raw log message
  • Loading branch information
StephenHynes7 authored Sep 13, 2016
2 parents b0077c5 + f44d6bc commit 64a275a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
16 changes: 16 additions & 0 deletions lib/src/main/java/com/logentries/logger/AndroidLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ public static synchronized AndroidLogger getInstance() {
}
}

/**
* Set whether you wish to send your log message without additional meta data to Logentries.
* @param sendRawLogMessage Set to true if you wish to send raw log messages
*/
public void setSendRawLogMessage(boolean sendRawLogMessage){
loggingWorker.setSendRawLogMessage(sendRawLogMessage);
}

/**
* Returns whether the logger is configured to send raw log messages or not.
* @return
*/
public boolean getSendRawLogMessage(){
return loggingWorker.getSendRawLogMessage();
}

public void log(String message) {
loggingWorker.addLineToQueue(message);
}
Expand Down
27 changes: 23 additions & 4 deletions lib/src/main/java/com/logentries/logger/AsyncLoggingWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class AsyncLoggingWorker {
*/
private boolean started = false;

/**
* Whether should send logs with or without meta data
*/
private boolean sendRawLogMessage = false;

/**
* Asynchronous socket appender.
*/
Expand All @@ -73,7 +78,7 @@ public AsyncLoggingWorker(Context context, boolean useSsl, boolean useHttpPost,

queue = new ArrayBlockingQueue<String>(QUEUE_SIZE);
localStorage = new LogStorage(context);
appender = new SocketAppender(useHttpPost, useSsl, useDataHub, dataHubAddress, dataHubPort, logToken, logHostName);
appender = new SocketAppender(useHttpPost, useSsl, useDataHub, dataHubAddress, dataHubPort, logToken, logHostName, sendRawLogMessage);

This comment has been minimized.

Copy link
@rwtaylorjr

rwtaylorjr Feb 6, 2018

Unless i'm missing something, SocketAppender will always have a value of false for sendRawLogMessage. Even though you have provided a setter, you will need to create an instance of AsyncLoggingWorker in order to use that setter; however, by then, it's too late because a value of false has already been passed to SocketAppender.

appender.start();
started = true;
}
Expand All @@ -91,6 +96,14 @@ public AsyncLoggingWorker(Context context, boolean useSsl, String logToken, Stri
this(context, useSsl, false, true, logToken, dataHubAddr, dataHubPort, true);
}

public void setSendRawLogMessage(boolean sendRawLogMessage){
this.sendRawLogMessage = sendRawLogMessage;
}

public boolean getSendRawLogMessage(){
return sendRawLogMessage;
}

public void addLineToQueue(String line) {

// Check that we have all parameters set and socket appender running.
Expand Down Expand Up @@ -182,9 +195,10 @@ private class SocketAppender extends Thread {
private int dataHubPort;
private String token;
private boolean logHostName = true;
private boolean sendRawLogMessage = false;

public SocketAppender(boolean useHttpPost, boolean useSsl, boolean isUsingDataHub, String dataHubAddr, int dataHubPort,
String token, boolean logHostName) {
String token, boolean logHostName, boolean sendRawLogMessage) {
super("Logentries Socket appender");

// Don't block shut down
Expand All @@ -197,6 +211,7 @@ public SocketAppender(boolean useHttpPost, boolean useSsl, boolean isUsingDataHu
this.dataHubPort = dataHubPort;
this.token = token;
this.logHostName = logHostName;
this.sendRawLogMessage = sendRawLogMessage;
}

private void openConnection() throws IOException, InstantiationException {
Expand Down Expand Up @@ -246,8 +261,11 @@ private boolean tryUploadSavedLogs() {

logs = localStorage.getAllLogsFromStorage(false);
for (String msg = logs.peek(); msg != null; msg = logs.peek()) {
leClient.write(Utils.formatMessage(msg.replace("\n", LINE_SEP_REPLACER),
logHostName, useHttpPost));
if(sendRawLogMessage){
leClient.write(Utils.formatMessage(msg.replace("\n", LINE_SEP_REPLACER),logHostName, useHttpPost));
}else{
leClient.write(msg.replace("\n", LINE_SEP_REPLACER));
}
logs.poll(); // Remove the message after successful sending.
}

Expand Down Expand Up @@ -381,4 +399,5 @@ public void run() {
}
}


}

0 comments on commit 64a275a

Please sign in to comment.