StaticLog - super lightweight static logging for Kotlin, Java and Android

Overview

StaticLog

Kotlin license Dependency Status Download

StaticLog is a super lightweight logging library implemented in pure Kotlin (https://kotlinlang.org). It is designed to be used in Kotlin, Java and Android.
It is for formatting standard output comfortably without the need to construct a Logger object. But it's also no problem to create one.

This is an example output in IntelliJ IDEA example output Yes, the occurrence of the log message is clickable!

Table of Contents

Getting Started

The source/target compatibility is Java 1.6.
This library is uploaded to jCenter and Maven Central.

Gradle / Maven

dependencies {
    compile 'io.github.jupf.staticlog:staticlog:2.2.0'
}
<dependency>
    <groupId>io.github.jupf.staticlog</groupId>
    <artifactId>staticlog</artifactId>
    <version>2.1.9</version>
</dependency>

If you dont have the Kotlin runtime already present in your project, use the following dependency.

dependencies {
    compile 'io.github.jupf.staticlog:staticlog-java:2.2.0'
}
<dependency>
    <groupId>io.github.jupf.staticlog</groupId>
    <artifactId>staticlog-java</artifactId>
    <version>2.1.9</version>
</dependency>

StaticLog in Kotlin

You can find the example source code here.

Logging in Kotlin

Logging with StaticLog in Kotlin is as easy as it gets:

Log.info("This is an info message")
Log.debug("This is a debug message")
Log.warn("This is a warning message","WithACustomTag")
Log.error("This is an error message with an additional Exception for output", "AndACustomTag", exception )

Log.logLevel = LogLevel.WARN
Log.info("This message will not be shown")

Formatting Output in Kotlin

To define an output format for StaticLog in Kotlin is very easy. It uses a mix from builders and function call syntax.
This defines for example the default format:

Log.newFormat {
    line(date("yyyy-MM-dd HH:mm:ss"), space, level, text("/"), tag, space(2), message, space(2), occurrence)
}

You can even define multiple lines and indent them:

Log.newFormat {
    line(date("yyyy-MM-dd HH:mm:ss"), space, level, text("/"), tag, space(2), occurrence)
    indent {
        line(message)
    }
}

Tag Filtering in Kotlin

It is possible to filter the output for a specific tag. This is rather easy, just provide the tag:

Log.filterTag = "filterTag"
Log.info("This log will be filtered out", "otherTag")
Log.info("This log has the right tag", "filterTag")

Deleting a tag filter is just as easy:

Log.deleteTagFilter()

Log instances in Kotlin

If you need another log instance you can create one very easy. It can have an own format and log level:

val logger = Log.kotlinInstance()
logger.debug("This message is from an individual logger instance")

The interface of individual log instances is exactly the same as the interface for the static Log class.

FormatBuilders in Kotlin

Here are all possible FormatBuilders:

FormatBuilder Output
date(Pattern) Prints the date in the given pattern
(The pattern is defined in SimpleDateFormat)
epoch Prints the current time in milliseconds
level Prints the log level
tag Prints the log tag
(If none was provided to the logging function,
it defaults to the class name the message was logged from.)

message Prints the log message
occurrence Prints the origin of the logging (In Eclipse and IntelliJ clickable!)
space Prints 1 space
space(X: Integer) Prints X spaces
tab Prints 1 tab
tab(X: Integer) Prints X tabs
text(S: String) Prints the String S

Custom Printers in Kotlin

tbd

StaticLog in Java

You can find the example source code here.

Logging in Java

Logging with StaticLog in Kotlin is as easy as it gets:

Log.info("This is an info message");
Log.debug("This is a debug message");
Log.warn("This is a warning message","WithACustomTag");
Log.error("This is an error message with an additional Exception for output", "AndACustomTag", exception );

Log.setLogLevel(LogLevel.WARN);
Log.info("This message will not be shown");

Formatting Output in Java

To define an output format for StaticLog in Java is very easy.
This defines for example the default format:

import static de.jupf.staticlog.Log.FormatOperations.*;

...

LogFormat format = Log.newFormat();
format.line(date("yyyy-MM-dd HH:mm:ss"), space(1), level(), text("/"), tag(), space(2), message(), space(2), occurrence());

You can even define multiple lines and indent them:

LogFormat format = Log.newFormat();
format.line(date("yyyy-MM-dd HH:mm:ss"), space(1), level(), text("/"), tag(), space(2), occurrence());
format.indent(line(message()));

Tag Filtering in Java

It is possible to filter the output for a specific tag. This is rather easy, just provide the tag:

Log.setTagFilter("filterTag");
Log.info("This log will be filtered out", "otherTag");
Log.info("This log has the right tag", "filterTag");

Deleting a tag filter is just as easy:

Log.deleteTagFilter();

Log instances in Java

If you need another log instance you can create one very easy. It can have an own log level and format:

Logger logger = Log.javaInstance();
logger.debug("This message is from an individual logger instance");

The interface of individual log instances is exactly the same as the interface for the static Log class.

FormatBuilders in Java

Here are all possible FormatBuilders:

FormatBuilder Output
date(Pattern) Prints the date in the given pattern
(The pattern is defined in SimpleDateFormat)
epoch() Prints the current time in milliseconds
level() Prints the log level
tag() Prints the log tag
(If none was provided to the logging function,
it defaults to the class name the message was logged from.)

message() Prints the log message
occurrence() Prints the origin of the logging (In Eclipse and IntelliJ clickable!)
space(X: Integer) Prints X spaces
tab(X: Integer) Prints X tabs
text(S: String) Prints the String S

Custom Printers in Java

tbd

StaticLog in Android

StaticLog automatically detects Android VMs and switches its output to the Android logger.
The default format for Android is defined like this:

format.line(message(), space(2), occurrence());

The tag is forwarded to the Android logger. If none is provided, it defaults to the class name the log was printed from.
For further questions look at StaticLog in Java

You might also like...
A lightweight cache library written in Kotlin

[NEW] Released to Maven Central: 'com.github.yundom:kache:1.x.x' Kache A runtime in-memory cache. Installation Put this in your build.gradle implemen

Lightweight Kotlin DSL dependency injection library
Lightweight Kotlin DSL dependency injection library

Warehouse DSL Warehouse is a lightweight Kotlin DSL dependency injection library this library has an extremely faster learning curve and more human fr

A fast, lightweight, entity component system library written in Kotlin.

Fleks A fast, lightweight, entity component system library written in Kotlin. Motivation When developing my hobby games using LibGDX, I always used As

Kotlin Object Notation - Lightweight DSL to build fluid JSON trees

Kotlin Object Notation Lightweight kotlin MPP DSL for building JSON trees Setup Just drop the dependency in your commonMain sourceSet kotlin { sourc

Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

Lightweight data loading and caching library for android

ColdStorage A lightweight data loading and caching library for android Quicklinks Feature requests: Got a new requirement? Request it here and it will

A lightweight, simple, smart and powerful Android routing library.

RxRouter Read this in other languages: 中文, English A lightweight, simple, smart and powerful Android routing library. Getting started Setting up the d

Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.
Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.

Clickstream is an event agnostic, real-time data ingestion platform. Clickstream allows apps to maintain a long-running connection to send data in real-time.

:balloon: A lightweight popup like tooltips, fully customizable with an arrow and animations.
:balloon: A lightweight popup like tooltips, fully customizable with an arrow and animations.

Balloon 🎈 A lightweight popup like tooltips, fully customizable with arrow and animations. Including in your project Gradle Add below codes to your r

Comments
Releases(v2.2.0)
Owner
Julian Pfeifer
Julian Pfeifer
Minimalistic and multiplatform logging for Kotlin

klog This project is not abandonned. It's just nothing to add. KLogging provides unified logging API, which you can use from Kotlin code targeted for

Lev Shagalov 11 Oct 3, 2022
[Android Library] Get easy access to device information super fast, real quick

DeviceInfo-Sample Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the d

Anitaa Murthy 193 Nov 20, 2022
Simple, fast, efficient logging facade for Android apps

µlog Simple, fast, and efficient logging facade for Android apps. Inspired by Timber and Logcat. Features Lazy message evaluation Pluggable backends (

Danny Lin 9 Oct 21, 2022
Marvel Super Heroes | MVVM | Coroutines | DaggerHilt | LiveData

As an iOS developer, I'm learning Android and Kotlin trying to apply best practices, so I've started the same iOS project based on MARVEL, but now for ANDROID!

Míchel Marqués 2 Jun 4, 2022
A lightweight and simple Kotlin library for deep link handling on Android 🔗.

A lightweight and simple Kotlin library for deep link handling on Android ??.

Jeziel Lago 101 Aug 14, 2022
🚟 Lightweight, and simple scheduling library made for Kotlin (JVM)

Haru ?? Lightweight, and simple scheduling library made for Kotlin (JVM) Why did you build this? I built this library as a personal usage library to h

Noel 13 Dec 16, 2022
Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

Lorris Creantor 18 Nov 24, 2022
Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties

Easy lightweight SharedPreferences library for Android in Kotlin using delegated properties Idea Delegated properties in Kotlin allow you to execute a

null 25 Dec 27, 2022
Koi, a lightweight kotlin library for Android Development.

Koi - A lightweight Kotlin library for Android Koi include many useful extensions and functions, they can help reducing the boilerplate code in Androi

Hello World 514 Nov 29, 2022
A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx ?? Work In-Progress ?? A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Jaya Surya Thotapalli 5 Feb 15, 2022