Skip to content
Merged
Show file tree
Hide file tree
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 Dec 29, 2023
9c23c8b
recommanded example
Pil0tXia Dec 29, 2023
9f1e5d3
add known dependencies
Pil0tXia Dec 29, 2023
8daf32a
remove log4j-to-slf4j
Pil0tXia Dec 29, 2023
bd6c91c
Revert "recommanded example"
Pil0tXia Dec 30, 2023
854f39f
Deprecate `LogUtils` for removal
ppkarwasz Dec 30, 2023
3e4dc11
Add minimal `errorPronePatch` task
ppkarwasz Dec 30, 2023
e78fcef
Rewrite `LogUtils` call sites
ppkarwasz Dec 30, 2023
7c1c2dd
add suppliers
Pil0tXia Dec 30, 2023
c474c70
Revert "Rewrite `LogUtils` call sites"
Pil0tXia Jan 5, 2024
6a8d5cf
Merge branch 'remove-logutils' into pil0txia_enhance_4697
Pil0tXia Jan 5, 2024
f21e084
Replace the time-consuming method parms with the supplier usage of Lo…
Pil0tXia Jan 5, 2024
be0c532
Execute errorProne scripts and remove blank line by IDEA optimize import
Pil0tXia Jan 5, 2024
5dd28fa
Remove non-supplier methods in LogUtils
Pil0tXia Jan 5, 2024
ffcf2dc
Remove unused trace and error log level
Pil0tXia Jan 5, 2024
30ff1bb
Rename LogUtils to LogUtil to save space
Pil0tXia Jan 5, 2024
028f142
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia Jan 5, 2024
e6b07b1
Fix checkstyle
Pil0tXia Jan 5, 2024
40a1606
Replace isXXXXEnabled to normal use
Pil0tXia Jan 5, 2024
45028a5
Rename messageLogger to static final MESSAGE_LOGGER
Pil0tXia Jan 5, 2024
af00ea3
Fix all checkstyle warnings
Pil0tXia Jan 5, 2024
ef7292d
run spotlessApply
Pil0tXia Jan 5, 2024
005316c
Fix JDK11 Javadoc task failed
Pil0tXia Jan 5, 2024
abc67ce
Add {} and fix javadoc task
Pil0tXia Jan 6, 2024
c259f00
Revert "Add minimal `errorPronePatch` task"
Pil0tXia Jan 6, 2024
3731d78
Turn back to surpress javadoc only on JDK8
Pil0tXia Jan 6, 2024
56b3d16
Fix logging lack param
Pil0tXia Jan 6, 2024
a88e2f7
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia Jan 11, 2024
ae565be
Merge branch 'master' into pil0txia_enhance_4697
Pil0tXia Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ classes
package-lock.json
node_modules
.run
*.log

h2/db.mv.db

Expand Down
18 changes: 10 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ buildscript {
}
}

