一、搭建SkyWalking
官方文档(英文):skywalking/docs at master · apache/skywalking
中文可以使用:GitHub - SkyAPM/document-cn-translation-of-skywalking: [已过期,请使用官网AI文档] The CN translation version of Apache SkyWalking document
需要搭建服务:SkyWalkingOAP,SkyWalkingUi, Elastisearch
1.先搭建SkyWalkingOAP服务.
SkyWalkingOAP 负责数据的收集、分析和存储。通过部署oap来启动SkyWalking的基础服务。
1.1首先搭建工作负载:
kind: Deployment
apiVersion: apps/v1
metadata:
name: skywalk-970-oap
namespace: common
labels:
app: skywalk-970-oap
annotations:
deployment.kubernetes.io/revision: '4'
kubesphere.io/creator: fly
spec:
replicas: 1
selector:
matchLabels:
app: skywalk-970-oap
template:
metadata:
creationTimestamp: null
labels:
app: skywalk-970-oap
release: skywalking
annotations:
kubesphere.io/creator: fly
kubesphere.io/restartedAt: '2024-05-22T03:21:09.886Z'
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- name: oap
image: '159.75.136.188:40080/szqc2023002/skywalking-oap-server:9.7.0'
ports:
- name: grpc
containerPort: 11800
protocol: TCP
- name: rest
containerPort: 12800
protocol: TCP
env:
- name: JAVA_OPTS
value: '-Xmx1g -Xms1g'
- name: SW_CORE_RECORD_DATA_TTL
value: '2'
- name: SW_CORE_METRICS_DATA_TTL
value: '2'
- name: SW_STORAGE
value: elasticsearch
- name: SW_STORAGE_ES_CLUSTER_NODES
value: 'elasticsearch762.common:9200'
resources:
limits:
memory: 2Gi
requests:
memory: 1Gi
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
我们存储日志的方式是使用es.
1.2然后搭建SkyWalking服务
kind: Service
apiVersion: v1
metadata:
name: skywalk-970-oap
namespace: common
labels:
app: skywalk-970-oap
annotations:
kubesphere.io/creator: fly
spec:
ports:
- name: tcp-11800
protocol: TCP
port: 11800
targetPort: 11800
nodePort: 30876
- name: tcp-12800
protocol: TCP
port: 12800
targetPort: 12800
nodePort: 31012
selector:
app: skywalk-970-oap
release: skywalking
clusterIP: 10.233.43.222
clusterIPs:
- 10.233.43.222
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
至此,SkyWalkingOAP服务完成。
2.搭建SkyWalkingUi服务
SkyWalkibgUi是SkyWalking的可视化界面服务。用于展示分布式系统的监控数据。我们可以通过WebUi来访问和使用SkyWalking。
2.1首先搭建SkyWalkingUi的工作负载
kind: Deployment
apiVersion: apps/v1
metadata:
name: skywalk-970-ui
namespace: common
labels:
app: skywalk-970-ui
annotations:
deployment.kubernetes.io/revision: '4'
kubesphere.io/creator: fly
spec:
replicas: 1
selector:
matchLabels:
app: skywalk-970-ui
template:
metadata:
creationTimestamp: null
labels:
app: skywalk-970-ui
release: skywalking
annotations:
kubesphere.io/creator: fly
kubesphere.io/restartedAt: '2024-05-22T03:10:50.693Z'
spec:
containers:
- name: sk-ui
image: 'apache/skywalking-ui:9.7.0'
ports:
- containerPort: 8080
protocol: TCP
env:
- name: SW_OAP_ADDRESS
value: 'http://skywalk-970-oap.common:12800'
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
2.2搭建SkyWalkingUi服务
kind: Service
apiVersion: v1
metadata:
name: skywalk-970-ui
namespace: common
labels:
app: skywalk-970-ui
annotations:
kubesphere.io/creator: fly
spec:
ports:
- name: http-8080
protocol: TCP
port: 8080
targetPort: 8080
nodePort: 31195
selector:
app: skywalk-970-ui
release: skywalking
clusterIP: 10.233.2.227
clusterIPs:
- 10.233.2.227
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
至此SkyWalkingUi服务搭建完成。
3.搭建Es服务,用于存储SkyWalking日志。
3.1搭建Es服务的工作负载
kind: Deployment
apiVersion: apps/v1
metadata:
name: elasticsearch762
namespace: common
labels:
app: elasticsearch762
annotations:
deployment.kubernetes.io/revision: '4'
kubesphere.io/creator: fly
kubesphere.io/description: 未提供nodeport服务,供Skywalking做数据源
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch762
template:
metadata:
creationTimestamp: null
labels:
app: elasticsearch762
annotations:
kubesphere.io/creator: fly
kubesphere.io/restartedAt: '2024-05-22T03:41:36.061Z'
logging.kubesphere.io/logsidecar-config: '{}'
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
- name: volume-m5uec2
configMap:
name: elasticsearch760
items:
- key: elasticsearch.yml
path: elasticsearch.yml
defaultMode: 420
- name: volume-vcbpgy
configMap:
name: elasticsearch760
items:
- key: jvm.options
path: jvm.options
defaultMode: 420
containers:
- name: container-3sukk2
image: 'elasticsearch:7.6.2'
ports:
- name: tcp-9200
containerPort: 9200
protocol: TCP
- name: tcp-9300
containerPort: 9300
protocol: TCP
env:
- name: discovery.type
value: single-node
- name: ES_JAVA_OPTS
value: '-Xms1024m -Xmx1024m'
resources: {}
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
- name: volume-m5uec2
readOnly: true
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
- name: volume-vcbpgy
readOnly: true
mountPath: /usr/share/elasticsearch/config/jvm.options
subPath: jvm.options
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
nodeSelector:
kubernetes.io/hostname: worker1
serviceAccountName: default
serviceAccount: default
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
3.2搭建Es的服务
kind: Service
apiVersion: v1
metadata:
name: elasticsearch762
namespace: common
labels:
app: elasticsearch762
annotations:
kubesphere.io/creator: fly
spec:
ports:
- name: tcp-9200
protocol: TCP
port: 9200
targetPort: 9200
- name: tcp-9300
protocol: TCP
port: 9300
targetPort: 9300
selector:
app: elasticsearch762
clusterIP: 10.233.7.71
clusterIPs:
- 10.233.7.71
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
至此Es搭建服务完成。需要注意的点是:SkyWalkingAOP配置的Es的变量值,要对应Es的Dns服务名称。
- name: SW_STORAGE_ES_CLUSTER_NODES
value: 'elasticsearch762.common:9200'
二、项目集成Skywalking
在需要集成SkyWalking服务的deploy.yml添加initContainer,达到无侵入方式集成。
kind: Deployment
apiVersion: apps/v1
metadata:
name: zhqc-frame-gateway
namespace: szqc2023002-dev
labels:
app: zhqc-frame-gateway
annotations:
deployment.kubernetes.io/revision: '86'
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"zhqc-frame-gateway"},"name":"zhqc-frame-gateway","namespace":"szqc2023002-dev"},"spec":{"progressDeadlineSeconds":600,"replicas":1,"selector":{"matchLabels":{"app":"zhqc-frame-gateway"}},"strategy":{"rollingUpdate":{"maxSurge":"50%","maxUnavailable":"50%"},"type":"RollingUpdate"},"template":{"metadata":{"labels":{"app":"zhqc-frame-gateway"}},"spec":{"containers":[{"env":[{"name":"JAVA_TOOL_OPTIONS","value":"-javaagent:/skywalking/agent/skywalking-agent.jar"},{"name":"SW_AGENT_NAME","value":"zhqc-frame-gateway"},{"name":"SW_AGENT_COLLECTOR_BACKEND_SERVICES","value":"192.168.10.222:30876"},{"name":"SW_AGENT_TRACE_IGNORE_PATH","value":"GET:/actuator/**,Lettuce/**"},{"name":"SPRING_PROFILES_ACTIVE","value":"dev_k8s"},{"name":"NACOS_ENABLED","value":"true"},{"name":"NACOS_SERVER_ADDR","value":"192.168.10.222"},{"name":"NACOS_SERVER_PORT","value":"32064"},{"name":"NACOS_SERVER_USERNAME","value":"nacos"},{"name":"NACOS_SERVER_PASSWORD","value":"nacos"},{"name":"NACOS_DISCOVERY_NAMESPACE","value":"ff54f1f9-5b3f-432e-addc-0b006b2646c7"},{"name":"NACOS_CONFIG_NAMESPACE","value":"016dcce2-92c4-4ae4-b2e3-3375d790c43a"}],"image":"159.75.136.188:40080/szqc2023002/zhqc-frame-gateway:SNAPSHOT-87","imagePullPolicy":"Always","name":"app","ports":[{"containerPort":8080,"protocol":"TCP"}],"resources":{"limits":{"memory":"1000Mi"},"requests":{"cpu":"100m","memory":"200Mi"}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","volumeMounts":[{"mountPath":"/skywalking","name":"skywalking-agent"}]}],"dnsPolicy":"ClusterFirst","imagePullSecrets":[{"name":"zhqc-dockerhub"}],"initContainers":[{"args":["-c","cp
-R /skywalking/agent /agent/;cp
/skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
/agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
/agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
trace.ignore_path=\\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} \u003e
/agent/agent/config/apm-trace-ignore-plugin.config; cp
/skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar; cp
/skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;"],"command":["/bin/sh"],"image":"apache/skywalking-java-agent:9.0.0-alpine","name":"agent-container","volumeMounts":[{"mountPath":"/agent","name":"skywalking-agent"}]}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"volumes":[{"emptyDir":{},"name":"skywalking-agent"}]}}}}
spec:
replicas: 1
selector:
matchLabels:
app: zhqc-frame-gateway
template:
metadata:
creationTimestamp: null
labels:
app: zhqc-frame-gateway
pod-template-hash: 788dd5dc8b
annotations:
kubesphere.io/restartedAt: '2024-05-20T05:52:23.124Z'
spec:
volumes:
- name: skywalking-agent
emptyDir: {}
initContainers:
- name: agent-container
image: 'apache/skywalking-java-agent:9.0.0-alpine'
command:
- /bin/sh
args:
- '-c'
- >-
cp -R /skywalking/agent /agent/;cp
/skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
/agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
/agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
trace.ignore_path=\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} >
/agent/agent/config/apm-trace-ignore-plugin.config; cp
/skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar;
cp
/skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;
resources: {}
volumeMounts:
- name: skywalking-agent
mountPath: /agent
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
containers:
- name: app
image: '159.75.136.188:40080/szqc2023002/zhqc-frame-gateway:SNAPSHOT-2'
ports:
- containerPort: 8080
protocol: TCP
env:
- name: JAVA_TOOL_OPTIONS
value: '-javaagent:/skywalking/agent/skywalking-agent.jar'
- name: SW_AGENT_NAME
value: zhqc-frame-gateway
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: '192.168.10.222:30876'
- name: SW_AGENT_TRACE_IGNORE_PATH
value: 'GET:/actuator/**,Lettuce/**'
- name: SPRING_PROFILES_ACTIVE
value: dev_k8s
- name: NACOS_ENABLED
value: 'true'
- name: NACOS_SERVER_ADDR
value: nacos223.szqc2023002-dev
- name: NACOS_SERVER_PORT
value: '8848'
- name: NACOS_SERVER_USERNAME
value: nacos4app
- name: NACOS_SERVER_PASSWORD
value: nacos@2024
- name: NACOS_DISCOVERY_NAMESPACE
value: ff54f1f9-5b3f-432e-addc-0b006b2646c7
- name: NACOS_CONFIG_NAMESPACE
value: 016dcce2-92c4-4ae4-b2e3-3375d790c43a
resources:
limits:
memory: 1000Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: skywalking-agent
mountPath: /skywalking
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
- name: zhqc-dockerhub
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 50%
maxSurge: 50%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
添加了挂载点:
spec:
volumes:
- name: skywalking-agent
emptyDir: {}
添加了initContainer
initContainers:
- name: agent-container
image: 'apache/skywalking-java-agent:9.0.0-alpine'
command:
- /bin/sh
args:
- '-c'
- >-
cp -R /skywalking/agent /agent/;cp
/skywalking/agent/optional-plugins/apm-trace-ignore-plugin-9.0.0.jar
/agent/agent/plugins/apm-trace-ignore-plugin-9.0.0.jar;rm
/agent/agent/plugins/apm-redisson-3.x-plugin-9.0.0.jar;echo
trace.ignore_path=\${SW_AGENT_TRACE_IGNORE_PATH:Lettuce/**} >
/agent/agent/config/apm-trace-ignore-plugin.config; cp
/skywalking/agent/optional-plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-cloud-gateway-3.x-plugin-9.0.0.jar;
cp
/skywalking/agent/optional-plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar
/agent/agent/plugins/apm-spring-webflux-5.x-plugin-9.0.0.jar;
resources: {}
volumeMounts:
- name: skywalking-agent
mountPath: /agent
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
增加了SkyWalking的相关配置:
env:
- name: JAVA_TOOL_OPTIONS
value: '-javaagent:/skywalking/agent/skywalking-agent.jar'
- name: SW_AGENT_NAME
value: zhqc-frame-gateway
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: '192.168.10.222:30876'
- name: SW_AGENT_TRACE_IGNORE_PATH
value: 'GET:/actuator/**,Lettuce/**'
SkyWalking忽略的接口
- name: SW_AGENT_TRACE_IGNORE_PATH
value: 'GET:/actuator/**,Lettuce/**'
SkyWalking的收集服务,即SkyWalkingAOP暴漏的服务
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES
value: '192.168.10.222:30876'
部署服务之后,就可以在SKyWalking看到该服务。
三、项目将日志集成到SkyWalking中。
1.引入pom包
<!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-trace --> <dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-trace</artifactId> <version>9.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.skywalking/apm-toolkit-logback-1.x --> <dependency> <groupId>org.apache.skywalking</groupId> <artifactId>apm-toolkit-logback-1.x</artifactId> <version>9.0.0</version> </dependency> </dependencies>
2.修改logback-spring.xml的配置
<?xml version="1.0" encoding="UTF-8" ?> <!-- 级别从高到低 OFF 、 FATAL 、 ERROR 、 WARN 、 INFO 、 DEBUG 、 TRACE 、 ALL --> <!-- 日志输出规则 根据当前ROOT 级别,日志输出时,级别高于root默认的级别时 会输出 --> <!-- 以下 每个配置的 filter 是过滤掉输出文件里面,会出现高级别文件,依然出现低级别的日志信息,通过filter 过滤只记录本级别的日志 --> <!-- scan 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true。 --> <!-- scanPeriod 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 --> <!-- debug 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 --> <configuration scan="true" scanPeriod="60 seconds" debug="false"> <contextName>springboot-security</contextName> <include resource="org/springframework/boot/logging/logback/defaults.xml"/> <springProperty scope="context" name="APP_PORT" source="server.port"/> <springProperty scope="context" name="springAppName" source="spring.application.name"/> <springProperty scope="context" name="log.home_dir" source="logging.path"/> <!-- 日志输出格式 --> <property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS}[${springAppName}-${APP_PORT}][%clr(${PID:-}) %X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread] %-5level %logger{50} - %msg%n"/> <!-- 定义日志文件 输出位置 --> <!--<springProfile name="dev">--> <!--<property name="log.home_dir" value="${logging.path}"/>--> <!--</springProfile>--> <!--<springProfile name="test">--> <!--<property name="log.home_dir" value="${logging.path}"/>--> <!--</springProfile>--> <!--<springProfile name="prod">--> <!--<property name="log.home_dir" value="${logging.path}"/>--> <!--</springProfile>--> <!-- 日志最大的历史 30天 --> <property name="log.maxHistory" value="30"/> <!-- 打印debug级别日志及以上级别日志 --> <property name="log.level" value="info"/> <!-- ConsoleAppender 控制台输出日志 start --> <!-- <appender name="console" class="ch.qos.logback.core.ConsoleAppender">--> <!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">--> <!-- <level>INFO</level>--> <!-- </filter>--> <!-- <encoder>--> <!-- <pattern>--> <!-- <pattern>${CONSOLE_LOG_PATTERN}</pattern>--> <!-- <!–<charset>utf8</charset>–>--> <!-- </pattern>--> <!-- </encoder>--> <!-- </appender>--> <!-- ConsoleAppender 控制台输出日志 end --> <!-- errorAppender 控制台输出日志 start --> <!-- <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">--> <!-- <!– 过滤器,只记录WARN级别的日志 –>--> <!-- <!– 果日志级别等于配置级别,过滤器会根据onMath 和 onMismatch接收或拒绝日志。 –>--> <!-- <filter class="ch.qos.logback.classic.filter.LevelFilter">--> <!-- <!– 设置过滤级别 –>--> <!-- <level>ERROR</level>--> <!-- <!– 用于配置符合过滤条件的操作 –>--> <!-- <onMatch>ACCEPT</onMatch>--> <!-- <!– 用于配置不符合过滤条件的操作 –>--> <!-- <onMismatch>DENY</onMismatch>--> <!-- </filter>--> <!-- <!– 最常用的滚动策略,它根据时间来制定滚动策略.既负责滚动也负责触发滚动 –>--> <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> <!-- <!–日志输出位置 可以是相对和绝对路径 –>--> <!-- <fileNamePattern>--> <!-- ${log.home_dir}/error/%d{yyyy-MM-dd}/errorLog-%i.log--> <!-- </fileNamePattern>--> <!-- <!– 可选节点,控制保留的归档文件的最大数量,超出数量就删除旧文件假设设置每个月滚动,且<maxHistory>是6, 则只保存最近6个月的文件,删除之前的旧文件。注意,删除旧文件是,那些为了归档而创建的目录也会被删除 –>--> <!-- <maxHistory>${log.maxHistory}</maxHistory>--> <!-- <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">--> <!-- <!– 单个log文件超过该大小就会重新建一个log文件 –>--> <!-- <MaxFileSize>2MB</MaxFileSize>--> <!-- </TimeBasedFileNamingAndTriggeringPolicy>--> <!-- </rollingPolicy>--> <!-- <encoder>--> <!-- <pattern>--> <!-- <pattern>${CONSOLE_LOG_PATTERN}</pattern>--> <!-- <charset>utf8</charset>--> <!-- </pattern>--> <!-- </encoder>--> <!-- </appender>--> <!-- errorAppender 控制台输出日志 end --> <!-- warnAppender 控制台输出日志 start --> <!-- <appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">--> <!-- <filter class="ch.qos.logback.classic.filter.LevelFilter">--> <!-- <level>WARN</level>--> <!-- <onMatch>ACCEPT</onMatch>--> <!-- <onMismatch>DENY</onMismatch>--> <!-- </filter>--> <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> <!-- <fileNamePattern>--> <!-- ${log.home_dir}/warn/%d{yyyy-MM-dd}/warnLog-%i.log--> <!-- </fileNamePattern>--> <!-- <maxHistory>${log.maxHistory}</maxHistory>--> <!-- <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">--> <!-- <MaxFileSize>2MB</MaxFileSize>--> <!-- </TimeBasedFileNamingAndTriggeringPolicy>--> <!-- </rollingPolicy>--> <!-- <encoder>--> <!-- <pattern>--> <!-- <pattern>${CONSOLE_LOG_PATTERN}</pattern>--> <!-- <charset>utf8</charset>--> <!-- </pattern>--> <!-- </encoder>--> <!-- </appender>--> <!-- warnAppender 控制台输出日志 end --> <!-- infoAppender 控制台输出日志 start --> <!-- <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">--> <!-- <filter class="ch.qos.logback.classic.filter.LevelFilter">--> <!-- <level>INFO</level>--> <!-- <onMatch>ACCEPT</onMatch>--> <!-- <onMismatch>DENY</onMismatch>--> <!-- </filter>--> <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> <!-- <fileNamePattern>${log.home_dir}/info/%d{yyyy-MM-dd}/infoLog-%i.log</fileNamePattern>--> <!-- <maxHistory>${log.maxHistory}</maxHistory>--> <!-- <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">--> <!-- <MaxFileSize>2MB</MaxFileSize>--> <!-- </TimeBasedFileNamingAndTriggeringPolicy>--> <!-- </rollingPolicy>--> <!-- <encoder>--> <!-- <pattern>--> <!-- <pattern>${CONSOLE_LOG_PATTERN}</pattern>--> <!-- <charset>utf8</charset>--> <!-- </pattern>--> <!-- </encoder>--> <!-- </appender>--> <!-- infoAppender 控制台输出日志 end --> <!-- debugAppender 控制台输出日志 start --> <!-- <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">--> <!-- <filter class="ch.qos.logback.classic.filter.LevelFilter">--> <!-- <level>DEBUG</level>--> <!-- <onMatch>ACCEPT</onMatch>--> <!-- <onMismatch>DENY</onMismatch>--> <!-- </filter>--> <!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">--> <!-- <fileNamePattern>${log.home_dir}/debug/%d{yyyy-MM-dd}/debugLog-%i.log</fileNamePattern>--> <!-- <maxHistory>${log.maxHistory}</maxHistory>--> <!-- <TimeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">--> <!-- <MaxFileSize>2MB</MaxFileSize>--> <!-- </TimeBasedFileNamingAndTriggeringPolicy>--> <!-- </rollingPolicy>--> <!-- <encoder>--> <!-- <pattern>--> <!-- <pattern>${CONSOLE_LOG_PATTERN}</pattern>--> <!-- <charset>utf8</charset>--> <!-- </pattern>--> <!-- </encoder>--> <!-- </appender>--> <!-- debugAppender 控制台输出日志 end --> <!--日志发送到logstash=>elasticSearch=>kibana start--> <!--<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">--> <!--<destination>localhost:9601</destination>--> <!--<queueSize>1048576</queueSize>--> <!--<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" />--> <!--</appender>--> <!--<logger name="kibanaLog" level="DEBUG" additivity="false">--> <!--<appender-ref ref="LOGSTASH"/>--> <!--</logger>--> <!--日志发送到logstash=>elasticSearch=>kibana end --> <!-- 1、控制台输出 --> <property name="CONSOLE_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%tid][%blue(%thread)][%cyan(%logger)] - %m%n"/> <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <Pattern>${CONSOLE_PATTERN}</Pattern> </layout> </encoder> </appender> <!-- 异步输出 --> <appender name="console-async" class="ch.qos.logback.classic.AsyncAppender"> <discardingThreshold>0</discardingThreshold> <queueSize>1024</queueSize> <neverBlock>true</neverBlock> <appender-ref ref="consoleLog"/> </appender> <!-- 2、使用gRpc将日志发送到Skywalking服务端 --> <!-- 日志输出格式 --> <property name="RPC_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [${appName}] %-5p [%tid] [%thread] %logger{36} - %m%n"/> <appender name="grpc-log" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender"> <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout"> <Pattern>${RPC_PATTERN}</Pattern> </layout> </encoder> </appender> <root> <!-- <level value="${log.level}"/>--> <!-- 控制台输出 --> <!-- <appender-ref ref="console"/>--> <!-- <appender-ref ref="consoleLog"/>--> <appender-ref ref="console-async" /> <appender-ref ref="grpc-log" /> <!-- 文件输出 --> <!-- <appender-ref ref="error"/>--> <!-- <appender-ref ref="warn"/>--> <!-- <appender-ref ref="info"/>--> <!-- <appender-ref ref="debug"/>--> </root> <!-- 文件不输出 --> <Logger name="org.springframework" level="ERROR"></Logger> <Logger name="org.hibernate" level="ERROR"></Logger> <Logger name="org.apache" level="ERROR"></Logger> <Logger name="com.netflix" level="ERROR"></Logger> <Logger name="ch.qos.logback" level="ERROR"></Logger> <Logger name="com.alibaba.cloud.nacos" level="INFO"></Logger> </configuration>
这样日志就会打印到SkyWalking中,不需要在输出到日志文件中