public String createOutputStreamAppender ( String name , String pattern , String encoding , Collection < String > loggerNames , String levelStr , boolean recursive , boolean overrideLogLevel ) { Level level = getLevel ( levelStr ) ; String encodingToUse = StringUtils . isEmpty ( encoding ) ? "UTF-8" : encoding ; PatternLayout layout = PatternLayout . newBuilder ( ) . withPattern ( StringUtils . isEmpty ( pattern ) ? DEFAULT_PATTERN : pattern ) . withCharset ( Charset . forName ( encodingToUse ) ) . build ( ) ; String appenderName = StringUtils . isEmpty ( name ) ? UUID . randomUUID ( ) . toString ( ) : name ; AdminToolLog4j2OutputStream baos = new AdminToolLog4j2OutputStream ( 4096 , encodingToUse ) ; outputStreams . put ( appenderName , baos ) ; OutputStreamAppender appender = OutputStreamAppender . newBuilder ( ) . setName ( appenderName ) . setTarget ( baos ) . setLayout ( layout ) . setFollow ( false ) . build ( ) ; appender . start ( ) ; final LoggerContext ctx = ( LoggerContext ) LogManager . getContext ( false ) ; final Configuration config = ctx . getConfiguration ( ) ; config . addAppender ( appender ) ; Collection < String > parentLoggerNames = getParentLoggerNames ( ) ; Map < String , LoggerConfig > configs = getRecursiveLoggerConfigs ( loggerNames , recursive , config ) ; configs . entrySet ( ) . forEach ( configEntry -> { configEntry . getValue ( ) . addAppender ( appender , level , null ) ; if ( overrideLogLevel ) { baos . addOriginalLevel ( configEntry . getKey ( ) , configEntry . getValue ( ) . getLevel ( ) ) ; changeLogger ( configEntry . getKey ( ) , level , parentLoggerNames . contains ( configEntry . getKey ( ) ) ) ; } } ) ; ctx . updateLoggers ( ) ; return appenderName ; }
creates the custom output steam appender and returns the name