SteemJ V0.4.0 Feature Preview – Logging

in #steemdev7 years ago

SteemJ v0.4.0 will finally allow you to choose the logging framework of your choice.


SteemJV2Logo

SteemJ V0.4.0 Feature Preview – Logging

Hello Steemians!

The development of SteemJ in version 0.4.0 is going on and some big features are planned. I will use this series to give you a small preview of what will come. Today`s post is about the changes related to the logging.

Logging

Prior to SteemJ version 0.4.0, SteemJ was shipped with a logging framework implementation. As this is a bad practice for several reasons, SteemJ 0.4.0 removed this implementation and allows you to configure the logging on your own.

To achieve this, SteemJ only contains the slf4j-api and expects you, to add the slf4j implementation of your choice to your project. A list of the most common implementations can be found at www.slf4j.org/manual, while you can find a lot more in the "vastness of the internet".

Example Configuration

One good example of an alternative slf4j implementation is log4j-slf4j-impl, which implements the slf4j-api and adds the powerfull configuration options of log4j2.

As a first step, the log4j-slf4j-impl jar needs to be added to your project. The most easiest way to achieve this is the usage of a Build-Management tool like Maven, because you only need to add the required dependencies the pom.xml.

<dependency>
    <groupId>eu.bittrade.libs</groupId>
    <artifactId>steemj-core</artifactId>
    <version>${steemJ.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j.version}</version>
</dependency>

To finalize the logging configuration of your project, create a log4j2.xml and add it to the src/main/resources folder. An example log4j2.xml configuration is shown below.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="eu.bittrade.libs.steemj" level="WARN">
            <AppenderRef ref="Console" />
        </Logger>
        <Logger name="my.project" level="DEBUG">
            <AppenderRef ref="Console" />
        </Logger>
        <Root level="ERROR" />
    </Loggers>
</Configuration>

The configuration above would append all log messages of:

  • SteemJ, that have a severity of WARN or higher
  • your project (package my.project), that have a severity of DEBUG or higher
    to the console, while ignoring all other log messages, because no logger is defined for Root.

If you want to use log4j2 in your project too, you should have a look at the official documentation to find detailed configuration examples.

General information

What is SteemJ?

SteemJ is a project that allows you to communicate with a Steem node using Java. So far, the project supports most of the API calls and is also able to broadcast most of the common operation types. Further information can be found on GitHub.

https://github.com/marvin-we/steem-java-api-wrapper

How to add it to your project?

SteemJ binaries are pushed into the maven central repository and can be integrated with a bunch of build management tools like Maven. The Wiki provides a lot of examples for the most common build tools. If you do not use a build management tool you can download the binaries as described here.

Contribute

The project became quite big and there is still a lot to do. If you want to support the project simply clone the git repository and submit a pull request. I would really appreciate it =).

git clone https://github.com/marvin-we/steem-java-api-wrapper.git

Get in touch!

Most of my projects are pretty time consuming and I always try to provide some useful stuff to the community. What keeps me going for that is your feedback and your support. For that reason I would love to get some Feedback from you <3. Just contact me here on Steemit or ping me on GitHub.


If you want to stay up to date or just like the stuff I am doing it would be great if you could press the button below =).

Follow meFollow @dez1337
follow mefollow dez1337


Thanks for reading and best regards,
@dez1337

Sort:  

Keep the good work. I am starting to use it with good results.

Thanks man, good post. Keep it that way
Peace

I don't use Java, but I love to see the API get better and more accessible. Thanks for all your work!

Thank you very much for the positive feedback and for the support!

Keep the good work. I am starting to use it with good results.👌👌👌👌👌👌👌👌👌👌

Good job bro...