add logback plugin
Signed-off-by: 于树强.信息技术中心.架构部 <yushuqiang@yolo24.com>
This commit is contained in:
parent
d7fc6c626a
commit
1c3cf43e47
|
|
@ -0,0 +1,55 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-log</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</parent>
|
||||
<artifactId>logback-plugin</artifactId>
|
||||
<name>logback-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>bintray-wu-sheng-sky-walking-repository</id>
|
||||
<name>wu-sheng-sky-walking-repository</name>
|
||||
<url>https://api.bintray.com/maven/wu-sheng/skywalking/com.ai.cloud.skywalking-log4j-1.x-plugin/;publish=1</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.ai.cloud.skywalking.plugin.log.logback;
|
||||
import ch.qos.logback.classic.pattern.ClassicConverter;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
|
||||
import com.ai.cloud.skywalking.api.Tracing;
|
||||
import com.ai.cloud.skywalking.conf.AuthDesc;
|
||||
/**
|
||||
*
|
||||
* @author yushuqiang
|
||||
*
|
||||
*/
|
||||
public class LogbackPatternConverter extends ClassicConverter {
|
||||
|
||||
@Override
|
||||
public String convert(ILoggingEvent event) {
|
||||
if (AuthDesc.isAuth()) {
|
||||
return "TID:" + Tracing.getTraceId();
|
||||
}
|
||||
|
||||
return "TID: N/A"+" "+event.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.ai.cloud.skywalking.plugin.log.logback;
|
||||
import ch.qos.logback.classic.PatternLayout;
|
||||
/**
|
||||
*
|
||||
* @author yushuqiang
|
||||
*
|
||||
*/
|
||||
public class TraceIdPatternLogbackLayout extends PatternLayout {
|
||||
static {
|
||||
defaultConverterMap.put("tid",LogbackPatternConverter.class.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.ai;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||
import ch.qos.logback.core.joran.spi.JoranException;
|
||||
import ch.qos.logback.core.util.StatusPrinter;
|
||||
public class LogbackMain {
|
||||
|
||||
static Logger logger = LoggerFactory.getLogger(LogbackMain.class);
|
||||
|
||||
public static void main(String[] args) throws JoranException {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
|
||||
JoranConfigurator configurator = new JoranConfigurator();
|
||||
configurator.setContext(lc);
|
||||
lc.reset();
|
||||
configurator.doConfigure("E:\\testdubbo\\GTrace\\GTrace-client\\src\\test\\resources\\logback.xml");
|
||||
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
|
||||
|
||||
logger.info("Hello world11");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
||||
<!-- 日志输出格式 -->
|
||||
<layout class="com.ai.cloud.skywalking.plugin.log.logback.TraceIdPatternLogbackLayout">
|
||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n</Pattern>
|
||||
</layout>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
Loading…
Reference in New Issue