Giter VIP home page Giter VIP logo

jl4c-log4j's Introduction

jl4c Log4j

A Log4j adapter for ceylon.logging.

Status

The implementation is complete. Some non-Log4j specific types including Mdc and MdcObtainableEntry may be moved to a separate module in the future.

The source code must be compiled against the latest development version of Ceylon, so a precompiled module will not be available until after Ceylon's next release.

Dependencies

The aether repository must be enabled in order to resolve "log4j:log4j" "1.2.17", which is a shared import of this module. For more information, see http://ceylon-lang.org/documentation/1.1/reference/repository/maven/.

Usage Example

import ceylon.logging {
    Logger,
    logger
}

import com.vasileff.jl4c.log4j {
    MdcObtainableEntry,
    useLog4jLogging
}

import org.apache.log4j {
    ConsoleAppender,
    PatternLayout,
    Level,
    JLog4jLogger=Logger
}

// initializeLogging() must be called before
// log is first accessed
Logger log = logger(`package`);

shared
void run() {
    initializeLogging();

    log.info("Initialization complete");

    try(MdcObtainableEntry("userId", "5150")) {
        log.info("Processing user request");
    }

    log.info("Goodbye!");
}

shared
void initializeLogging() {
    // include the MDC value "userId"
    value pattern = "%-5p [%t:%X{userId}] (%F:%L) - %m%n";

    // setup Log4j programmatically
    value console = ConsoleAppender();
    console.layout = PatternLayout(pattern);
    console.threshold = Level.\iTRACE;
    console.activateOptions();
    JLog4jLogger.rootLogger.addAppender(console);
    JLog4jLogger.rootLogger.setPriority(Level.\iINFO);

    // use log4j for:
    //      ceylon.logging::logger
    //      com.vasileff.jl4c.log4j::mdc
    useLog4jLogging();
}

Produces:

INFO  [main:] (run.ceylon:26) - Initialization complete
INFO  [main:5150] (run.ceylon:29) - Processing user request
INFO  [main:] (run.ceylon:32) - Goodbye!

License

The content of this repository is released under the MIT License as provided in the LICENSE file that accompanied this code.

By submitting a "pull request" or otherwise contributing to this repository, you agree to license your contribution under the license mentioned above.

jl4c-log4j's People

Contributors

jvasileff avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.