[logback-user] Logback Joran Custom Conversion Rule

Jennifer Donahoe jlueding at gmail.com
Mon Apr 5 16:39:38 CEST 2021


I'm trying to create a console appender that uses a custom pattern and a
custom conversion rule to run the logback logs through the DataConverter
class. I can see in the logs that the new conversion rule gets created but
the logs get dropped after that point. I assume some setup in the below
code is not correct but I'm not sure where I'm going wrong.





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



I created a question in StackOverflow about this as well:
https://stackoverflow.com/q/66768278/7371030?sem=2



Please let me know if you have any examples of this setup or if you can
pinpoint where I’m going wrong.



Thank you,

Jennifer



This e-mail and any files transmitted with it are confidential and are
solely for the use of the addressee. It may contain material that is
legally privileged, proprietary or subject to copyright belonging to the
sender and its affiliates, and it may be subject to protection under
federal or state law. If you are not the intended recipient, you are
notified that any use of this material is strictly prohibited. If you
received this transmission in error, please contact the sender immediately
by replying to this e-mail and delete the material from your system. The
sender may archive e-mails, which may be accessed by authorized persons and
may be produced to other parties, including public authorities, in
compliance with applicable laws.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20210405/2d7c5f6c/attachment.html>


More information about the logback-user mailing list