报错Unable to invoke factory method in class com....log4j.ScheduleLoggerFilter

2020-05-13 16:32:35,613 main ERROR Unable to invoke factory method in class com.yuanian.mbase.config.log4j.ScheduleLoggerFilter for element ScheduleLoggerFilter: java.lang.IllegalStateException: No factory method found for class com.yuanian.mbase.config.log4j.ScheduleLoggerFilter java.lang.IllegalStateException: No factory method found for class com.yuanian.mbase.config.log4j.ScheduleLoggerFilter
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:234)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:134)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:964)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:904)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:896)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.reinitialize(Log4J2LoggingSystem.java:194)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:75)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:148)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.reinitializeLoggingSystem(PropertySourceBootstrapConfiguration.java:136)
at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:113)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:649)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:373)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at com.yuanian.mbase.App.main(App.java:14)

原因:没有加工厂创建方法,即注解标注@PluginFactory的这个方法,必须提供

完整代码如下:

package com.***.**.*.log4j;

import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.job.core.log.XxlJobLogger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.config.Node;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.util.PerformanceSensitive; /**
* @author liujy
* @date 2020/5/13 9:55
* 替换控制台原收集日志filter,增加调度中心rolling收集业务日志的功能
**/
@Plugin(name = "ScheduleLoggerFilter", category = Node.CATEGORY, elementType = Filter.ELEMENT_TYPE, printObject = true)
@PerformanceSensitive({"allocation"})
public class ScheduleLoggerFilter extends AbstractFilter { private final Level level; @PluginFactory
public static ScheduleLoggerFilter createFilter(@PluginAttribute("level") Level level, @PluginAttribute("onMatch") Result match, @PluginAttribute("onMismatch") Result mismatch) {
Level actualLevel = level == null ? Level.ERROR : level;
Result onMatch = match == null ? Result.NEUTRAL : match;
Result onMismatch = mismatch == null ? Result.DENY : mismatch;
return new ScheduleLoggerFilter(actualLevel, onMatch, onMismatch);
} private ScheduleLoggerFilter(Level level, Result onMatch, Result onMismatch) {
super(onMatch, onMismatch);
this.level = level;
} @Override
public Result filter(LogEvent event) {
String logFileName = XxlJobFileAppender.contextHolder.get();
if (logFileName != null && logFileName.trim().length() > 0) {
Message message = event.getMessage();
String formattedMessage = message.getFormattedMessage();
XxlJobLogger.log(formattedMessage);
}
return super.filter(event);
} @Override
public Result filter(Logger logger, Level testLevel, Marker marker, String msg, Object... params) {
return this.filter(testLevel);
} @Override
public Result filter(Logger logger, Level testLevel, Marker marker, Object msg, Throwable t) {
return this.filter(testLevel);
} @Override
public Result filter(Logger logger, Level testLevel, Marker marker, Message msg, Throwable t) {
return this.filter(testLevel);
} private Result filter(Level testLevel) {
return testLevel.isMoreSpecificThan(this.level) ? this.onMatch : this.onMismatch;
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8) {
return this.filter(level);
} @Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object p0, Object p1, Object p2, Object p3, Object p4, Object p5, Object p6, Object p7, Object p8, Object p9) {
return this.filter(level);
} public Level getLevel() {
return this.level;
} }

配置文件

Configuration:
status: warn
packages: com.***.**.*.log4j
monitorInterval: 30
strict: true
Appenders:
Console: #输出到控制台
name: CONSOLE
target: SYSTEM_OUT
filters:
ScheduleLoggerFilter:
level: info
onMatch: ACCEPT
onMismatch: DENY

注意:

  • Console这个appender下的只有第一个filter会生效
  • 需要配置扫描路径Configuration.packages,不然扫描不到配置类

