日志

artifacthub-shim 使用 zap 生成结构化进程日志。默认的 chart 配置会在 info 级别将 JSON 日志写入 stdout,这适用于 Kubernetes 日志收集。

配置级别和格式

在常见场景中,使用 logging.levellogging.format

logging:
  level: debug
  format: json

支持的级别有 debuginfowarnerror。支持的格式有 jsonconsole

该 chart 会将这些值渲染为:

Environment variableDescription
ARTIFACTHUB_SHIM_LOG_LEVEL在未使用配置文件时的最低启用日志级别。
ARTIFACTHUB_SHIM_LOG_FORMAT在未使用配置文件时的日志编码器格式。

在诊断仓库刷新、索引或 API 请求行为时,可临时使用 debug。调查结束后请恢复为 info,因为按来源和请求级别的 debug 日志可能会非常冗长。

使用 zap 配置文件

对于更高级的日志需求,请提供一个符合 zap.Config 结构的 YAML 或 JSON 文件。当设置了 ARTIFACTHUB_SHIM_LOG_CONFIG_FILE 时,进程会在启动期间读取该文件,并忽略 ARTIFACTHUB_SHIM_LOG_LEVELARTIFACTHUB_SHIM_LOG_FORMAT

该 chart 可以从 logging.config 渲染该文件:

logging:
  config:
    level: debug
    encoding: console
    outputPaths:
      - stdout
    errorOutputPaths:
      - stderr
    disableCaller: false
    disableStacktrace: true
    encoderConfig:
      messageKey: message
      levelKey: level
      timeKey: ts
      callerKey: caller
      levelEncoder: lowercase
      timeEncoder: iso8601
      durationEncoder: string
      callerEncoder: short

这会创建一个 ConfigMap,并将其挂载到 /etc/artifacthub-shim/logging.yaml。进程接收的环境变量为 ARTIFACTHUB_SHIM_LOG_CONFIG_FILE=/etc/artifacthub-shim/logging.yaml

你也可以挂载自己的文件,并让 chart 指向它:

logging:
  configFile: /etc/custom-artifacthub-shim/logging.yaml

extraVolumes:
  - name: custom-logging
    configMap:
      name: artifacthub-shim-custom-logging

extraVolumeMounts:
  - name: custom-logging
    mountPath: /etc/custom-artifacthub-shim/logging.yaml
    subPath: logging.yaml
    readOnly: true

不要同时设置 logging.configlogging.configFile

应用更改

日志记录器仅在进程启动期间读取基于文件的配置。更改 logging.levellogging.formatlogging.config 或自定义挂载的配置文件后,请重启 deployment 或执行 rollout restart:

kubectl rollout restart deployment artifacthub-shim -n artifacthub-shim-system

敏感数据

该服务不会记录请求正文、Kubernetes Secrets、bearer token 或 Authorization headers。包含用户信息的 Git URLs 会在返回到日志或源状态消息之前进行脱敏。