Giter Club home page Giter Club logo

java-logging's Introduction

OSGL Logging

OSGL Logging is yet another Java Logging facade.

Why not Slf4J

I don't like the Slf4J Logger's API. Specifically the logging API with Throwable arguments, e.g.

void debug(String msg, Throwable t);

The better one in my mind should be

void debug(Throwable t, String format, Object... args);

And yes OSGL logging Logger use the better one ;-)

Usage

  1. Classic usage
import org.osgl.logging.*;

public class Foo {

    protected final Logger logger = LogManager.get(Foo.class);

    private void bar(int n) {
        logger.trace("enter bar with %s", n);
        try {
            // do something dangerous
        } catch (Exception e) {
            logger.error(e, "error executing bar with %s", n);
        }
    }
}
  1. Use LogManager's static log methods
import org.osgl.logging.*;

public class Foo {
    private void bar(int n) {
        LogManager.trace("enter bar with %s", n);
        try {
            // do something dangerous
        } catch (Exception e) {
            LogManager.error(e, "error executing bar with %s", n);
        }
    }
}
  1. Use LogManager's alias L and the static log methods
import org.osgl.logging.*;

public class Foo {
    private void bar(int n) {
        L.trace("enter bar with %s", n);
        try {
            // do something dangerous
        } catch (Exception e) {
            L.error(e, "error executing bar with %s", n);
        }
    }
}

Configuration

The only configuration for OSGL logging is to configure the LogServiceProvider:

import org.osgl.logging.*;
import org.osgl.logging.service.*;

public class Bootstrap {
    static {
        LogManager.registerLogServiceProvider(new CommonsLoggingServiceProvider());
    }
}

At the moment there are four predefined LogServiceProvider:

  1. CommonsLoggingServiceProvider, bridge to Apache Commons-Logger
  2. Log4jServiceProvider, bridge to Apache Log4J
  3. Slf4jServiceProvider, bridge to Slf4j
  4. TinyLogServiceProvider, bridge to TinyLog

Please refer to relevant logging framework documents to check how to configure specific log service.

Auto discover LogService

If user application does not explicitly register log service provider to LogManager, then LogManager will automatically discover the underline LogService by trying to check if a certain Java Class is in the class path. The discovery is proceeded with the following order:

  1. Check if TinyLog is in the class path. If found then use TinyLogServiceProvider
  2. Else then check if Slf4j is in the class path. If found then use Slf4jServiceProvider
  3. Else then check if Commons-Logging is in the class path. If found then use CommonsLoggingServiceProvider
  4. Else check if Log4j is in the class path. If found then use Log4jServiceProvider
  5. Finally if none of the service provider is used, then by default use JDKLogService

java-logging's People

Contributors

greenlaw110 avatar

Stargazers

SunnyMarkLiu avatar

Watchers

 avatar James Cloos avatar Joe Cincotta avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.