Logtail配置是Logtail进行日志采集的策略集合,包括日志文件的位置、采集方式和参数等。本文档为您介绍API方式采集数据时的Logtail配置。

Lotail配置参数

Lotail配置参数如下所示:
参数 类型 是否必须 描述
configName string Logtail配置名称,同一Project下配置名必须唯一。
  • 只能包括小写字母、数字、连字符(-)和下划线(_)。
  • 必须以小写字母或者数字开头和结尾。
  • 长度必须为2~128字节。
logSample string 日志样例。
inputType string 配置类型,支持plugin、file。
inputDetail object 输入类型配置。
outputType string 输出类型,目前只支持LogService。
outputDetail object 输出类型配置。
createTime int32 Logtail配置创建时间。服务端返回参数,不支持设置。
lastModifyTime int32 Logtail配置最后一次修改时间。服务端返回参数,不支持设置。
inputDetail和outputDetail参数的配置如下所示:
  • inputDetail参数
    • 基础配置
      属性 类型 是否必须 描述
      filterKey array 用于过滤日志的key,只有key的值满足对应filterRegex列中设定的正则表达式,该日志数据才会被采集。
      filterRegex array 与filterKey对应的正则表达式,filterRegex的长度和filterKey的长度必须相同。
      shardHashKey array 数据写入的模式。默认按照负载均衡模式写入,开启后按照ShardHashKey模式写入。支持的值包括__topic__、__hostname__、__source__。
      enableRawLog bool 是否上传原始日志。
      sensitive_keys array 脱敏功能配置,类型为数组,该参数详细介绍请参见下述表格。
      mergeType string 聚合方式,默认为topic,表示按照Topic方式聚合。支持的值为topic、logstore。
      delayAlarmBytes int 采集进度落后的告警阈值,默认为209715200,即200 MB。
      adjustTimezone bool 是否调整日志时区,仅在配置时间解析的情况下使用。
      logTimezone string 时区偏移量,例如日志时间为东八区,则该值为GMT+08:00。
      priority int 日志发送优先级,默认为0,若需设置为高优先级,则设置为1。
      其中sensitive_keys参数的配置如下。
      • 参数配置
        属性 类型 是否必须 描述
        key string 日志Key名称。
        type string 脱敏方式,取值为const、md5。
        • 若取值为const,则将敏感内容替换成const字段取值内容。
        • 若取值为md5,则将敏感内容替换为其对应的MD5值。
        regex_begin string 敏感内容的前缀。
        regex_content string 敏感内容正则表达式。
        all bool 是否替换该字段中所有的敏感内容。建议设置为true。
        const string 当type设置为const时必须填写。
      • 配置示例
        假设日志中存在字段content,内容为[{'account':'1812213231432969','password':'04a23f38'}, {'account':'1812213685634','password':'123a'}],现在需要将其中的password部分脱敏,则sensitive_keys配置为:
        "key" : "content"
        "type" : "const"
        "regex_begin" : "'password':'"
        "regex_content" : "[^']*"
        "all" : true
        "const" : "********"
        												
        脱敏后的日志内容为:
        [{'account':'1812213231432969','password':'********'}, {'account':'1812213685634','password':'********'}]
    • 文本类型配置
      • 基础配置
        属性 类型 是否必须 描述
        logType string 日志的采集模式。如果Logtail配置参数inputType选择为file,则该参数为必填项。目前可选:
        • json_log:JSON模式。
        • apsara_log:飞天模式。
        • common_reg_log:完整正则模式。
        • delimiter_log:分隔符模式。
        logPath string 日志文件所在的父目录,例如/var/logs/
        filePattern string 日志文件的Pattern,例如access*.log
        topicFormat string Topic生成方式,支持以下四种类型:
        • none,表示topic为空。
        • default,表示将日志文件路径作为topic。
        • group_topic,表示将应用该配置的机器组topic属性作为topic。
        • 也可以将日志文件路径的某一部分作为topic,如/var/log/(.*).log
        timeFormat string 日志时间格式,如%Y/%m/%d%H:%M:%S
        preserve bool 监控目录超时设置。默认为true,代表监控目录永不超时,false代表监控目录超过30分钟则超时。
        preserveDepth integer 当设置preserve为false时,指定监控不超时目录的深度,最大深度支持3。
        fileEncoding string 支持两种类型:utf8gbk
        discardUnmatch bool 是否丢弃匹配失败的日志。
        maxDepth int 最大目录监控深度范围:0~1000,0代表只监控本层目录。
        delaySkipBytes int 采集落后时是否丢弃落后数据的阈值,默认为0,即不丢弃。当采集落后超过该值时,则直接丢弃落后的数据。
        dockerFile bool 采集的目标文件是否为容器内文件,默认为false。
        dockerIncludeLabel object 容器Label白名单,采集包含白名单中Label的Docker容器日志,为空表示全部采集。
        dockerExcludeLabel object 容器Label黑名单,不采集包含黑名单中Label的Docker容器日志,为空表示全部采集。
        dockerIncludeEnv object 容器环境变量白名单,采集包含白名单中的环境变量的日志,为空表示全部采集。
        dockerExcludeEnv object 容器环境变量黑名单,采集不包含黑名单中的环境变量的日志,为空表示全部采集。
      • 完整正则和极简模式特有配置
        属性 类型 是否必须 描述
        key array 日志内容提取结果的key列表。
        logBeginRegex string 行首正则表达式。
        regex string 提取字段的正则表达式。
        说明 极简模式是完整正则模式的一个特例,配置示例如下。
        "key" : ["content"]
        "logBeginRegex" : ".*"
        "regex" : "(.*)"
      • JSON模式特有配置
        属性 类型 是否必须 描述
        timeKey string 指定时间字段的key名称。
      • 分隔符模式特有配置
        属性 类型 是否必须 描述
        separator string 分隔符。
        quote string 引用符。
        key array 日志内容提取结果的key列表。
        timeKey string 指定时间字段key名称,必须在key列表里面。
        autoExtend bool 当日志中实际的key数量大于配置的key数量时,是否自动扩展。
      • 飞天模式特有配置
        属性 类型 是否必须 描述
        logBeginRegex string 行首正则表达式。
    • 插件配置
      下表为inputDetail插件模式特有的配置。
      属性 类型 是否必须 描述
      plugin object 插件所需JSON对象,具体请参见自定义插件
  • outputDetail参数
    用于配置日志输出的Project和Logstore。
    属性 类型 是否必须 描述
    projectName string 项目名称,必须为请求的project名。
    logstoreName string 日志库名称。

