diff --git a/lib/src/main/java/com/logentries/logger/AndroidLogger.java b/lib/src/main/java/com/logentries/logger/AndroidLogger.java index d7bd9b4..f141611 100644 --- a/lib/src/main/java/com/logentries/logger/AndroidLogger.java +++ b/lib/src/main/java/com/logentries/logger/AndroidLogger.java @@ -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); } diff --git a/lib/src/main/java/com/logentries/logger/AsyncLoggingWorker.java b/lib/src/main/java/com/logentries/logger/AsyncLoggingWorker.java index f4ee777..c1d36b8 100644 --- a/lib/src/main/java/com/logentries/logger/AsyncLoggingWorker.java +++ b/lib/src/main/java/com/logentries/logger/AsyncLoggingWorker.java @@ -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. */ @@ -73,7 +78,7 @@ public AsyncLoggingWorker(Context context, boolean useSsl, boolean useHttpPost, queue = new ArrayBlockingQueue(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); appender.start(); started = true; } @@ -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. @@ -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 @@ -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 { @@ -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. } @@ -381,4 +399,5 @@ public void run() { } } + }