Red Hat Build of Quarkus 1.11 Configuring Logging with Quarkus Legal Notice
Total Page:16
File Type:pdf, Size:1020Kb
Red Hat build of Quarkus 1.11 Configuring logging with Quarkus Last Updated: 2021-06-24 Red Hat build of Quarkus 1.11 Configuring logging with Quarkus Legal Notice Copyright © 2021 Red Hat, Inc. The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/ . In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version. Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law. Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries. Linux ® is the registered trademark of Linus Torvalds in the United States and other countries. Java ® is a registered trademark of Oracle and/or its affiliates. XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries. MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries. Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project. The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community. All other trademarks are the property of their respective owners. Abstract Configure logging to collect information about events that occurred within your application. Table of Contents Table of Contents .P .R . E. .F . A. .C . E. 3. .P .R . O. V. .I D. .I N. .G . F. .E .E . D. .B . A. .C . K. O. .N . R. .E .D . .H . .A .T . .D . O. C. .U . M. E. .N . T. .A .T . I.O . .N . .4 . .M . A. .K . I.N . .G . .O . P. .E . N. S. .O . U. .R . C. .E . .M . .O . R. .E . .I N. .C . L. .U . S. .I V. .E . 5. .C . H. .A . P. .T .E . R. 1.. .J . B. .O . S. .S . .L .O . .G . M. A. .N . A. .G . .E . R. .A . N. D. S. U. P. P. .O . .R . T. E. .D . .L . O. .G . .G . I.N . .G . .F . R. .A . M. .E . W. O. .R . K. .S . 6. 1.1. ADDING APACHE LOG4J LOGGING FRAMEWORK 6 1.2. USING LOGGING ADAPTERS 7 .C . H. .A . P. .T .E . R. 2. E. .N . A. .B . L. .I N. .G . J. B. .O . .S . S. .L . O. .G . .G . I.N . .G . .F . O. .R . .Y . O. .U . R. A. .P . P. .L . I.C . A. .T . I.O . N. 9. .C . H. .A . P. .T .E . R. 3. S. .E . T. .T .I .N . G. R. .U . N. .T . I.M . .E . .C . O. .N . .F .I G. U. .R . A. .T . I.O . N. 1. 2. 3.1. CONFIGURING LOGGING FORMAT 12 3.1.1. Logging format strings 13 3.2. LOGGING CATEGORIES SETTING 15 3.3. LOGGING LEVELS 15 3.4. ROOT LOGGER CONFIGURATION 16 3.5. QUARKUS LOG HANDLERS 17 3.6. EXAMPLE LOGGING CONFIGURATION 17 .C . H. .A . P. .T .E . R. 4. .C . O. .N . F. .I G. U. .R . I.N . G. .J .S . O. .N . L. O. G. .G . .I N. .G . .F . O. R. M. A. .T . 1.9 . 4.1. JSON LOGGING CONFIGURATION PROPERTIES 19 .C . H. .A . P. .T .E . R. 5. C. .O . .N . F. .I G. .U . .R .I .N . G. L. .O . G. G. .I N. G. F. .O . R. @. .Q . .U . A. .R . K. .U . S. T. .E . S. .T . 2. .1 . .C . H. .A . P. .T .E . R. 6. .A . D. .D . I.T . I.O . N. A. .L . R. .E . S. .O . U. .R . C. .E . S. 2. 2. 1 Red Hat build of Quarkus 1.11 Configuring logging with Quarkus 2 PREFACE PREFACE As an application developer, you can use logging to view and record messages about events that occur while your application is running. Log messages provide information that you can use to debug your application during development and testing, and to monitor your application in a production environment. Prerequisites Have OpenJDK (JDK) 11 installed and the JAVA_HOME environment variable set to specify the location of the Java SDK. Log in to the Red Hat Customer Portal to download Red Hat build of Open JDK from the Software Downloads page. Have Apache Maven 3.6.2 or higher installed. Download Maven from the Apache Maven Project website. Have a Quarkus Maven project. For information on how to create Quarkus applications with Maven, see Developing and compiling your Quarkus applications with Apache Maven. 3 Red Hat build of Quarkus 1.11 Configuring logging with Quarkus PROVIDING FEEDBACK ON RED HAT DOCUMENTATION We appreciate your feedback on our technical content and encourage you to tell us what you think. If you’d like to add comments, provide insights, correct a typo, or even ask a question, you can do so directly in the documentation. NOTE You must have a Red Hat account and be logged in to the customer portal. To submit documentation feedback from the customer portal, do the following: 1. Select the Multi-page HTML format. 2. Click the Feedback button at the top-right of the document. 3. Highlight the section of text where you want to provide feedback. 4. Click the Add Feedback dialog next to your highlighted text. 5. Enter your feedback in the text box on the right of the page and then click Submit. We automatically create a tracking issue each time you submit feedback. Open the link that is displayed after you click Submit and start watching the issue or add more comments. Thank you for the valuable feedback. 4 MAKING OPEN SOURCE MORE INCLUSIVE MAKING OPEN SOURCE MORE INCLUSIVE Red Hat is committed to replacing problematic language in our code, documentation, and web properties. We are beginning with these four terms: master, slave, blacklist, and whitelist. Because of the enormity of this endeavor, these changes will be implemented gradually over several upcoming releases. For more details, see our CTO Chris Wright’s message . 5 Red Hat build of Quarkus 1.11 Configuring logging with Quarkus CHAPTER 1. JBOSS LOGMANAGER AND SUPPORTED LOGGING FRAMEWORKS Quarkus uses the JBoss LogManager logging backend to collect and manage log data. You can use JBoss Logging to collect data about Quarkus internal events and also about the events within your application. You can configure logging behavior in your application.properties file. JBoss LogManager supports several third-party logging APIs in addition to the JBoss Logging. JBoss LogManager merges the logs from all the supported logging APIs. Supported APIs for logging: JDK JUL java.util.logging JBoss Logging SLF4J Apache Commons Logging Log4j 1.x Log4j 2 Quarkus handles all of its logging functionalities using JBoss Logging. When you use a library that relies on a different logging API, you need to exclude this library from the dependencies and configure JBoss Logging to use a logging adapter for the third-party API. Additional resources Using logging adapters Adding Apache Log4j logging framework Example logging configuration 1.1. ADDING APACHE LOG4J LOGGING FRAMEWORK Apache Log4j is a logging framework that includes a logging backend and a logging API. Since Quarkus uses the JBoss LogManager backend, you can add the log4j2-jboss-logmanager library to your project and use Log4j as a logging API. Adding the Log4j library routes the Log4j logs to the JBoss Log Manager. You do not need to include any Log4j dependencies. Procedure Add the log4j2-jboss-logmanager library as a dependency of your project’s pom.xml file: pom.xml <dependency> <groupId>org.jboss.logmanager</groupId> <artifactId>log4j2-jboss-logmanager</artifactId> </dependency> The log4j2-jboss-logmanager is the library for the Log4J version 2 API. If you want to use the legacy 6 CHAPTER 1. JBOSS LOGMANAGER AND SUPPORTED LOGGING FRAMEWORKS The log4j2-jboss-logmanager is the library for the Log4J version 2 API. If you want to use the legacy Log4J version 1 API then you must add the log4j-jboss-logmanager instead. Additional resources About Log4j 1.2. USING LOGGING ADAPTERS Quarkus relies on the JBoss Logging library for all the.