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 0000000000000000000000000000000000000000..c50e8f8e8ef93e9778287f299e88520f43f3001c --- /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 3d1e44d9d924b80d3acf0f9f4f53867d5acd8080..4f7551b3655864da1183389d580e09c9871c6e35 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;