Class DefaultConsoleHandler

java.lang.Object
java.util.logging.Handler
org.jboss.logmanager.ExtHandler
org.jboss.logmanager.handlers.WriterHandler
org.jboss.logmanager.handlers.OutputStreamHandler
org.jboss.logmanager.handlers.ConsoleHandler
eu.mulk.quarkus.googlecloud.jsonlogging.logmanager.DefaultConsoleHandler
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable, org.jboss.logmanager.handlers.FlushableCloseable

public final class DefaultConsoleHandler extends org.jboss.logmanager.handlers.ConsoleHandler
A ConsoleHandler preconfigured with Formatter.

Useful as a handler for java.util.logging.

If you have a logging.properties file (see LogManager.readConfiguration(InputStream)), you can use this handler by setting the following properties:

handlers = eu.mulk.quarkus.googlecloud.jsonlogging.logmanager.DefaultConsoleHandler

Note: You can use org.slf4j.bridge.SLF4JBridgeHandler from org.slf4j:jul-to-slf4j instead if you also have org.jboss.slf4j:slf4j-jboss-logmanager on the class path. In comparison to this class, which relies on the relatively efficient ExtLogRecord.wrap(java.util.logging.LogRecord), routing through SLF4J incurs additional overhead because of the necessary conversions between SLF4J's log entry structure and LogRecord.

Usage with Spring Boot

In case you are using Spring Boot, note that in addition to ensuring that org.springframework.boot.logging.java.JavaLoggingSystem is the logging system in use (see below), you need to accompany this with an entry in application.properties that points to your logging.properties file:

logging.config = classpath:logging.properties

In order to ensure that Spring Boot chooses JavaLoggingSystem over other implementations, make sure that no other logging backends are present on the class path. A simple way of doing this is by relying on spring-boot-starter-logging while excluding Logback:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
  <exclusions>
    <exclusion>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </exclusion>
  </exclusions>
</dependency>

You will probably want to include at least org.jboss.slf4j:slf4j-jboss-logmanager as well. In addition, org.slf4j:jcl-over-slf4j, org.jboss.logmanager:log4j-jboss-logmanager, and org.jboss.logmanager:log4j2-jboss-logmanager may be useful, but are not required.