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

    非特殊字符解码正常

  • 相关阅读:
    最新 | 诺奖得主涉嫌论文造假
    带你深入了解Fragment懒加载
    ubuntu 系统 怎么判断系统有没有GPU
    正则表达式ReqExp
    【C++11】C++11新增语法特性 右值引用/移动语义/完美转发
    redis面试基础
    RK3588芯片介绍
    toPlainString()
    OAuth2.0和1.0的区别
    Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法
  • 原文地址:https://blog.csdn.net/qq_32783703/article/details/125413088