Build requirements: Android SDK 1.5+ Runtime requirements: Android OS 1.5+
Set up an account with Logentries at https://logentries.com/, and register a host by selecting Hosts and then New (in the top right). The host name is for your own benefit.
Then create a logfile, by clicking New Log (in the top right) and give it a name for your own benefit. Be sure to choose Token TCP as the source type.
The token UUID used in green will be used in the next step.
Next, download the library jar file here and place it in the /lib folder of your Android project.
Add the android.permission.INTERNET to the project manifest file.
In the desired Activity class,
To create an instance of the Logger object in an Activity class:
AndroidLogger logger = AndroidLogger.getLogger(Context context, String token);
context: for example, if in an Activity class, use
getApplicationContext(), or if in an Application class, use
token: is the Token UUID we copied earlier which represents the logfile on Logentries
Log events are created using the following methods of the AndroidLogger class, which differ only in terms of the severity level they report:
- severe, debug, info, config, fine, finer, finest, verbose
logger.error("Log Event Contents"); creates the log
Sat Jul 30 16:04:36 GMT+00:00 2011, severity=ERROR, Log Event Contents.
Each method corresponds to those used in android.util.Log and java.util.logging.Logger.
logger.setImmediateUpload(boolean) to control the buffering of logs
false: logs are saved offline until
logger.uploadAllLogs()is called Logs must be saved to a file when the application is closed: logger.saveLogs()
true: logs are uploaded immediately The default value is
logger.getImmediateUpload()returns the current value.
The logs will now be available in your Logentries account under hostname > logname.
To upload log events at a particular interval, use
TimedLogger (a subclass
TimedLogger logger = TimedLogger.getLogger(context, userkey, hostname, logname) logger.start(float timeDelay)
- timeDelay: time in seconds between uploads
Create logs in the same way as with
logger.uploadAllLogs() may still be used to force the upload of any saved
To extend or alter the function of the library, subclass
The protected AndroidLogger constructor requires the same parameters as
getLogger(), and can simply call
super() with them.
To add methods for the creation of different log severities,
process(String logContents, String severity) with the desired severity
getSavedLogs() store and access log events in a file on
the device's internal storage between sessions. This is private to the app and
unseen by the user. Override these methods to save logs to a different
location when the app is not in use. While the app is open, logs are saved to