Skip to content

日志流(Log streaming)#

功能可用性

日志流功能适用于所有企业计划。

日志流功能允许你将事件从 n8n 发送到你自己的日志工具。这使你可以在自己的报警和日志管理流程中管理 n8n 的监控。

🌐 Log streaming allows you to send events from n8n to your own logging tools. This allows you to manage your n8n monitoring in your own alerting and logging processes.

设置日志流(Set up log streaming)#

要使用日志流,你必须添加一个流目标。

🌐 To use log streaming, you have to add a streaming destination.

  1. 导航到 设置 > 日志流
  2. 选择 添加新目的地
  3. 选择你的目标类型。n8n 会打开新事件目标模态窗口。
  4. 新建事件目的地 弹窗中,输入事件目的地的配置信息。这些信息取决于你所使用的目的地类型。
  5. 选择 事件 来选择要播放的事件。
  6. 选择 保存

自托管用户

如果你自托管 n8n,你可以使用环境变量配置额外的日志流行为。你还可以从环境变量管理目标,参见使用环境变量配置日志流目标

每个进程的事件日志文件(Per-process event log files)#

n8n 会在将每个发出的事件转发到流式目标之前,将其保存在本地日志文件中。该文件可以在重启后依然存在,并允许 n8n 重新发出尚未传递的事件。

🌐 n8n persists each emitted event to a local log file before forwarding it to streaming destinations. The file survives restarts and lets n8n re-emit events that weren't yet delivered.

默认情况下,n8n 会将事件日志写入 <n8n-user-folder>/n8nEventLog.log,这些进程上会有 -worker-webhook-processor 后缀。当单个 n8n 进程拥有该文件时,此默认设置可以按预期工作。

🌐 By default, n8n writes the event log to <n8n-user-folder>/n8nEventLog.log, with a -worker or -webhook-processor suffix on those processes. When a single n8n process owns the file, this default works as expected.

共享可写文件系统

如果多个 n8n 进程共享一个可写卷,例如由 NFS 或 EFS 上的共享持久卷支持的 队列模式 工作进程,它们不能写入同一个事件日志文件。多个进程的并发追加可能会交错或损坏文件,从而导致恢复失败和事件丢失。

为避免这种情况,请在每个进程上将 N8N_EVENTBUS_LOGWRITER_LOGFULLPATH 设置为以 .log 结尾的唯一绝对路径。n8n 会按原样使用配置的路径,不会附加进程类型后缀,因此你的编排器负责确保各进程之间的唯一性。

🌐 To avoid this, set N8N_EVENTBUS_LOGWRITER_LOGFULLPATH on each process to a unique absolute path that ends in .log. n8n uses the configured path verbatim and doesn't append a process-type suffix, so your orchestrator owns uniqueness across processes.

伴随变量 N8N_EVENTBUS_LOGWRITER_MAXTOTALMESSAGESPERFILE 限制了 n8n 在恢复过程中从单个事件日志文件解析的行数,因此损坏的文件无法耗尽进程内存。

🌐 The companion variable N8N_EVENTBUS_LOGWRITER_MAXTOTALMESSAGESPERFILE bounds how many lines n8n parses from a single event log file during recovery, so a corrupted file can't exhaust process memory.

备注:

🌐 Notes:

  • 当未设置 N8N_EVENTBUS_LOGWRITER_LOGFULLPATH 时,默认行为保持不变。
  • 当变量设置后,n8n 不会自动在路径上添加后缀。每个进程必须接收其自己的值。
  • 如果之前的部署中已经存在共享的 n8nEventLog-worker.log 文件,请在选择加入之前手动将其隔离。n8n 不会自动删除旧文件。

事件(Events)#

以下事件可用。你可以在 设置 > 日志流 > 事件 中选择要流式传输的事件。

