Logging Adapters for Java

Adapters for various Java and Android logging implementations

License

License

Categories

Categories

Java Languages Logging Application Layer Libs
GroupId

GroupId

com.cookingfox
ArtifactId

ArtifactId

logging-adapter-java
Last Version

Last Version

0.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

Logging Adapters for Java
Adapters for various Java and Android logging implementations
Project URL

Project URL

http://github.com/cookingfox/logging-adapter-java
Project Organization

Project Organization

Cooking Fox
Source Code Management

Source Code Management

http://github.com/cookingfox/logging-adapter-java

Download logging-adapter-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.cookingfox/logging-adapter-java/ -->
<dependency>
    <groupId>com.cookingfox</groupId>
    <artifactId>logging-adapter-java</artifactId>
    <version>0.4.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.cookingfox/logging-adapter-java/
implementation 'com.cookingfox:logging-adapter-java:0.4.0'
// https://jarcasting.com/artifacts/com.cookingfox/logging-adapter-java/
implementation ("com.cookingfox:logging-adapter-java:0.4.0")
'com.cookingfox:logging-adapter-java:jar:0.4.0'
<dependency org="com.cookingfox" name="logging-adapter-java" rev="0.4.0">
  <artifact name="logging-adapter-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.cookingfox', module='logging-adapter-java', version='0.4.0')
)
libraryDependencies += "com.cookingfox" % "logging-adapter-java" % "0.4.0"
[com.cookingfox/logging-adapter-java "0.4.0"]

Dependencies

provided (2)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.12
com.google.android : android jar 4.1.1.4

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-core jar 1.3
com.jcabi : jcabi-matchers jar 1.3
ch.qos.logback : logback-classic jar 1.1.3

Project Modules

There are no modules declared in this project.

Logging Adapters for Java

Adapters for various Java and Android logging implementations.

Build Status

Features

  • Contains adapters for popular logging libraries. (i.e. Android Log, SLF4J)
  • Easy to implement your own adapter through a simple interface.
  • Simple log method calls: no need to define a TAG (Android) or create a logger per class (SLF4J).

Download

Download Maven Central

The distribution is hosted on Bintray. To include the package in your projects, you can add the jCenter repository.

Gradle

Add jCenter to your repositories block:

repositories {
    jcenter()
}

and add the project to the dependencies block in your build.gradle:

dependencies {
    compile 'com.cookingfox:logging-adapter-java:0.4.0'
}

Maven

Add jCenter to your repositories in pom.xml or settings.xml:

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

and add the project declaration to your pom.xml:

<dependency>
    <groupId>com.cookingfox</groupId>
    <artifactId>logging-adapter-java</artifactId>
    <version>0.4.0</version>
</dependency>

Usage

Example using Android adapter:

Logger.init().setLoggerAdapter(new AndroidLoggerAdapter());

Logger.debug("Created a user: %s", user);

Configuration

The following example is used to explain the configuration options:

package com.example;

import com.cookingfox.logging.Logger;

public class MyClass {
   public void myMethod() {
       Logger.debug("Hello!");
   }
}

When one of the Logger methods is called, a reference to the 'caller' is generated by analyzing the stack trace. By default, the way this caller reference is formatted is its fully-qualified class name. For the above example, this would be: com.example.MyClass.

To configure the Logger, you call Logger.init(), which returns a Settings object. This class provides the following options:

setLoggerAdapter()

Sets the LoggerAdapter instance, which typically wraps a third party logging library. Of course, you can always create your own implementation. It is not possible to set multiple logger adapters.

setEnabled()

Use this method to enable or disable logging. For example, you can disable logging for your release build.

callerAddLineNumber()

Set to true to add the caller line number, for example: com.example.MyClass:7.

callerAddMethodName()

Set to true to add the caller method name, for example: com.example.MyClass#myMethod.

callerUseSimpleName()

Set to true to use a simple class name for the caller, for example: MyClass.

Example output when all caller options are set to 'true'

MyClass#myMethod:7

Versions

Version
0.4.0
0.3.2
0.3.1
0.3.0
0.2.2
0.1.2