• loggie 编码以及换行符测试


    一、测试非编码单行换行符

    1、测试场景

    \r\n测试

    pipeline配置文件:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: carriage_return_line_feed
    8. value: "\r\n"
    9. charset: utf-8
    10. paths:
    11. - /home/zhanglei/*.log
    12. fields:
    13. topic: "loggie"
    14. interceptors:
    15. - type: iconv
    16. charset: "utf-8"
    17. sink:
    18. type: dev
    19. printEvents: true
    20. codec:
    21. pretty: true

    2、测试脚本

    1. <?php
    2. $a = "1ddsjaodjasiodjasoidjasoidjasid段晒苏杭怠速后端三十u的\r\n";
    3. file_put_contents("a.log", $a, FILE_APPEND);
    4. var_dump("1ddsjaodjasiodjasoidjasoidjasid段晒苏杭怠速后端三十u的");

    3、测试结果

    输出正常

    二、测试编码单行换行符

    1、测试场景

    gbk 编码

    \r\n测试

    pipeline配置文件:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: carriage_return_line_feed
    8. value: "\r\n"
    9. charset: gbk
    10. paths:
    11. - /home/zhanglei/*.log
    12. fields:
    13. topic: "loggie"
    14. interceptors:
    15. - type: iconv
    16. charset: "gbk"
    17. sink:
    18. type: dev
    19. printEvents: true
    20. codec:
    21. pretty: true

    2.测试脚本

    1. <?php
    2. $a = iconv("utf-8", "gbk", "哈哈哈顿巴斯涉及到八级大把货都不花钱我闻不到几千万望
    3. 变电气文件变动祭敖包\r\n");
    4. file_put_contents("a.log", $a, FILE_APPEND);
    5. var_dump($a);

    3.测试结果

    三、测试非编码 auto 换行符

    1、测试场景

    \n测试

    pipeline配置文件:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: auto
    8. paths:
    9. - /home/zhanglei/*.log
    10. fields:
    11. topic: "loggie"
    12. interceptors:
    13. - type: iconv
    14. sink:
    15. type: dev
    16. printEvents: true
    17. codec:
    18. pretty: true

    2.测试脚本

    1. <?php
    2. $a = "1ddsjaodjasiodjasoidjasoidjasid段晒苏杭怠速后端三十u的\r\n";
    3. file_put_contents("b.log", $a, FILE_APPEND);
    4. var_dump($a);

    3.测试结果

     四、测试编码 auto 换行符

    1、测试场景

    gbk 编码

    \n测试

    pipeline配置文件:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: auto
    8. value: "\r\n"
    9. charset: gbk
    10. paths:
    11. - /home/zhanglei/*.log
    12. fields:
    13. topic: "loggie"
    14. interceptors:
    15. - type: iconv
    16. charset: "gbk"
    17. sink:
    18. type: dev
    19. printEvents: true
    20. codec:
    21. pretty: true

    2.测试脚本

    1. <?php
    2. $a = iconv("utf-8", "gbk", "哈哈哈顿巴斯涉及到八级大把货都不花钱我闻不到几千万望
    3. 变电气文件变动祭敖包\r\n");
    4. file_put_contents("a.log", $a, FILE_APPEND);
    5. var_dump($a);

    3.测试结果

    五、测试非编码自定义换行符(特殊字符)

    1、测试场景

    pipeline:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: custome
    8. value: "\r\n"
    9. paths:
    10. - /home/zhanglei/*.log
    11. fields:
    12. topic: "loggie"
    13. interceptors:
    14. - type: iconv
    15. sink:
    16. type: dev
    17. printEvents: true
    18. codec:
    19. pretty: true

    2、测试结果

    3、结论

    custom 配置不能解决 特殊ascii码问题 

    特殊字符使用

    1. lineTerminators = map[string]LineTerminator{
    2. "auto": AutoLineTerminator,
    3. "line_feed": LineFeed,
    4. "vertical_tab": VerticalTab,
    5. "form_feed": FormFeed,
    6. "carriage_return": CarriageReturn,
    7. "carriage_return_line_feed": CarriageReturnLineFeed,
    8. "next_line": NextLine,
    9. "line_separator": LineSeparator,
    10. "paragraph_separator": ParagraphSeparator,
    11. "null_terminator": NullTerminator,
    12. }

    六、测试非编码自定义换行符(非特殊字符)

    1、测试场景

    pipeline:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: custom
    8. value: "的"
    9. paths:
    10. - /home/zhanglei/*.log
    11. fields:
    12. topic: "loggie"
    13. interceptors:
    14. - type: iconv
    15. sink:
    16. type: dev
    17. printEvents: true
    18. codec:
    19. pretty: true

    2、测试结果

    3、结论

    正常

     七、测试编码自定义换行符(特殊字符)

    1、测试场景

    pipeline:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: custom
    8. value: "\r\n"
    9. charset: gbk
    10. paths:
    11. - /home/zhanglei/*.log
    12. fields:
    13. topic: "loggie"
    14. interceptors:
    15. - type: iconv
    16. charset: gbk
    17. sink:
    18. type: dev
    19. printEvents: true
    20. codec:
    21. pretty: true

    2、测试结果

    3、结论

    custom 配置不能解决 特殊ascii码问题 

    但是可见字符都是正常的,如果出现不可见字符请使用

    1. lineTerminators = map[string]LineTerminator{
    2. "auto": AutoLineTerminator,
    3. "line_feed": LineFeed,
    4. "vertical_tab": VerticalTab,
    5. "form_feed": FormFeed,
    6. "carriage_return": CarriageReturn,
    7. "carriage_return_line_feed": CarriageReturnLineFeed,
    8. "next_line": NextLine,
    9. "line_separator": LineSeparator,
    10. "paragraph_separator": ParagraphSeparator,
    11. "null_terminator": NullTerminator,
    12. }

    解码后出现bug

     八、测试编码自定义换行符(非特殊字符)

    1、测试场景

    pipeline:

    1. pipelines:
    2. - name: local
    3. sources:
    4. - type: file
    5. name: demo
    6. lineEnd:
    7. type: custom
    8. value: "\r\n"
    9. charset: gbk
    10. paths:
    11. - /home/zhanglei/*.log
    12. fields:
    13. topic: "loggie"
    14. interceptors:
    15. - type: iconv
    16. charset: gbk
    17. sink:
    18. type: dev
    19. printEvents: true
    20. codec:
    21. pretty: true

    2、测试结果

    3、结论

    非特殊字符解码正常

  • 相关阅读:
    后端的add接口,能收到postman发来的请求,但是接收不到数据
    Hyperledge Fabric-身份与角色认证
    【RabbitMQ】消息队列需要解决的几个问题
    2023双11笔记本电脑候选名单(截止2023.10.13的价格,双十一活动可能会更便宜一点)
    react实战 系列 —— React 的数据流和生命周期
    Redis系列4:高可用之Sentinel(哨兵模式)
    无人机培训机构所需资质证书详解
    VNC viewer在windows与linux之间文本和文件拷贝
    Greenplum数据库数据分片策略Hash分布——GUC gp_use_legacy_hashops
    java swing 设计心得--窗体和面板
  • 原文地址:https://blog.csdn.net/qq_32783703/article/details/125413088