跳到主要内容

fluent

简介

Logger for Fluentd/Fluent Bit

接入方式

  1. Fluentd守护进程必须监听一个TCP端口用于日志转发;为了便于测试,这里添加了一个记录到标准输出的匹配器。
# fluentd.conf

<source>
type forward
port 24224
</source>

<match fluentd.test.**>
type stdout
</match>
  1. 启动Fluentd守护进程。
fluentd -c fluentd.conf
  1. 参考样例接入pkg.fluent,可以看到Fluentd控制台输出内容。
2024-08-28 02:15:38.000000000 -0400 fluentd.test.follow: {"from":"userA","to":"userB"}
  1. 通过配置,可以将日志记录到各种存储媒介。

组件接口

fluent.gs

函数原型函数作用
object create_logger(string tag_prefix, string host, int port)创建FluentLogger对象

FluentLogger.gs

函数原型函数作用
bool log(string label, map data)记录日志

样例

public void sample()
{
string host = get_sys_env("FLUENTD_HOST");

// 创建logger对象
object logger = fluent.create_logger("fluentd.test", host, 24224);

// 记录日志
logger.log("follow", {
"from": "userA",
"to": "userB",
});
}