TinyLog v2 with multimodule maven project spring-boot

251 views Asked by At

Hi I have a multimodule springboot based project and I would like to keep logging separate for each module. I am using tiny log 2, but the issue I am facing is that, when there is a stack trace thrown, it is not getting captured in my rolling log file. Here is the tinyLog configuration:

exception = strip: jdk.internal
writer        = file
writer.format = {date} [{class}] {level}: {message}
writer.file   = log.txt

In this way, when there is no error, I see proper logging. But purposefully I gave wrong mysql connection properties, and then I see whole bunch of error logs on console but on the log file I see only debug, info logs.

1

There are 1 answers

1
Martin On BEST ANSWER

This is likely due to one of the following two causes:

1) The Maven Configuration is Incomplete

For using tinylog instead of Logback, which is the default logging back-end of Spring Boot, you have to exclude Spring Boot's logging dependencies and replace them with the corresponding tinylog artifacts:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jul-to-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.tinylog</groupId>
        <artifactId>tinylog-api</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.tinylog</groupId>
        <artifactId>tinylog-impl</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.tinylog</groupId>
        <artifactId>slf4j-tinylog</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.tinylog</groupId>
        <artifactId>jcl-tinylog</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.tinylog</groupId>
        <artifactId>log4j1.2-api</artifactId>
        <version>2.2.1</version>
    </dependency>
</dependencies>

(Copied from https://github.com/pmwmedia/tinylog-spring-boot-example/blob/v2/pom.xml)

2) Exception is not Output via a Logger

Have you checked that the exception is logged via a logger (e.g. Logger.error(ex)) and not printed via ex.printStackTrace() directly to the console? tinylog (and any other logging framework) can only write log entries into files, if these log entries are issued via logging API.

If none of both suggestions fix the issue, it would be helpful to know which logging API is being used to log the missing exception.