log4j2配置自定义filter报错Unable to invoke factory method in class的更多相关文章

  1. Log4j2 - Unable to invoke factory method in class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFileAppender for element RollingFile

    问题与分析 在使用Log4j2时,虽然可以正确读取配置文件并生成log文件,但偶然发现控制台打印了异常信息如下: 2018-12-31 17:28:14,282 Log4j2-TF-19-Config ...

  2. 在IIS下配置自定义的报错页面

    这里介绍在IIS中配置自定义出错页面的方法,主要以404为例,其他状态可类推 1.远程桌面连接IIS所在的服务器,进入控制面板>系统和安全>管理工具,双击打开IIS管理器,选择需要配置的网 ...

  3. python 接口测试时,后端报错no String-argument constructor/factory method

    解决方法: 1.先将字典转化为序列化的数据类型 data = {"pageNo":0,"pageSize":10,"shopId":15,& ...

  4. C# 解决SharpSvn启动窗口报错 Unable to connect to a repository at URL 'svn://....'

    在远程机打开sharpsvn客户端测试,结果报错 Svn启动窗口报错 Unable to connect to a repository at URL 'svn://...' 咋整,我在win10我的 ...

  5. selenium+phantomjs报错:Unable to find a free port的分析和解决

    selenium+phantomjs报错:Unable to find a free port的分析和解决 Table of Contents 1. 现象 2. 分析 3. 解决办法 1 现象 在做项 ...

  6. dubbo 使用 filter 报错解决

    dubbo可以用filter实现类似tomcat filter过滤器. 实现1.接口请求时间监控. 2.打印输入输出日志(输出日志有应用自己决定) 配置时出现报错. No such extension ...

  7. jpa报错 Unable to acquire a connection from driver [null], user [null] and URL [null]

    jpa报错 Unable to acquire a connection from driver [null], user [null] and URL [null] 为啥报错 因为你在persist ...

  8. Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

    Jpa自定义查询报错 问题背景 今天遇到一个奇怪的报错"Failed to convert from type [java.lang.Object[]] to type",这个报错 ...

  9. delphi调试需要管理员权限程序报错“Unable to create process:请求的操作需要提升”

    delphi调试启动需要UAC权限的程序的时候会报错“Unable to create process:请求的操作需要提升”.这是因为delphi没有以管理员身份启动,这样delphi createp ...

  10. AS添加依赖报错Unable to merge dex

    AS添加依赖报错Unable to merge dex 最近在给项目添加依赖的时候,要给项目导入Bmob的SDK,参照Bmob的官方文档,可以直接在app的build.gradle文件中添加 //Bm ...

随机推荐

  1. NVIDIA Omniverse Audio2Face的安装

    下载 NVIDIA Omniverse 并运行安装程序 - 安装后,打开 Omniverse Launcher - 在"Apps"(应用)部分中找到 Omniverse Audio ...

  2. batch_norm在强化学习中建议使用的形式

    def batch_norm(layer, **kwargs): """ Apply batch normalization to an existing layer. ...

  3. 为baselines算法库安装mujoco环境支持——ubuntu 20.04安装MuJoCo2.1.1

    下载开源版本的mujoco二进制文件: wget https://github.com/deepmind/mujoco/releases/download/2.1.1/mujoco-2.1.1-lin ...

  4. code: 'ERR_OSSL_EVP_UNSUPPORTED' 报错解决

    报错: Error: error:0308010C:digital envelope routines::unsupported at new Hash (node:internal/crypto/h ...

  5. WhaleStudio 分钟级构建 AI 模型,强大 Ops 能力简化模型调度与部署

    什么是机器学习(ML)? 它有什么作用 机器学习(ML)是人工智能(AI)的一个子集,通过算法发现数据中的通用模式,并根据持续不断的训练来优化调整最终结果.ML模型从过去的经验中学习,并根据已有的经验 ...

  6. dpwwn-01靶机笔记

    dpwwn-01靶机笔记 概述 这是一台Vulnhub的靶机,主要在web方面,我们无法找到突破口时,应该怎样抉择mysql和ssh的爆破,以及弱口令的尝试. 我这里准备了连接,当然你也可去Vulnh ...

  7. 将 Rust 代码编译为 WASM

    前言 在现代 Web 开发中,WebAssembly (WASM) 已成为一种强大的工具.它使得开发者可以在浏览器中运行高性能的代码,跨越传统的 JavaScript 性能限制.Rust 语言因其高效 ...

  8. 【CMake系列】05-静态库与动态库编译

    在各种项目类型中,可能我们的项目就是一个 库 项目,向其他人提供 我们开发好的 库 (windows下的 dll /lib : linux下的 .a / .so):有时候在一个项目中,我们对部分功能 ...

  9. String究竟能存储多少字符?

    能存储多少字符,通过以下步骤来看 首先String的length方法返回是int.所以理论上长度一定不会超过int的最大值. 编译器对字符串字面量长度的限制源自Java编译器(如javac)在处理常量 ...

  10. CD、VCD、DVD、BD 傻傻分不清楚?

    CD 激光唱片(Compact Disk, CD),于 1982 年面世,最初用于存储数字音频.容量约 700 MB(80 分钟音频). 激光唱片 | 维基百科 VCD 影音光盘(Video Comp ...