Another alternative is to use the Java DSL: https://logging.apache.org/log4j/2.x/manual/customconfig.html
Then you can reuse normal variables when setting values. On Fri, 20 Nov 2020 at 09:43, Stig Rohde Døssing <stigdoess...@gmail.com> wrote: > > Thank you, did not know about RoutingAppender. Will definitely look into > that. Good to know that wrapping like this is a known pattern. > > On 2020/11/20 14:15:53, Matt Sicker <b...@gmail.com> wrote: > > That plug-in wrapper pattern will always work. Maybe creating properties > to> > > reference as variables is an option? There might be a way to structure > your> > > configuration to use routing appenders or something like that to > minimize> > > duplication, too.> > > > > On Fri, Nov 20, 2020 at 05:07 Stig Rohde Døssing <st...@gmail.com>> > > wrote:> > > > > > Hi,> > > >> > > > I have an application that ships with a number of config files > included. We> > > > have a PatternLayout pattern that is used across all configurations, > since> > > > our application needs to parse logs from that certain logs. We > currently> > > > copy-paste the pattern to each file.> > > >> > > > I took a look at using properties and XInclude to avoid repeating the> > > > pattern, but this doesn't work too well with log4j2-test.xml, since > that> > > > file is not located in the same directory as the production log4j2.xml> > > > files. I would also like to make it easy for customers doing their own> > > > custom log configs to reference the pattern, and it would be nice if > they> > > > could just refer to the pattern by name.> > > >> > > > A bit of a hack I came up with was to programmatically create a named> > > > PatternLayout by using the PluginFactory mechanism> > > >> > > > @Plugin(name = "MyPatternLayout", category = Node.CATEGORY, elementType > => > > > Layout.ELEMENT_TYPE, printObject = true)> > > > class MyPatternLayout {> > > > @PluginFactory> > > > public static PatternLayout createLayout() {> > > > PatternLayout.builder.withPattern(myPattern).build()> > > > }> > > > }> > > >> > > > This lets me refer to MyPatternLayout rather than including the pattern > in> > > > the config files.> > > >> > > > Is this a reasonable way to accomplish reuse, or am I misusing the > factory> > > > mechanism in a way that is likely to break in future releases?> > > >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org