skywalking agent配置日志到本地

1.引言

  SkyWalking Agent 提供了内置的日志功能,用于记录运行过程中的信息、调试信息和错误信息。由于日志采集是通过直接读取本地日志文件的方式,因此需要将日志配置为写入本地文件。由于这里使用的是k8s

 

2.配置K8S

2.1 配置文件位置

  在 SkyWalking Agent 中,日志的配置项通常位于 skywalking-agent/config/application.yml 配置文件中。该文件用于配置 SkyWalking Agent 的各类设置,包括日志级别、日志输出格式以及日志输出位置等。

  重要配置文件位置:

skywalking/config/agent.config

  这里进入k8s pod查看配置文件

[root@iZuf61d4l1loivrfalojzkZ ~]# kubectl -n debug exec -ti iot-device-things-7bdc79dcb7-ln588 -- /bin/bash
Defaulted container "iot-device-things" out of: iot-device-things, skywalking-agent (init)
bash-4.4# cd /skywalking/agent/config/
bash-4.4# ls
agent.config

  查看配置文件样例(比如这里暂时日志模块)

# Logging level
logging.level=${SW_LOGGING_LEVEL:INFO}
# Logging file_name
logging.file_name=${SW_LOGGING_FILE_NAME:skywalking-api.log}
# Log output. Default is FILE. Use CONSOLE means output to stdout.
logging.output=${SW_LOGGING_OUTPUT:FILE}
# Log files directory. Default is blank string, meaning use "{theSkywalkingAgentJarDir}/logs " to output logs.
# {theSkywalkingAgentJarDir} is the directory where the skywalking agent jar file is located
logging.dir=${SW_LOGGING_DIR:}
# Logger resolver: PATTERN or JSON. The default is PATTERN, which uses logging.pattern to print traditional text logs.
# JSON resolver prints logs in JSON format.
logging.resolver=${SW_LOGGING_RESOLVER:PATTERN}
# Logging format. There are all conversion specifiers:
#  * %level means log level.
#  * %timestamp means now of time with format yyyy-MM-dd HH:mm:ss:SSS.
#  * %thread means name of current thread.
#  * %msg means some message which user logged.
#  * %class means SimpleName of TargetClass.
#  * %throwable means a throwable which user called.
#  * %agent_name means agent.service_name. Only apply to the PatternLogger.
logging.pattern=${SW_LOGGING_PATTERN:%level %timestamp %thread %class : %msg %throwable}
# Logging max_file_size, default: 300 * 1024 * 1024 = 314572800
logging.max_file_size=${SW_LOGGING_MAX_FILE_SIZE:314572800}
# The max history log files. When rollover happened, if log files exceed this number,
# then the oldest file will be delete. Negative or zero means off, by default.
logging.max_history_files=${SW_LOGGING_MAX_HISTORY_FILES:-1}

 

2.2 K8S pod配置skywalking本地日志方式

  在 Kubernetes 中运行 SkyWalking Agent 并使用 K8sEnv 方式进行配置时,我们这里通过环境变量的方式配置日志输出

env:
- name: JAVA_OPTS
  value: "-javaagent:/skywalking/agent/skywalking-agent.jar -Dskywalking.logging.file_name=skywalking-agent.log  -Dskywalking.logging.output=FILE -Dskywalking.logging.dir=/opt/logs -Dskywalking.logging.resolver=JSON -Dskywalking.agent.service_name=${PROJECT_NAME}-${RUNTIME} -Dskywalking.collector.backend_service=skywalking-oap.skywalking.svc.cluster.local:11800"

  以上Dskywaling开头的全是skywaling的配置,但是配置怎么来,就在上述agent.config文件中,

  具体格式如下

-Dskywalking.agent.service_name=

  按照以上方式进行配置即可完成 SkyWalking Agent 的日志输出设置。

 

posted @ 2025-03-14 17:45  小家电维修  阅读(248)  评论(0)    收藏  举报