🌐 The following events are available. You can choose which events to stream in Settings > Log Streaming > Events.

  • 工作流
    • 已开始
    • 成功
    • 失败
    • 已取消
  • 节点执行
    • 已开始
    • 完成
  • 审计
    • 用户登录成功
    • 用户登录失败
    • 已注册用户
    • 已更新用户
    • 已删除用户
    • 已邀请用户
    • 已接受用户邀请
    • 已重新邀请用户
    • 用户邮箱发送失败
    • 已请求重置用户
    • 已重置用户
    • 已创建用户凭据
    • 已共享用户凭据
    • 已更新用户凭据
    • 已删除用户凭据
    • 已创建用户 API
    • 已删除用户 API
    • 用户已启用多因素身份验证
    • 用户多因素认证已禁用
    • 用户执行已删除
    • 执行数据揭示
    • 执行数据揭示失败
    • 软件包已安装
    • 软件包已更新
    • 软件包已删除
    • 创建工作流
    • 删除工作流
    • 更新工作流
    • 工作流已归档
    • 工作流已取消归档
    • 工作流已激活
    • 工作流已停用
    • 工作流版本已更新
    • 工作流已执行
    • 工作流等待
    • 工作流已恢复
    • 变量已创建
    • 变量已更新
    • 变量已删除
    • 外部密钥提供者设置已保存
    • 外部秘密提供者已重新加载
    • 已创建外部密钥连接
    • 外部密钥连接已更新
    • 外部密钥连接已删除
    • 外部密钥连接已测试
    • 外部秘密连接已重新加载
    • 个人发布受限已启用
    • 个人发布受限已禁用
    • 已启用个人共享限制
    • 个人共享受限已禁用
    • 已启用双因素身份验证
    • 已禁用双因素身份验证
    • 令牌交换成功
    • 令牌交换失败
    • 令牌交换嵌入登录
    • 令牌交换嵌入登录失败
    • 令牌交换身份已关联
    • 令牌交换用户配置
    • 令牌交换角色已更新
    • 角色映射角色已解析
    • 角色映射规则已创建
    • 角色映射规则已更新
    • 角色映射规则已删除
    • 角色映射规则已批量删除
  • 工作者
    • 已开始
    • 停止
  • AI 节点日志
    • 内存获取消息
    • 内存添加消息
    • 输出解析器已解析
    • 检索器获取相关文档
    • 嵌入文档
    • 嵌入查询
    • 已处理文档
    • 文本分割器分割
    • 工具名称
    • 向量存储已搜索
    • LLM 已生成
    • 大型语言模型错误
    • 向量存储已填充
    • 向量存储已更新
  • 运行器
    • 任务已请求
    • 已收到响应
  • 队列
    • 任务已入队
    • 任务已出队
    • 任务已完成
    • 任务失败
    • 任务已停止

目标(Destinations)#

n8n 支持三种目标类型:

🌐 n8n supports three destination types:

  • A syslog 服务器
  • 通用 Webhook
  • Sentry 客户端

使用环境变量进行配置(Configure using environment variables)#

如果你自托管 n8n,你可以通过环境变量而不是 UI 来管理日志流目的地。从 n8n v2.19.0 开始提供。将 N8N_LOG_STREAMING_MANAGED_BY_ENV 设置为 true,并在 N8N_LOG_STREAMING_DESTINATIONS 中以 JSON 数组的形式提供你的目的地。n8n 每次启动时都会重新应用这些设置,并将 日志流 UI 锁定为只读。完整模式请参见 使用环境变量管理实例设置

🌐 If you self-host n8n, you can manage log streaming destinations from environment variables instead of the UI. Available from n8n v2.19.0. Set N8N_LOG_STREAMING_MANAGED_BY_ENV to true and provide your destinations as a JSON array in N8N_LOG_STREAMING_DESTINATIONS. n8n reapplies these on every startup and locks the Log Streaming UI as read-only. See Manage instance settings using environment variables for the full pattern.

Variable Type Default Description
N8N_LOG_STREAMING_MANAGED_BY_ENV Boolean false Set to true to manage log streaming from environment variables. When true, n8n applies the log streaming variables on every startup and locks the matching UI controls.
N8N_LOG_STREAMING_DESTINATIONS JSON string - JSON array of log streaming destinations. Each destination is an object with a type of webhook, syslog, or sentry, plus the configuration for that type.

常见字段(Common fields)#

每个目的地都接受这些字段,无论 type 如何。

🌐 Every destination accepts these fields, regardless of type.

