Giter Club home page Giter Club logo

loggliest's Introduction

Loggliest Download

Android Loggly client. Loggliest provides asynchronous logging that queues log messages locally in the internal app storage and uploads logs to Loggly using the HTTP/S bulk api.

Setup

Add this to your Gradle configuration:

dependencies {
    compile 'com.inrista.loggliest:loggliest:0.2'
}

Loggliest is available on JCenter which is the default repository, so no further configuration should be necessary. Loggliest depends on Retrofit 1.9.0 and requires API level 9 (Android 2.3). It requires the internet permission.

Usage

First, before you log any messages, initialize the global singleton instance using the Builder provided by with(android.content.Context, String). You must provide your Loggly token. A minimal setup looks like this:

final String TOKEN = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
Loggly.with(this, TOKEN).init();

You typically init Loggliest in your MainActivity's onCreate() or in an Application subclass. Either way, Loggliest keeps a global application context and lives as long the app process lives so that you can log for instance activity state changes.

Log a message:

Loggly.i("stringfield", "test"); 
Loggly.i("numberfield", 123);

Log messages are formatted as json messages as expected by Loggly. Along with the json field and value provided by calling one of the log functions, a "level" field is appended with the current log level (verbose, debug, info, warning, error), and a "timestamp" set according to when the message was logged. Also, a set of various default fields can be appended, including app version name and number.

The log messages are saved in the internal app storage and uploaded to Loggly in bulk when either one of these conditions are fulfilled:

  1. The time since the last upload exceeds the uploadIntervalSecs(int seconds) setting
  2. The number of log messages since the last upload exceeds the uploadIntervalLogCount(int count) setting
  3. A new Loggly instance is created and there are (old) messages that have not previously been uploaded. This will happen for instance when the app is killed and the user restarts it some time later
  4. forceUpload() is called

A typical configuration that sets upload intervals to 30mins, max number of messages between uploads to 1000 messages, limits the internal app storage log buffer to 500k and appends the default info fields along with a custom language field looks like this:

Loggly.with(this, TOKEN)
    .appendDefaultInfo(true)
    .uploadIntervalLogCount(1000)
    .uploadIntervalSecs(1800)
    .maxSizeOnDisk(500000)
    .appendStickyInfo("language", currentLanguage)
    .init();

By default, each message gets the app's package name as its Loggly tag, but this can be changed by setting the tag(String logglyTag) on the Builder.

NOTE: Short upload intervals will have a negative effect on the battery life. You want to carefully configure the upload settings and limit the amount of data you log in production settings so as to limit the impact on battery life and network data usage your logging causes.

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

loggliest's People

Contributors

inrista avatar

Watchers

 avatar

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.