【问题标题】:How to remove unicode in fluentd tail/s3 plugin如何在 fluentd tail/s3 插件中删除 unicode
【发布时间】:2021-07-10 03:11:24
【问题描述】:

我有 fluentd 配置,源为尾部类型,目标为 aws s3。 我可以将日志存储在 S3 中。

我们已根据 winston 记录器中的日志级别在应用程序日志中启用着色,但在存储在 S3 中时,我得到了颜色的 unicode 值,例如 \u001b[34mdebug\u001b[ 39米。特殊字符也会发生同样的情况(\u003c for >)

Fluentd Config
--------------
    <source>
      @type tail
      path /var/log/containers/abc-*.log
      pos_file /var/log/abc.log.pos
      tag abc.**
      <parse>
        @type none
      </parse>
      read_from_head true
    </source>
    
    <match abc.**>
       @type s3
    
       aws_key_id "#{ENV['AWS_ACCESS_KEY']}"
       aws_sec_key "#{ENV['AWS_SECRET_ACCESS_KEY']}"
       s3_bucket "#{ENV['S3_LOGS_BUCKET_NAME']}"
       s3_region "#{ENV['S3_LOGS_BUCKET_REGION']}"
       path "#{ENV['S3_LOGS_BUCKET_PREFIX']}"
       s3_object_key_format %{path}/abc/%Y%m%d/%{index}.json
    
       buffer_chunk_limit 20m
       buffer_path /var/log/fluentd-buffer
       store_as json
       flush_interval 600s
       time_slice_format %Y/%m/%d
       utc
    
       <format>
          @type single_value
       </format>
    
       <instance_profile_credentials>
         ip_address 169.254.169.254
         port       80
       </instance_profile_credentials>
    </match>

存储在 S3 中的当前日志:

{"log":"2021-04-10T12:34:51.050Z - \u001b[34mdebug\u001b[39m: \u003e\u003e\u003e\u003e testlog1 from app \n","stream":"stdout","time":"2021-04-10T12:34:51.050571552Z"}
{"log":"2021-04-10T12:34:51.067Z - \u001b[34mdebug\u001b[39m: \u003c\u003c\u003c\u003c testlog2 from app\n","stream":"stdout","time":"2021-04-10T12:34:51.068105637Z"}

预期

{"log":"2021-04-10T12:34:51.050Z - debug: <<<< exec start from app \n","stream":"stdout","time":"2021-04-10T12:34:51.050571552Z"}
{"log":"2021-04-10T12:34:51.067Z - debug: <<<< exec end from app\n","stream":"stdout","time":"2021-04-10T12:34:51.068105637Z"}

需要有关如何打印原始值的帮助。

【问题讨论】:

    标签: amazon-web-services amazon-s3 fluent fluentd winston


    【解决方案1】:

    试试像这样的流利的record_transformer过滤插件:

    <filter abc.**>
      @type record_transformer
      enable_ruby true
      <record>
        message ${ record["message"].gsub(/(\\u\d+b\[\d+m)|(\\u\d+e)/, '') }
      </record>
    </filter>
    

    【讨论】:

    • 你测试了吗?
    • @ChenA.:是的,它已针对上述用例进行了测试。如果您的用例相似,您可以在此基础上进行扩展。
    • 我的用例是删除/过滤带有非 ascii 字符的事件。我用排除过滤器的 grep 出去了
    • @ChenA.:对。这也应该有效。 ?
    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    相关资源
    最近更新 更多