0

我正在尝试创建一个控制台附加程序,它使用自定义模式和自定义转换规则通过 DataConverter 类运行 logback 日志。我可以在日志中看到创建了新的转换规则,但在那之后日志被删除了。我假设以下代码中的某些设置不正确,但我不确定我哪里出错了。

ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>()
appender.setName("consoleAppender")

RuleStore rs = new SimpleRuleStore(context)

Interpreter interpreter = new Interpreter(context, rs, new ElementPath())
InterpretationContext interpretationContext = interpreter.getInterpretationContext()
interpretationContext.setContext(context)

AttributesImpl attributes = new AttributesImpl()
attributes.addAttribute("","","conversionWord", "", "msgMask")
attributes.addAttribute("","","converterClass", "", "com.x.logging.library.DataConverter")

ConversionRuleAction conversionRule = new ConversionRuleAction()
conversionRule.setContext(context)
conversionRule.begin(interpretationContext, conversionWord, attributes)

PatternLayoutEncoder encoder = new PatternLayoutEncoder()
encoder.setContext(context)
encoder.setPattern('-%clr(%d{-yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(-%5p) %clr(-){magenta} %clr(---){faint} %clr([%t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %msgMask(%msg) %n')
encoder.start()

appender.setEncoder(encoder)
appender.setContext(context)
appender.start()

//the appender is later added to the logger
4

0 回答 0