Coder Social home page Coder Social logo

le_android's Introduction

Logging support for Android devices

License

Build requirements: Android SDK 2.3+ Runtime requirements: Android OS 2.3+

Setup

Set up an account with Logentries at https://logentries.com/, and create a logfile, by clicking + Add New button and selecting the Manual Configuration Option at the bottom. Select Token TCP as the source type and copy the Token UUID printed in green.

Next, download the library jar file here and place it in the /yourProject/libs folder of your Android project.

Add the android.permission.INTERNET to the project manifest file.

Use

In the desired Activity class, import com.logentries.android.AndroidLogger

To create an instance of the Logger object in an Activity class: AndroidLogger logger = AndroidLogger.getLogger(Context context, String token); Where

  • context: for example, if in an Activity class, use getApplicationContext(), or if in an Application class, use getBaseContext().

  • 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

Eg: 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.

Logging Device IP

Alternative Constructor which allows a User to log the devices IP:

To create an instance of the Logger object in an Activity class:

AndroidLogger logger = AndroidLogger.getLogger(Context context, String token, boolean logIp);

Where

  • context: for example, if in an Activity class, use getApplicationContext(), or if in an Application class, use getBaseContext().

  • token: is the Token UUID we copied earlier which represents the logfile on Logentries

  • logIp: Is an option to log the users IP address. The IP logged will be the public if it is available otherwise it is gotten via the Host Address.

DataHub Support

Additional constructors for AndroidLogger have been created for use with Logentries DataHub. There are two additional constructors added, one with a customID and one without customID. They are respectively:

  AndroidLogger logger = AndroidLogger.getLogger(Context context, String datahub_address, int datahub_port);

and

 AndroidLogger logger = AndroidLogger.getLogger(Context context, String datahub_address, int datahub_port, String customID);
  • context: for example, if in an Activity class, use getApplicationContext(), or if in an Application class, use getBaseContext().

  • datahub_address: is a String of the IP Address of your DataHub machine.

  • datahub_port: is an int of the port number of your incoming connection on your DataHub machine. The default is port 10000, but this can be changed to any port by altering the /etc/leproxy/leproxyLocal.config file on your DataHub machine and restarting the leproxy daemon using "sudo service leproxy restart".

  • customID - is a String of the customID you may wish to add to your log events. This is different from the deviceID which is now automatically set and entered into your logs.

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)

le_android's People

Contributors

marklc-r7 avatar c-fenlon avatar m0wfo avatar hirro avatar jedi4ever avatar michael-seibert-le avatar omgapuppy avatar ericntd-legacy avatar

Watchers

Hendrik Dacquin avatar James Cloos avatar Wouter De Rijck avatar  avatar  avatar

Forkers

vrtprivate

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.