Skip to content

Hakky54/yaslf4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status Quality Gate Status Coverage Reliability Rating Security Rating Vulnerabilities Apache2 license Maven Central javadoc FOSSA Status Join the chat at https://gitter.im/hakky54/yaslf4j

SonarCloud

YASLF4J - yet another simple logging facade for java

Install library with:

Install with maven

<dependency>
    <groupId>io.github.hakky54</groupId>
    <artifactId>yaslf4j</artifactId>
    <version>1.0.1</version>
</dependency>

Install with Gradle

implementation 'io.github.hakky54:yaslf4j:1.0.1'

Install with Scala SBT

libraryDependencies += "io.github.hakky54" % "yaslf4j" % "1.0.1"

Install with Apache Ivy

<dependency org="io.github.hakky54" name="yaslf4j" rev="1.0.1" />

Table of contents

  1. Introduction
  2. Usage
  3. Contributing
  4. License

Introduction

YASLF4J is a logging facade / api which will delegate application logs to the underlying provider. It will either delegate it to SLF4J api if present, or else Log4j2 api if present or fallback to Java Util Logging Logger.

History

When a library owner is using SLF4J or Log4j2 the end-user will end up getting that library as a transitive dependency. The end-user needs to either provide a logging implementation or omit it. When not providing an implementation the end-user will also get the following error message:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

YASLF4J is just a simple logging api which is capable of logging. It will use SLF4J as logging api if it is present on the classpath of the end-user, but it won't provide it as a transitive dependency. The same goes for Log4j2. So the end-user may provide a logging binding but is not required and also won't get bothered if it is absent.

Advantages

  • The end-user won't get a transitive dependency on SLF4J or Log4j2
  • The end-user won't get warning from SLF4J or Log4j2 when not having SLF4J or Log4j2 on the classpath
  • It will use either SLF4J or Log4j2 if it is present at the classpath or fallback to Java Util Logging Logger
  • Plug & play

Tested Java versions

  • Java 8
  • Java 11
  • Java 15

Usage

import nl.altindag.log.Logger;
import nl.altindag.log.LoggerFactory;

public class FooService {

    private static final Logger LOGGER = LoggerFactory.getLogger(FooService.class);

    public void sayHello() {
        LOGGER.info("Keyboard not responding. Press any key to continue...");
        LOGGER.warn("Congratulations, you are pregnant!");
    }

}

Contributing

There are plenty of ways to contribute to this project:

  • Give it a star
  • Join the Gitter room and leave a feedback or help with answering users questions
  • Submit a PR

License

FOSSA Status