Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ to any port by altering the /etc/leproxy/leproxyLocal.config file on your DataHu
The logger will now add the android deviceID as a Key Value Pair in your logs. This requires API 9 and above.

NOTE: You cannot use both Token-based and DataHub-based AndroidLogger constructors in your application. You can only use one or the other.

## Raw Message/Json Support
By default the timestamp and other configurable elements get logged with the message.
To send a raw logmessage (for example to log plain json) you can configure that the logger sends the raw message

AndroidLogger logger = AndroidLogger.getLogger(Context context, String datahub_address, int datahub_port);
logger.setSendRawMessage(true)
Binary file modified lib/logentries-android-2.1.4.jar
Binary file not shown.
15 changes: 15 additions & 0 deletions src/main/java/com/logentries/android/AndroidLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ public boolean getImmediateUpload() {
return immediateUpload;
}

/**
* @param raw true if messages needs to be send as raw Logentries messages
*/
public void setSendRawMessage(boolean raw) {
le.setSendRawMessage(raw);
}

/**
* @return true if messages are send as raw Logentries messages
*/
public boolean getSendRawMessage() {
return le.getSendRawMessage();
}


/**
* disconnect from theLogentries server
*/
Expand Down
47 changes: 38 additions & 9 deletions src/main/java/com/logentries/android/LogentriesAndroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class LogentriesAndroid extends Handler {
boolean datahub_enabled = false;
String m_customID="";

/** Send raw message , useful for sending json data */
boolean send_raw_message = false;

/** Asynchronous socket appender */
SocketAppender appender;
Expand Down Expand Up @@ -368,15 +370,25 @@ public boolean checkCredentials() {
public void publish(LogRecord record) {
Log.w(TAG, "publish");
Date dateTime = new Date(record.getMillis());
String MESSAGE = this.format(dateTime, record.getMessage(), record.getLevel());

// Append message with deviceID (Requires API 9 or above
MESSAGE = "deviceID="+Build.SERIAL +" " + MESSAGE;

// Append message with customID
if (!m_customID.equals("")){
MESSAGE = "customID="+m_customID +" " + MESSAGE;
}

String MESSAGE = "";

if (send_raw_message) {
// Send the message as is
MESSAGE = record.getMessage();
} else {
// Add information to the logged message

MESSAGE = this.format(dateTime, record.getMessage(), record.getLevel());

// Append message with deviceID (Requires API 9 or above
MESSAGE = "deviceID="+Build.SERIAL +" " + MESSAGE;

// Append message with customID
if (!m_customID.equals("")){
MESSAGE = "customID="+m_customID +" " + MESSAGE;
}
}

if (!datahub_enabled){

Expand Down Expand Up @@ -439,4 +451,21 @@ public void upload(String toUpload) {
LogRecord record = new LogRecord(Level.INFO, toUpload);
publish(record);
}


/**
* @param true send raw message to logentries
*/
public void setSendRawMessage(boolean send) {
send_raw_message = send;
}

/**
* @return true if events messages are to send in the raw form to logentries
* default value: false
*/
public boolean getSendRawMessage() {
return send_raw_message;
}

}