//Remove doclint warnings that pollute javadoc logs when building with java8
if(JavaVersion.current().isJava8()){
// Remove doclint warnings that pollute javadoc logs when building
if (JavaVersion.current().isJava8()) {
allprojects {
tasks.withType(Javadoc){
options.addStringOption('xdoclint:none','-quiet')
tasks.withType(Javadoc) {
options.addStringOption('xdoclint:none', '-quiet')
}
}
}
Expand Down Expand Up @@ -473,6 +473,7 @@ subprojects {
}

def grpcVersion = '1.43.2'
def log4jVersion = '2.22.1'

dependencyManagement {
dependencies {
Expand All @@ -486,10 +487,11 @@ subprojects {

dependency "com.google.guava:guava:31.0.1-jre"

dependency "org.slf4j:slf4j-api:1.7.30"
dependency "org.apache.logging.log4j:log4j-api:2.17.1"
dependency "org.apache.logging.log4j:log4j-core:2.17.1"
dependency "org.apache.logging.log4j:log4j-slf4j-impl:2.17.1"
dependency "org.slf4j:slf4j-api:2.0.9"
dependency "org.apache.logging.log4j:log4j-api:${log4jVersion}"
dependency "org.apache.logging.log4j:log4j-core:${log4jVersion}"
dependency "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
dependency "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" // used with SLF4J 1.7.x or older for third-party dependencies

dependency "com.lmax:disruptor:3.4.2"

Expand Down
4 changes: 2 additions & 2 deletions eventmesh-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

implementation "org.apache.logging.log4j:log4j-api"
implementation "org.apache.logging.log4j:log4j-core"
implementation "org.apache.logging.log4j:log4j-slf4j-impl"
implementation "org.apache.logging.log4j:log4j-slf4j2-impl"

implementation 'com.github.seancfoley:ipaddress'

Expand Down Expand Up @@ -67,7 +67,7 @@ dependencies {
testImplementation "org.slf4j:slf4j-api"
testImplementation "org.apache.logging.log4j:log4j-api"
testImplementation "org.apache.logging.log4j:log4j-core"
testImplementation "org.apache.logging.log4j:log4j-slf4j-impl"
testImplementation "org.apache.logging.log4j:log4j-slf4j2-impl"

testImplementation "com.lmax:disruptor"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.eventmesh.common.file;

import org.apache.eventmesh.common.utils.LogUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -62,10 +60,10 @@ private static void shutdown() {
return;
}

LogUtils.info(log, "[WatchFileManager] start close");
log.info("[WatchFileManager] start close");

for (Map.Entry<String, WatchFileTask> entry : WATCH_FILE_TASK_MAP.entrySet()) {
LogUtils.info(log, "[WatchFileManager] start to shutdown : {}", entry.getKey());
log.info("[WatchFileManager] start to shutdown : {}", entry.getKey());

try {
entry.getValue().shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.eventmesh.common.file;

import org.apache.eventmesh.common.utils.LogUtils;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
Expand Down Expand Up @@ -89,15 +87,15 @@ public void run() {
for (WatchEvent<?> event : events) {
WatchEvent.Kind<?> kind = event.kind();
if (kind.equals(StandardWatchEventKinds.OVERFLOW)) {
LogUtils.warn(log, "[WatchFileTask] file overflow: {}", event.context());
log.warn("[WatchFileTask] file overflow: {}", event.context());
continue;
}
precessWatchEvent(event);
}
} catch (InterruptedException ex) {
boolean interrupted = Thread.interrupted();
if (interrupted) {
LogUtils.debug(log, "[WatchFileTask] file watch is interrupted");
log.debug("[WatchFileTask] file watch is interrupted");
}
} catch (Exception ex) {
log.error("[WatchFileTask] an exception occurred during file listening : ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.eventmesh.common.protocol.tcp.Subscription;
import org.apache.eventmesh.common.protocol.tcp.UserAgent;
import org.apache.eventmesh.common.utils.JsonUtils;
import org.apache.eventmesh.common.utils.LogUtils;
import org.apache.eventmesh.common.utils.LogUtil;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -39,7 +39,6 @@
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.ReplayingDecoder;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Preconditions;

Expand Down Expand Up @@ -73,9 +72,7 @@ public void encode(ChannelHandlerContext ctx, Package pkg, ByteBuf out) throws E
Preconditions.checkNotNull(pkg, "TcpPackage cannot be null");
final Header header = pkg.getHeader();
Preconditions.checkNotNull(header, "TcpPackage header cannot be null", header);
if (log.isDebugEnabled()) {
log.debug("Encoder pkg={}", JsonUtils.toJSONString(pkg));
}
LogUtil.debug(log, "Encode pkg={}", () -> JsonUtils.toJSONString(pkg));

final byte[] headerData = JsonUtils.toJSONBytes(header);
final byte[] bodyData;
Expand Down Expand Up @@ -161,7 +158,7 @@ private Header parseHeader(ByteBuf in, int headerLength) throws JsonProcessingEx
}
final byte[] headerData = new byte[headerLength];
in.readBytes(headerData);
LogUtils.debug(log, "Decode headerJson={}", deserializeBytes(headerData));
LogUtil.debug(log, "Decode headerJson={}", () -> deserializeBytes(headerData));
return JsonUtils.parseObject(headerData, Header.class);
}

Expand All @@ -171,7 +168,7 @@ private Object parseBody(ByteBuf in, Header header, int bodyLength) throws JsonP
}
final byte[] bodyData = new byte[bodyLength];
in.readBytes(bodyData);
LogUtils.debug(log, "Decode bodyJson={}", deserializeBytes(bodyData));
LogUtil.debug(log, "Decode bodyJson={}", () -> deserializeBytes(bodyData));
return deserializeBody(deserializeBytes(bodyData), header);
}

Expand Down Expand Up @@ -223,7 +220,7 @@ private static Object deserializeBody(String bodyJsonString, Header header) thro
case REDIRECT_TO_CLIENT:
return JsonUtils.parseObject(bodyJsonString, RedirectInfo.class);
default:
LogUtils.warn(log, "Invalidate TCP command: {}", command);
log.warn("Invalidate TCP command: {}", command);
return null;
}
}
Expand Down
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);
}
}
Loading