Category : log4j2

log4j2elastic <!– https://mvnrepository.com/artifact/net.inemar.utility/log4j2elastic –> <dependency> <groupId>net.inemar.utility</groupId> <artifactId>log4j2elastic</artifactId> <version>3.1.0</version> </dependency> Log4j2 configuration <?xml version=”1.0″ encoding=”UTF-8″?> <Configuration status=”warn” name=”MyApp” packages=””> <Appenders> <Console name=”Console” target=”SYSTEM_OUT” ignoreExceptions=”false”> <PatternLayout pattern=”%d{yyyy-MM-dd HH:mm:ss} [%t] (%F:%L) – %m%n” /> </Console> <ElasticAppender name=”ElasticAppender” manager=”true”/> </Appenders> <Loggers> <Root level=”info”> <AppenderRef ref=”Console” /> <AppenderRef ref=”ElasticAppender” level=”error” /> </Root> </Loggers> </Configuration> Configure environment variables elastic_local = native://192.168.99.100:9300 ..

Read more

maven <!– log4j2 kafka appender –> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>0.9.0.1</version> <exclusions> <!– exclude掉过时的log依赖 –> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.10.4</version> </dependency> <!– log4j2 async –> <dependency> <groupId>com.lmax</groupId> <artifactId>disruptor</artifactId> <version>3.3.0</version> </dependency> log4j2.xml <?xml version=”1.0″ encoding=”UTF-8″?> <Configuration status=”warn” name=”MyApp” packages=””> <Appenders> <Console name=”Console” target=”SYSTEM_OUT” ignoreExceptions=”false”> <PatternLayout pattern=”%d{yyyy-MM-dd HH:mm:ss} [%t] ..

Read more

Example For example, add your own appender ref under root logger. public static void load(String appId,String serverAddress,int port){ final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); final org.apache.logging.log4j.core.config.Configuration config = ctx.getConfiguration(); PatternLayout layout= PatternLayout.createLayout(“%d{yyyy-MM-dd HH:mm:ss} [%t] (%F:%L) – %m%n”, null, config,null, Charset.forName(“UTF-8”),true,false,null,null); Appender appender= MyLog4j2Appender.createAppender(“MyLog4j2Appender”,layout, null, null); appender.start(); config.addAppender(appender); config.getLoggerConfig(“ROOT”).addAppender(appender, Level.ERROR,null); ctx.updateLoggers(config); } In fact, the corresponding ..

Read more