teragrep / cfe_31

0 stars 0 forks source link

Use SLF4J together with Log4J2 for logging instead of Typewriter class #35

Closed MoonBow-1 closed 5 months ago

MoonBow-1 commented 6 months ago

Description

Requested by @Nefarious46 to move to Log4J2 for better logging

TODO:

kortemik commented 6 months ago

Rather use slf4j facade and log4j2 backend for it.

ma 15. tammik. 2024 klo 14.10 Moonbow-1 @.***> kirjoitti:

Description

Requested by @Nefarious46 https://github.com/Nefarious46 to move to Log4J for better logging

— Reply to this email directly, view it on GitHub https://github.com/teragrep/cfe_31/issues/35, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGX2ORSINEAK2TGRFGJV6TYOUMDVAVCNFSM6AAAAABB3FLK76VHI2DSMVQWIX3LMV43ASLTON2WKOZSGA4DCOJQGUZDINA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

MoonBow-1 commented 6 months ago

SLF4J and Log4J2 have been implemented as requested by @kortemik

Log4J2 conf:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout
        pattern="%d{HH:mm:ss.SSS} [%C{1}] %highlight{%-5level}{FATAL=white, ERROR=red, WARN=bright_blue, INFO=black, DEBUG=bright_green, TRACE=blue} - %msg%n%throwable"
      />
    </Console>
  </Appenders>
  <Loggers>
    <Root level="ERROR" name="logger">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

Produces following logs to console:

13:16:37.775 [CFE01GenerateFile] ERROR - java.sql.SQLTransientConnectionException: (conn=98) {"id": null, "message": "iso_8601_comma is not available"}

Logger classes/fields declared:

private final static Logger LOGGER = LoggerFactory.getLogger("logger");

And used:

LOGGER.error("Didn't find Generate file");
MoonBow-1 commented 6 months ago

Also added more Trace logs to Client.sendRequest method to troubleshoot problems with requests/responses

kortemik commented 6 months ago
private final static Logger LOGGER = LoggerFactory.getLogger("logger");

use class name instead if generic logger

such as

private final static Logger LOGGER = LoggerFactory.getLogger(Typewriter.class);

in case you are creating a LOGGER field within Typewriter class. This will allow configuring the loggers externally per class basis.

MoonBow-1 commented 6 months ago

Modified loggers to use classes when getting the logger from LogFactory

private final static Logger LOGGER = LoggerFactory.getLogger(HostMeta.class);

Configs are now available on per class basis

MoonBow-1 commented 6 months ago

Removed string concatenation from Loggers and changed format to conform to company logging policy:

Before:

LOGGER.debug("Found RELP folder: " + this.masterDir);

After:

LOGGER.debug("Found RELP master directory: <{}>", this.masterDir);