Home

Awesome

Lib-Logger

Build Status license: GPL v3 GitHub release

Intention

Lib-Logger is a library for easy logging with the Apache Log4j 2 in a Java(FX) & Maven desktop application.

Image: UML Lib-Logger
UML-diagram_Lib-Logger_v0.6.0_2018-01-14_11-00.png

Hint
The UML diagram is created with the Online Modeling Platform GenMyModel.

Content

Examples<a name="Examples" />

How to configure a project for logging<a name="HoToCoThFoLo" />

In this example I want to show you how to configure a Java or JavaFX project for the usage from the library Lib-Logger.

How to log a regular message<a name="HoToLoAReMe" />

In the first example the developer can see how to configure a project for logging purpose. With this requirements its now possible to log normal messages like:

Example how to log a debug message

public static final void loadResourcesInCache() {
    LoggerFacade.getDefault().debug(TemplateLoader.class, "Load resources in cache"); // NOI18N

    ...
}

// which will print in the console and in the configured `xy.log` file:
2017-05-27 08:56:53,757  DEBUG Load resources in cache     [TemplateLoader]

Example how to log a info message

@Override
public void initialize(URL location, ResourceBundle resources) {
    LoggerFacade.getDefault().info(this.getClass(), "Initialize ApplicationPresenter"); // NOI18N

    ...        
}

// which will print in the console and in the configured `xy.log` file:
2017-05-27 08:56:55,073  INFO  Initialize ApplicationPresenter     [ApplicationPresenter]

Example how to log a error message

private static String getResource(String name) {
    String loadedResource = null;
    try {
        final URL url = new URL(name);
        loadedResource = getResource(url.openStream());
    } catch(IOException ex){
        LoggerFacade.getDefault().error(ProjectCollector.class, "Error read resources: " + name, ex); // NOI18N
    }
        
    return loadedResource;
}

How to log a starting message<a name="HoToLoAStMe" />

This example will show you how to log a starting message with following statements:

public class StartApplication extends Application implements IApplicationConfiguration {

    @Override
    public void init() throws Exception {
        
        PropertiesFacade.getDefault().register(KEY__APPLICATION__RESOURCE_BUNDLE);
        PropertiesFacade.getDefault().register(ITemplateConfiguration.KEY__TEMPLATE__RESOURCE_BUNDLE);
        
        final char borderSign = this.getProperty(KEY__APPLICATION__BORDER_SIGN).charAt(0);
        final String message = this.getProperty(KEY__APPLICATION__MESSAGE_START);
        final String title = this.getProperty(KEY__APPLICATION__TITLE) + this.getProperty(KEY__APPLICATION__VERSION);
        LoggerFacade.getDefault().message(borderSign, 80, String.format(message, title));
        
        ...
    }
    ...
}

// which will print in the console and in the configured `xy.log` file:
2017-05-27 08:56:53,688  DEBUG Load properties: /com/github/naoghuman/demo/template/application/application.properties     [LibProperties]
2017-05-27 08:56:53,705  DEBUG Load properties: /com/github/naoghuman/demo/template/template.properties     [LibProperties]
2017-05-27 08:56:53,706  INFO  
################################################################################
Start Demo-Template v0.1.0-SNAPSHOT.
################################################################################     [Logger]

where the constants defined in

public interface IApplicationConfiguration {
    
    public static final String KEY__APPLICATION__BORDER_SIGN     = "application.border.sign"; // NOI18N
    public static final String KEY__APPLICATION__MESSAGE_START   = "application.message.start"; // NOI18N
    public static final String KEY__APPLICATION__RESOURCE_BUNDLE = "/com/github/naoghuman/demo/template/application/application.properties"; // NOI18N
    public static final String KEY__APPLICATION__TITLE           = "application.title"; // NOI18N
    public static final String KEY__APPLICATION__VERSION         = "application.version"; // NOI18N
    
    ...

}

and the key-value pairs in application.properties:

# Application
application.border.sign=#
application.message.start=Start %s.
application.message.stop=Stop %s.

# This values will be replaced during startup from the application.
# The format from the title in the application will be: ${pom.name} v${pom.version}
# Be aware from the empty sign between the two parameters.
application.build.datetime=${timestamp}
application.title=${pom.name} 
application.version=v${pom.version}

JavaDoc<a name="JavaDoc" />

The JavaDoc from the library Lib-Logger can be explored here: JavaDoc Lib-Logger

Image: JavaDoc Lib-Logger
Lib-Logger_JavaDoc_v0.7.0_2019-05-02_09-22.png

Download<a name="Download" />

Current version is 0.7.0. Main points in this release are:

Maven coordinates
In context from a Maven project you can use following maven coordinates:

<dependencies>
    <dependency>
        <groupId>com.github.naoghuman</groupId>
        <artifactId>lib-logger</artifactId>
        <version>0.7.0</version>
    </dependency>
</dependencies>

Download manuell

An overview about all existings releases can be found here:

Requirements<a name="Requirements" />

Installation<a name="Installation" />

Install the project in your preferred IDE

Contribution<a name="Contribution" />

License<a name="License" />

The project Lib-Logger is licensed under General Public License 3.0.

Autor<a name="Autor" />

The project Lib-Logger is maintained by me, Peter Rogge. See Contact.

Contact<a name="Contact" />

You can reach me under peter.rogge@yahoo.de.