-
Notifications
You must be signed in to change notification settings - Fork 645
[ISSUE #4697] Use Fluent Logging API to provide accurate, concise, and elegant logging #4698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
67740cc
upgrade log4j and slf4j
Pil0tXia 9c23c8b
recommanded example
Pil0tXia 9f1e5d3
add known dependencies
Pil0tXia 8daf32a
remove log4j-to-slf4j
Pil0tXia bd6c91c
Revert "recommanded example"
Pil0tXia 854f39f
Deprecate `LogUtils` for removal
ppkarwasz 3e4dc11
Add minimal `errorPronePatch` task
ppkarwasz e78fcef
Rewrite `LogUtils` call sites
ppkarwasz 7c1c2dd
add suppliers
Pil0tXia c474c70
Revert "Rewrite `LogUtils` call sites"
Pil0tXia 6a8d5cf
Merge branch 'remove-logutils' into pil0txia_enhance_4697
Pil0tXia f21e084
Replace the time-consuming method parms with the supplier usage of Lo…
Pil0tXia be0c532
Execute errorProne scripts and remove blank line by IDEA optimize import
Pil0tXia 5dd28fa
Remove non-supplier methods in LogUtils
Pil0tXia ffcf2dc
Remove unused trace and error log level
Pil0tXia 30ff1bb
Rename LogUtils to LogUtil to save space
Pil0tXia 028f142
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia e6b07b1
Fix checkstyle
Pil0tXia 40a1606
Replace isXXXXEnabled to normal use
Pil0tXia 45028a5
Rename messageLogger to static final MESSAGE_LOGGER
Pil0tXia af00ea3
Fix all checkstyle warnings
Pil0tXia ef7292d
run spotlessApply
Pil0tXia 005316c
Fix JDK11 Javadoc task failed
Pil0tXia abc67ce
Add {} and fix javadoc task
Pil0tXia c259f00
Revert "Add minimal `errorPronePatch` task"
Pil0tXia 3731d78
Turn back to surpress javadoc only on JDK8
Pil0tXia 56b3d16
Fix logging lack param
Pil0tXia a88e2f7
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia ae565be
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ classes | |
| package-lock.json | ||
| node_modules | ||
| .run | ||
| *.log | ||
|
|
||
| h2/db.mv.db | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/LogUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.eventmesh.common.utils; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.spi.CallerBoundaryAware; | ||
| import org.slf4j.spi.LoggingEventBuilder; | ||
|
|
||
| import lombok.experimental.UtilityClass; | ||
|
|
||
| /** | ||
| * This class provides logging methods that encapsulate SLF4J and Supplier. | ||
| * If the log level is not enabled, the passed Supplier is invoked lazily, | ||
| * thereby avoiding unnecessary method execution time. | ||
| * <p> | ||
| * The statement | ||
| * <pre> | ||
| * {@code | ||
| * LogUtil.debug(log, "A time-consuming method: {}", () -> myMethod()); | ||
| * } | ||
| * </pre> | ||
| * is equivalent to: | ||
| * <pre> | ||
| * {@code | ||
| * if (logger.isDebugEnabled()) { | ||
| * logger.debug("A time-consuming method: {}", myMethod()); | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * If no object parameters are passed or existing objects are referenced, use | ||
| * <pre> | ||
| * {@code | ||
| * log.debug("No time-consuming methods: {}", myObject); | ||
| * } | ||
| * </pre> | ||
| * instead. | ||
| */ | ||
|
|
||
| @UtilityClass | ||
| public final class LogUtil { | ||
|
|
||
| private static final String FQCN = LogUtil.class.getName(); | ||
|
|
||
| public static void debug(Logger logger, String format, Supplier<?> objectSupplier) { | ||
| final LoggingEventBuilder builder = logger.atDebug(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).log(format); | ||
| } | ||
|
|
||
| public static void debug(Logger logger, String format, Supplier<?> objectSupplier, Throwable t) { | ||
| final LoggingEventBuilder builder = logger.atDebug(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).setCause(t).log(format); | ||
| } | ||
|
|
||
| public static void debug(Logger logger, String format, Supplier<?>... objectSuppliers) { | ||
| LoggingEventBuilder builder = logger.atDebug(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| for (Supplier<?> objectSupplier : objectSuppliers) { | ||
| builder = builder.addArgument(objectSupplier); | ||
| } | ||
| builder.log(format); | ||
| } | ||
|
|
||
| public static void info(Logger logger, String format, Supplier<?> objectSupplier) { | ||
| final LoggingEventBuilder builder = logger.atInfo(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).log(format); | ||
| } | ||
|
|
||
| public static void info(Logger logger, String format, Supplier<?> objectSupplier, Throwable t) { | ||
| final LoggingEventBuilder builder = logger.atInfo(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).setCause(t).log(format); | ||
| } | ||
|
|
||
| public static void info(Logger logger, String format, Supplier<?>... objectSuppliers) { | ||
| LoggingEventBuilder builder = logger.atInfo(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| for (Supplier<?> objectSupplier : objectSuppliers) { | ||
| builder = builder.addArgument(objectSupplier); | ||
| } | ||
| builder.log(format); | ||
| } | ||
|
|
||
| public static void warn(Logger logger, String format, Supplier<?> objectSupplier) { | ||
| final LoggingEventBuilder builder = logger.atWarn(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).log(format); | ||
| } | ||
|
|
||
| public static void warn(Logger logger, String format, Supplier<?> objectSupplier, Throwable t) { | ||
| final LoggingEventBuilder builder = logger.atWarn(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| builder.addArgument(objectSupplier).setCause(t).log(format); | ||
| } | ||
|
|
||
| public static void warn(Logger logger, String format, Supplier<?>... objectSuppliers) { | ||
| LoggingEventBuilder builder = logger.atWarn(); | ||
| if (builder instanceof CallerBoundaryAware) { | ||
| ((CallerBoundaryAware) builder).setCallerBoundary(FQCN); | ||
| } | ||
| for (Supplier<?> objectSupplier : objectSuppliers) { | ||
| builder = builder.addArgument(objectSupplier); | ||
| } | ||
| builder.log(format); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.