Android Logger

Simple Log Wrapper over android.util.Log class

License

License

GroupId

GroupId

com.github.michelzanini
ArtifactId

ArtifactId

android-logger
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Android Logger
Simple Log Wrapper over android.util.Log class
Project URL

Project URL

https://github.com/michelzanini/android-logger
Source Code Management

Source Code Management

https://github.com/michelzanini/android-logger

Download android-logger

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.michelzanini/android-logger/ -->
<dependency>
    <groupId>com.github.michelzanini</groupId>
    <artifactId>android-logger</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.michelzanini/android-logger/
implementation 'com.github.michelzanini:android-logger:1.0.1'
// https://jarcasting.com/artifacts/com.github.michelzanini/android-logger/
implementation ("com.github.michelzanini:android-logger:1.0.1")
'com.github.michelzanini:android-logger:jar:1.0.1'
<dependency org="com.github.michelzanini" name="android-logger" rev="1.0.1">
  <artifact name="android-logger" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.michelzanini', module='android-logger', version='1.0.1')
)
libraryDependencies += "com.github.michelzanini" % "android-logger" % "1.0.1"
[com.github.michelzanini/android-logger "1.0.1"]

Dependencies

provided (1)

Group / Artifact Type Version
com.google.android : android jar 4.0.1.2

Project Modules

There are no modules declared in this project.

Android Logger

View the project's web site here.

It is hard to work with log levels when using android.util.Log class.
The methods are short and not very readable, like Log.d, Log.e, etc... There aren`t many options to format the log.
Also, there are a few bugs, like logging a null String will crash the app.

This project is a simple wrapper above the android.util.Log class. It is similar to Apache Commons Logging, as many may be used to. The log levels available are: verbose, debug, info, warn and error.

This is an example of how to obtain a Logger instance:

//using a String as Log Tag
Logger logger = LoggerFactory.getLogger("LOG_TAG");

//using a class name as Log Tag
Logger logger = LoggerFactory.getLogger(getClass());

These are some of the log methods available:

//logging a String message
logger.debug("String message");

//logging a String using arguments to format the string (message and params are used with String.format())
logger.info("String with params: Param 1 = %s, Param 2 = %s", "Param 1 Value", "Param 2 Value");

//logging a Exception
logger.error(e);

//logging a message and a Exception
logger.error("Message", e);

How to set the desired log level for logging (default is Level.INFO):

//log level constant from code
LoggerFactory.setLevel(LoggerLevel.DEBUG);

//log level constant from strings.xml
LoggerFactory.setLevelFromStringResource(context, R.string.log_level);

/*
in the 'strings.xml' file
<string name="log_level">DEBUG</string>
*/

How to filter log messages that can impact performance:

if (logger.isDebugEnabled()) {
   logger.debug("Message " + variable + " something else...");
}

How to get it

Download the bundle or add it as a Maven dependency:

<dependency>
   <groupId>com.github.michelzanini</groupId>
   <artifactId>android-logger</artifactId>
   <version>1.0.1</version>
</dependency>

Versions

Version
1.0.1
1.0.0