From 23a75ad9fb1b8f3b6f6268b93fa810445882002d Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Sun, 25 Feb 2024 18:32:32 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E4=BF=AE=E6=94=B9logbac?= =?UTF-8?q?k.xml=E6=96=87=E4=BB=B6=EF=BC=8C=E5=AF=B9info=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?=E7=BA=A7=E5=88=AB=E7=9A=84=E6=97=A5=E5=BF=97=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E5=9C=A8neatlogic=E8=B7=AF=E5=BE=84=E4=B8=8B=E6=89=8D=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1099304205254656]修改logback.xml文件,对info以下级别的日志,只在neatlogic路径下才输出 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1099304205254656 --- .../boolex/ConsoleFilterEvaluator.java | 136 ++++++++++++++++++ ...valuator.java => PathFilterEvaluator.java} | 2 +- 2 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/main/java/neatlogic/framework/logback/boolex/ConsoleFilterEvaluator.java rename src/main/java/neatlogic/framework/logback/boolex/{CustomFilterEvaluator.java => PathFilterEvaluator.java} (96%) diff --git a/src/main/java/neatlogic/framework/logback/boolex/ConsoleFilterEvaluator.java b/src/main/java/neatlogic/framework/logback/boolex/ConsoleFilterEvaluator.java new file mode 100644 index 000000000..c50e8f8e8 --- /dev/null +++ b/src/main/java/neatlogic/framework/logback/boolex/ConsoleFilterEvaluator.java @@ -0,0 +1,136 @@ +/* + * Copyright(c) 2023 NeatLogic Co., Ltd. All Rights Reserved. + * + * Licensed 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 neatlogic.framework.logback.boolex; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.boolex.EventEvaluatorBase; +import org.apache.commons.lang3.StringUtils; + +public class ConsoleFilterEvaluator extends EventEvaluatorBase { + + private String errorPathList; + + private String warnPathList; + + private String infoPathList; + + private String debugPathList; + + private String tracePathList; + + @Override + public boolean evaluate(ILoggingEvent event) throws NullPointerException { + if (event.getLevel() == Level.ERROR) { + if(StringUtils.isNotBlank(errorPathList)) { + String[] split = errorPathList.split("\\|"); + String loggerName = event.getLoggerName(); + for (String path : split) { + if (loggerName.startsWith(path)) { + return true; + } + } + return false; + } + } else if (event.getLevel() == Level.WARN) { + if(StringUtils.isNotBlank(warnPathList)) { + String[] split = warnPathList.split("\\|"); + String loggerName = event.getLoggerName(); + for (String path : split) { + if (loggerName.startsWith(path)) { + return true; + } + } + return false; + } + } else if (event.getLevel() == Level.INFO) { + if(StringUtils.isNotBlank(infoPathList)) { + String[] split = infoPathList.split("\\|"); + String loggerName = event.getLoggerName(); + for (String path : split) { + if (loggerName.startsWith(path)) { + return true; + } + } + return false; + } + } else if (event.getLevel() == Level.DEBUG) { + if(StringUtils.isNotBlank(debugPathList)) { + String[] split = debugPathList.split("\\|"); + String loggerName = event.getLoggerName(); + for (String path : split) { + if (loggerName.startsWith(path)) { + return true; + } + } + return false; + } + } else if (event.getLevel() == Level.TRACE) { + if(StringUtils.isNotBlank(tracePathList)) { + String[] split = tracePathList.split("\\|"); + String loggerName = event.getLoggerName(); + for (String path : split) { + if (loggerName.startsWith(path)) { + return true; + } + } + return false; + } + } + return true; + } + + public String getErrorPathList() { + return errorPathList; + } + + public void setErrorPathList(String errorPathList) { + this.errorPathList = errorPathList; + } + + public String getWarnPathList() { + return warnPathList; + } + + public void setWarnPathList(String warnPathList) { + this.warnPathList = warnPathList; + } + + public String getInfoPathList() { + return infoPathList; + } + + public void setInfoPathList(String infoPathList) { + this.infoPathList = infoPathList; + } + + public String getDebugPathList() { + return debugPathList; + } + + public void setDebugPathList(String debugPathList) { + this.debugPathList = debugPathList; + } + + public String getTracePathList() { + return tracePathList; + } + + public void setTracePathList(String tracePathList) { + this.tracePathList = tracePathList; + } +} diff --git a/src/main/java/neatlogic/framework/logback/boolex/CustomFilterEvaluator.java b/src/main/java/neatlogic/framework/logback/boolex/PathFilterEvaluator.java similarity index 96% rename from src/main/java/neatlogic/framework/logback/boolex/CustomFilterEvaluator.java rename to src/main/java/neatlogic/framework/logback/boolex/PathFilterEvaluator.java index 3d1e44d9d..4f7551b36 100644 --- a/src/main/java/neatlogic/framework/logback/boolex/CustomFilterEvaluator.java +++ b/src/main/java/neatlogic/framework/logback/boolex/PathFilterEvaluator.java @@ -24,7 +24,7 @@ import org.apache.commons.lang3.StringUtils; /** * 优先使用白名单。及:如果白名单和黑名单同时配置,则使用白名单 */ -public class CustomFilterEvaluator extends EventEvaluatorBase { +public class PathFilterEvaluator extends EventEvaluatorBase { private String whitelist; -- Gitee