Теперь я могу решить эту проблему с помощью поиска: log4j2.yml:
PatternLayout:
Pattern: "%date{yyyy-MM-dd HH:mm:ss.SSS}{UTC}; %msg; %level; %logger; %class; %method; %thread; [%file:%line]%n"
Header: $${headerlookup:header}
Плагин поиска:
@Plugin(name = "headerlookup", category = StrLookup.CATEGORY )
public class IONLog4j2HeaderLookup extends AbstractLookup {
/**
* Lookup the value for the key using the data in the LogEvent.
* @param event The current LogEvent.
* @param key the key to be looked up, may be null
* @return The value associated with the key.
*/
@Override
public String lookup(final LogEvent event, final String key) {
return new IONLogLayout().getFileHeader();
}
}
Не забудьте "$$ ", чтобы прочитать значение во время выполнения.