• 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、结论

    非特殊字符解码正常

  • 相关阅读:
    3.SpringSecurity基于数据库的认证与授权
    GNU和Linux的关系、 Linux的发行版本、CentOs和RedHat的区别
    阅读JavaScript文档-对象
    《用Go语言自制解释器》之第2章 语法分析
    管理系统搭建一般步骤(会话跟踪 路由导航守卫 响应拦截器)
    MySQL数据库期末考试试题及参考答案(04)
    PTE考试预览
    《canvas》之第7章 变形操作
    Could not create the Java virtual machine解决
    AIGC专栏6——通过阿里云与AutoDL快速拉起Stable Diffusion和EasyPhoto
  • 原文地址:https://blog.csdn.net/qq_32783703/article/details/125413088