Logtail配置示例

  • JSON模式配置示例
    {
        "configName": "logConfigName", 
        "outputType": "LogService", 
        "inputType": "file", 
        "inputDetail": {
            "logPath": "/logPath", 
            "filePattern": "access.log", 
            "logType": "json_log", 
            "topicFormat": "default", 
            "discardUnmatch": false, 
            "enableRawLog": true, 
            "fileEncoding": "gbk", 
            "maxDepth": 10
        }, 
        "outputDetail": {
            "projectName": "test-project", 
            "logstoreName": "test-logstore"
        }
    }
  • 分隔符模式配置示例
    {
        "configName": "logConfigName", 
        "logSample": "testlog", 
        "inputType": "file", 
        "outputType": "LogService", 
        "inputDetail": {
            "logPath": "/logPath", 
            "filePattern": "*", 
            "logType": "delimiter_log", 
            "topicFormat": "default", 
            "discardUnmatch": true, 
            "enableRawLog": true, 
            "fileEncoding": "utf8", 
            "maxDepth": 999, 
            "separator": ",", 
            "quote": "\"", 
            "key": [
                "test", 
                "test2"
            ], 
            "autoExtend": true
        }, 
        "outputDetail": {
            "projectName": "test-project", 
            "logstoreName": "test-logstore"
        }
    }
  • 完整正则模式配置示例
    {
        "configName": "logConfigName", 
        "outputType": "LogService", 
        "inputType": "file", 
        "inputDetail": {
            "logPath": "/logPath", 
            "filePattern": "*", 
            "logType": "common_reg_log", 
            "topicFormat": "default", 
            "discardUnmatch": false, 
            "enableRawLog": true, 
            "fileEncoding": "utf8", 
            "maxDepth": 10, 
            "key": [
                "content"
            ], 
            "logBeginRegex": ".*", 
            "regex": "(.*)"
        }, 
        "outputDetail": {
            "projectName": "test-project", 
            "logstoreName": "test-logstore"
        }
    }
  • Plugin插件模式(docker标准输出类型)配置示例
    {
        "configName": "logConfigName", 
        "outputType": "LogService", 
        "inputType": "plugin",
        "inputDetail": {
            "plugin": {
                "inputs": [
                    {
                        "detail": {
                            "ExcludeEnv": null, 
                            "ExcludeLabel": null, 
                            "IncludeEnv": null, 
                            "IncludeLabel": null, 
                            "Stderr": true, 
                            "Stdout": true
                        }, 
                        "type": "service_docker_stdout"
                    }
                ]
            }
        }, 
        "outputDetail": {
            "projectName": "test-project", 
            "logstoreName": "test-logstore"
        }
    }