Locations of visitors to this page

Logging

Logging in Qi4j is quite different from what we are used to from Log4J and similar systems. It is important to recognize that Logging is domain concern and not for developer activities. If you need warning systems for development purposes, you should use the debugLevel() in Debugging instead. Consider proper logging as the Log Book for a captain, where important events are recorded.

In Qi4j we just use a so called Private Mixin, which handles the details to connect to the LoggingService. It is fully possible to create new logging interfaces, yet utilize the LoggingService infrastructure gradually being built up. Initially, we have the SimpleLog interface, but expect this to grow as use cases will emerge.

SimpleLog


The SimpleLog is a minimal and fast, yet localization capable logger interface. The interface looks like;
public interface SimpleLog
{
    void info( String message );

    void info( String message, Object param1 );

    void info( String message, Object param1, Object param2 );

    void info( String message, Object... params );

    void warning( String message );

    void warning( String message, Object param1 );

    void warning( String message, Object param1, Object param2 );

    void warning( String message, Object... params );

    void error( String message );

    void error( String message, Object param1 );

    void error( String message, Object param1, Object param2 );

    void error( String message, Object... params );
}

And usage is really simple. Just put a @This SimpleLog injection into your code. For instance;
public class MyMixin
    implements My
{
    @This private SimpleLog logger;
    @This private Tank tank;
    @This private Threshold threshold;

    public void doSomething()
    {
        if( tank.level().get() > threshold.high().get() )
        {
            logger.warning( "High level in Tank: %s", level );
        }
    }
}

The SimpleLog will still provide a Category to the LogService, being the name of the Composite type it belongs to.

Qi4j and the Qi4j logo are trademarks of Richard Öberg, Niclas Hedhman and the members of the Qi4j Core Team. See Qi4j licensing for more information.
Powered by SiteVisionexternal link.