Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Overview

Trail Android Arsenal

Trail is a simple logging system for Java and Android. Create logs using the same API and the library will detect automatically in which platform the code is running.

Features

  • Easy and direct
  • Same API for Java/Android logging
  • 5 log levels:
    • VERBOSE
    • DEBUG
    • INFO
    • WARNING
    • ERROR
  • 5 different ways to create logs for each level
  • Register/unregister listeners for log events

Log parameters

  • Tag: The tag of the log. It can be any object from which the method toString() will be called. If missing, a default tag with the name of the class where the log is created will be used.

  • Message: The message of the log. It can be any object from which the method toString() will be called.

  • Exception: The exception of the log (if any).

Examples

 // providing only a message
 Trail.verbose("Applicatio started!");
 // providing a tag and a message
 Trail.info("LOGIN", "Successful");
 try
 {
     // do something
 }
 catch (Exception e)
 {
     // providing only an exception
     Trail.debug(e);
 }
 try
 {
     // do something
 }
 catch (NetworkException e)
 {
     // providing a tag and an exception
     Trail.warning("NETWORK_PROBLEM", e);
 }
 try
 {
     // do something
 }
 catch (SQLException e)
 {
     // providing a tag, a message and an exception
     Trail.error("DATABASE_PROBLEM", "Invalid query format", e);
 }

Utils

The library provides a method to retrieve the current location of the executing code:

 Trail.getCodeLocation()

This method returns an instance of the class CodeLocation that contains the name of the thread, the name of the class, the name of the method, the line number and the stack trace of the line of code being executed at that moment. This can be used to add more information to a log.

For example:

 Trail.verbose("LOCATION", "I am at " + Trail.getCodeLocation());

Could generate the following output:

 LOCATION: I am at [main]Sample.run:78

Listeners

The library allows to register/unregister listeners to be informed when a log is created:

 public class SampleListener implements Listener
 {
     public void run()
     {
         // register the object to receive log events
         Trail.register(this);

         // the object will be informed about the following log
         Trail.verbose("Message 1");

         // unregister the object to stop receiving log events
         Trail.unregister(this);
         
         // the object will NOT be informed about the following log
         Trail.info("Tag", "Message 2");
     }

     @Override
     public void onLog(TrailLog log)
     {
         // TODO: process log information (write in a file/database, send by network, etc.)
     }
 }

Global settings

Enable/disable log printing (enabled by default):

 // disables the log printing
 Trail.enableLogPrinting(false);

Enable/disable listeners notification (enabled by default):

 // disables the listener notification
 Trail.enableListenerNotification(false);

Download

Latest JAR:

Download

Maven (from JCenter):

<dependency>
    <groupId>com.mauriciotogneri</groupId>
    <artifactId>trail</artifactId>
    <version>1.0.0</version>
</dependency>

Adding JCenter to pom.xml:

<repositories>
    <repository>
        <id>central</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>

Gradle (from JCenter):

compile 'com.mauriciotogneri:trail:1.0.0'

Adding JCenter to build.gradle:

repositories {
    maven {
        url  "http://jcenter.bintray.com" 
    }
}

Compatibility

Trail works with any version of Java and Android.

License

The MIT License (MIT)

Copyright (c) 2015 Mauricio Togneri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
WebSocket & WAMP in Java for Android and Java 8

Autobahn|Java Client library providing WAMP on Java 8 (Netty) and Android, plus (secure) WebSocket for Android. Autobahn|Java is a subproject of the A

Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.

Disk LRU Cache A cache that uses a bounded amount of space on a filesystem. Each cache entry has a string key and a fixed number of values. Each key m

Android library which makes it  easy to handle the different obstacles while calling an API (Web Service) in Android App.
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Runtime code generation for the Java virtual machine.
Runtime code generation for the Java virtual machine.

Byte Buddy runtime code generation for the Java virtual machine Byte Buddy is a code generation and manipulation library for creating and modifying Ja

Android app that displays the logcat buffer in a system overlay window
Android app that displays the logcat buffer in a system overlay window

Ghost Log Ghost Log is an Android application that displays the device logcat buffer in a system overlay window. NOTE: Device root (superuser) access

📭 Extension to Ktor’s routing system to add object oriented routing and much more. 💜

📭 Ktor Routing Extensions Extension to Ktor’s routing system to add object-oriented routing and much more. 💜 Why? This extension library was created

A logger with a small, extensible API which provides utility on top of Android's normal Log class.
A logger with a small, extensible API which provides utility on top of Android's normal Log class.

This is a logger with a small, extensible API which provides utility on top of Android's normal Log class. I copy this class into all the little apps

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

An easy-to-use, cross-platform measurement tool that pulls data out of CD pipelines and analysis the four key metrics for you.
An easy-to-use, cross-platform measurement tool that pulls data out of CD pipelines and analysis the four key metrics for you.

Maintained by SEA team, ThoughtWorks Inc. Read this in other languages: English, 简体中文 Table of Contents About the Project Usage How to Compute Contrib

Releases(v1.0.0)
Owner
Mauricio Togneri
Mauricio Togneri
A small library which will save you from writing the same intent creation code again and again for the most simple tasks

Android Intents A small library which will save you from writing the same intent creation code again and again for the most simple tasks. I found myse

MarvinLabs 420 Nov 20, 2022
Convert OkHttp requests into curl logs.

Ok2Curl Convert OkHttp requests into curl logs. Usage Add library to project dependencies. Library is hosted on jcenter. repositories { jcenter()

Michal Moczulski 373 Jan 1, 2023
This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho for communication with Chrome DevTools.

J2V8-Debugger This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho f

Alex Trotsenko 76 Jan 3, 2023
SPIDlibraryAndroid is a library for logging in via SPID through several different identity providers.

SPIDlibraryAndroid SPIDlibraryAndroid is a library for logging in via SPID through several different identity providers.

INPS 98 Dec 15, 2022
Same as the Outlined text fields presented on the Material Design page but with some dynamic changes. 📝 🎉

README SSCustomEditTextOutlineBorder Getting Started SSCustomEditTextOutLineBorder is a small kotlin library for android to support outlined (stroked)

Simform Solutions 194 Dec 30, 2022
An Android App which is capable of accessing system apps

Android_Project_Kotlin In this Project I am building an Android App which is capable of accessing system apps. This project is written in Kotlin and I

null 0 Dec 13, 2021
A low intrusive, configurable android library that converts layout XML files into Java code to improve performance

qxml English 一个低侵入,可配置的 Android 库,用于将 layout xml 文件转换为 Java 代码以提高性能。 与X2C的对比 X2C: 使用注解处理器生成View类,使用时需要在类中添加注解,并替换setContentView方法,侵入性较强; 对于布局属性的支持不够完美

null 74 Oct 6, 2022
General purpose utilities and hash functions for Android and Java (aka java-common)

Essentials Essentials are a collection of general-purpose classes we found useful in many occasions. Beats standard Java API performance, e.g. LongHas

Markus Junginger 1.4k Dec 29, 2022
General purpose utilities and hash functions for Android and Java (aka java-common)

Essentials Essentials are a collection of general-purpose classes we found useful in many occasions. Beats standard Java API performance, e.g. LongHas

Markus Junginger 1.4k Dec 29, 2022
WebSocket & WAMP in Java for Android and Java 8

Autobahn|Java Client library providing WAMP on Java 8 (Netty) and Android, plus (secure) WebSocket for Android. Autobahn|Java is a subproject of the A

Crossbar.io 1.5k Dec 9, 2022