Lib-Logger

Lib-Logger is a library for `easy` logging with the `Apache Log4j 2` in a Java(FX) & Maven desktop application. See https://github.com/Naoghuman/lib-logger for more details.

License

License

GroupId

GroupId

com.github.naoghuman
ArtifactId

ArtifactId

lib-logger
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

jar
Description

Description

Lib-Logger
Lib-Logger is a library for `easy` logging with the `Apache Log4j 2` in a Java(FX) & Maven desktop application. See https://github.com/Naoghuman/lib-logger for more details.
Project URL

Project URL

https://github.com/Naoghuman/lib-logger.git
Project Organization

Project Organization

Naoghuman's dream
Source Code Management

Source Code Management

https://github.com/Naoghuman/lib-logger.git

Download lib-logger

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.naoghuman/lib-logger/ -->
<dependency>
    <groupId>com.github.naoghuman</groupId>
    <artifactId>lib-logger</artifactId>
    <version>0.7.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.naoghuman/lib-logger/
implementation 'com.github.naoghuman:lib-logger:0.7.0'
// https://jarcasting.com/artifacts/com.github.naoghuman/lib-logger/
implementation ("com.github.naoghuman:lib-logger:0.7.0")
'com.github.naoghuman:lib-logger:jar:0.7.0'
<dependency org="com.github.naoghuman" name="lib-logger" rev="0.7.0">
  <artifact name="lib-logger" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.naoghuman', module='lib-logger', version='0.7.0')
)
libraryDependencies += "com.github.naoghuman" % "lib-logger" % "0.7.0"
[com.github.naoghuman/lib-logger "0.7.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.apache.logging.log4j : log4j-api jar 2.11.2
org.apache.logging.log4j : log4j-core jar 2.11.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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

How to configure a project for logging

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

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

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

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

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

  • Prepare the library for Java-11!
  • Connect the GitHub project to Travis CI.
  • Move the JavaDoc to the GitHub folder docs/apidocs.

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

Installation

Install the project in your preferred IDE

Contribution

License

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

Autor

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

Contact

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

Versions

Version
0.7.0
0.6.0
0.5.1
0.5.0
0.4.1
0.4.0