类型 必修 描述
“type” “"webhook"” |'"syslog"' |“"sentry"” 是的 目的地类型。确定适用哪些类型特定的字段。
“label” 字符串 显示名称显示在界面中。
'enabled' 布尔值 目的地是否会推动事件。
'subscribedEvents' string[] 事件名称或组前缀转发(例如“n8n.audit”、“n8n.workflow”)。
“anonymizeAuditMessages” 布尔值 从“n8n.audit.*”事件中剥离敏感有效载荷数据。
“circuitBreaker” 对象 故障保护设置。参见[断路器](#circuit-breaker)。

Webhook#

字段 类型 必填 默认值 描述
url 字符串(URL) - 接收事件负载的端点。
“method” “"GET"” |'"POST"' |“"PUT"” “"POST"” HTTP 方法用于传输。
sendQuery 布尔值 false 是否发送查询参数。
specifyQuery "keypair" | "json" "keypair" sendQuerytrue 时的查询参数格式。
queryParameters { parameters: [{ name, value }] } - 查询参数作为键/值对使用。当 specifyQuery"keypair" 时使用。
jsonQuery 字符串 "" 查询参数,作为 JSON 字符串使用。当 specifyQuery"json" 时使用。
sendHeaders 布尔值 false 是否发送头信息。
specifyHeaders "keypair" | "json" "keypair" sendHeaderstrue 时标题的格式。
headerParameters { parameters: [{ name, value }] } - 以键/值对形式的头。当 specifyHeaders"keypair" 时使用。
jsonHeaders 字符串 "" 以 JSON 字符串形式的请求头。当 specifyHeaders"json" 时使用。
options 对象 {} 连接级选项。详见 Webhook 选项

Webhook 选项(Webhook options)#

字段 类型 必填 默认值 描述
allowUnauthorizedCerts 布尔值 false 忽略 SSL 证书验证。
“queryParameterArrays” “"repeat"” |'"brackets"' |“"indices"” “"brackets"” 查询参数中使用的数组格式。当“sendQuery”变为“true”时使用。
redirect { redirect: { followRedirects, maxRedirects } } { redirect: {} } 跟随 HTTP 重定向。followRedirects 默认值为 falsemaxRedirects 默认值为 21
proxy { proxy: { protocol, host, port } } { proxy: {} } HTTP/HTTPS 代理。protocol"https""http"host 默认为 "127.0.0.1"port 默认为 9000
timeout 整数 ≥ 1(毫秒) 5000 等待服务器开始响应的时间,超过则中止。
socket { keepAlive, maxSockets, maxFreeSockets } { keepAlive: true, maxSockets: 50, maxFreeSockets: 5 } 套接字池配置。maxSocketsmaxFreeSockets 是大于或等于 1 的整数。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
[
  {
    "type": "webhook",
    "label": "Audit",
    "subscribedEvents": ["n8n.audit", "n8n.workflow"],
    "anonymizeAuditMessages": true,
    "url": "https://hooks.example.com/n8n",
    "method": "POST",
    "sendHeaders": true,
    "specifyHeaders": "keypair",
    "headerParameters": {
      "parameters": [
        { "name": "Authorization", "value": "Bearer s3cret" }
      ]
    },
    "options": {
      "timeout": 5000,
      "redirect": { "redirect": { "followRedirects": true, "maxRedirects": 5 } }
    }
  }
]

系统日志(Syslog)#

类型 必修 默认 描述
“host” 字符串 是的 - Syslog服务器主机名或IP。
'port' 数字 '514' Syslog 服务器端口。
“protocol” “"udp"” |'"tcp"' |'"tls"' '"udp"' 运输协议。
“tlsCa” 字符串 当“protocol”变成“"tls"”时 “""” 用于TLS连接的PEM格式CA证书。
'facility' 数字 '16' Syslog 设施代码。允许的值有:'0'(内核)、'1'(用户)、'3'(系统)、'13'(审计)、'14'(警报)、'16'到'23'(local0到local7)。
“app_name” 字符串 '"n8n"' 该值用作syslog 'APP-NAME'。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[
  {
    "type": "syslog",
    "label": "SIEM",
    "subscribedEvents": ["n8n.audit", "n8n.workflow"],
    "host": "syslog.example.com",
    "port": 514,
    "protocol": "tls",
    "tlsCa": "-----BEGIN CERTIFICATE-----\n…\n-----END CERTIFICATE-----",
    "facility": 16,
    "app_name": "n8n"
  }
]

哨兵(Sentry)#

字段 类型 必填 默认值 描述
dsn 字符串(URL) - Sentry DSN 客户端密钥。
1
2
3
4
5
6
7
8
[
  {
    "type": "sentry",
    "label": "Sentry prod",
    "subscribedEvents": ["n8n.workflow"],
    "dsn": "https://public@sentry.example.com/1"
  }
]

断路器(Circuit breaker)#

断路器在多次失败后会暂时停止向目标的交付,防止对处于压力下的下游服务造成负载。适用于每种目标类型。

🌐 A circuit breaker temporarily stops delivery to a destination after repeated failures, preventing load on a struggling downstream service. Available on every destination type.

字段 类型 必填 默认值 描述
maxFailures 整数 ≥ 1 5 failureWindow 内的失败次数达到此数字时,n8n 停止向目标发送请求。
failureWindow 整数 ≥ 100 (毫秒) 60000 用于计算失败次数的滑动窗口。较早的失败会过期。
1
{ "circuitBreaker": { "maxFailures": 3, "failureWindow": 30000 } }

完整示例(Complete example)#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
N8N_LOG_STREAMING_MANAGED_BY_ENV=true
N8N_LOG_STREAMING_DESTINATIONS='[
  {
    "type": "webhook",
    "label": "Ops webhook",
    "enabled": true,
    "subscribedEvents": ["n8n.workflow", "n8n.audit"],
    "anonymizeAuditMessages": true,
    "url": "https://hooks.example.com/n8n",
    "method": "POST",
    "sendHeaders": true,
    "specifyHeaders": "keypair",
    "headerParameters": {
      "parameters": [
        { "name": "Authorization", "value": "Bearer s3cret" }
      ]
    },
    "circuitBreaker": { "maxFailures": 5, "failureWindow": 60000 }
  },
  {
    "type": "sentry",
    "label": "Sentry prod",
    "subscribedEvents": ["n8n.workflow"],
    "dsn": "https://public@sentry.example.com/1"
  }
]'