Skip to content

How to configure two loggers that will log separately into two different files #342

@mmubasil123

Description

@mmubasil123

I am trying to configure two loggers that will append logs separately into two different files one for system.logs and the other for audit.logs.

I added the dependency

       <dependency>
            <groupId>io.quarkiverse.loggingjson</groupId>
            <artifactId>quarkus-logging-json</artifactId>
            <version>3.1.0</version>
        </dependency>

The application.properties file

## General JSON Configuration
quarkus.log.json.console.enable=true
quarkus.log.json.fields.mdc.flat-fields=true
quarkus.log.json.fields.mdc.enabled=true
quarkus.log.json.fields.ndc.enabled=false
quarkus.log.file.enable=true

## System Logger Configuration
quarkus.log.category."system".handlers=SYSTEM_FILE,SYSTEM_CONSOLE
quarkus.log.category."system".use-parent-handlers=false
#
## System Console Handler
quarkus.log.handler.console.SYSTEM_CONSOLE.format=%d{HH:mm:ss} %-5p [SYSTEM] %s%e%n

# System File Handler
quarkus.log.handler.file.SYSTEM_FILE.enable=true
quarkus.log.handler.file.SYSTEM_FILE.json=false
quarkus.log.handler.file.SYSTEM_FILE.path=logs/system.log
quarkus.log.handler.file.SYSTEM_FILE.format=%d{yyyy-MM-dd HH:mm:ss} %-5p [SYSTEM] %s%e%n

# Route the 'audit' category to the file logger
# Audit Logger Configuration
quarkus.log.category.audit.handlers=AUDIT_FILE
quarkus.log.category.audit.use-parent-handlers=false

# Audit File Handler
quarkus.log.handler.file.AUDIT_FILE.enable=true
quarkus.log.handler.file.AUDIT_FILE.path=logs/audit.log

But the logs in the console are as expected in json format but in the files the logs are not being printed in json format. Am i missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions