在Logback XML中屏蔽动态文件名的日志输出值 [英] Masking Log Output Value for Dynamic File Name in Logback XML

查看:326
本文介绍了在Logback XML中屏蔽动态文件名的日志输出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在日志输出中需要屏蔽一个值,该值用于为我的Jenkins作业生成黄瓜报告.似乎唯一可行的方法是修改存储库的logback.xml文件.

I have a value I need masked in log output that is used to generate the Cucumber Reports for my Jenkins jobs. The only way this seems to be possible is modifying the logback.xml file for the repo.

我尝试过:

<appender name="REPORT" class="ch.qos.logback.core.FileAppender">
    <immediateFlush>false</immediateFlush>
    <file>target/surefire-reports/*.html</file>
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %replace(%msg){'(?&lt;=api-key:).*', 'xxxx'}%n</pattern>
    </encoder>
</appender>

但是我得到了不正确的文件名错误:

But I get an incorrect filename error:

16:58:44,485 |-ERROR in ch.qos.logback.core.FileAppender[REPORT] - openFile(target/surefire-reports/*.html,true) call failed. java.io.FileNotFoundException: target\surefire-reports\*.html (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileNotFoundException: target\surefire-reports\*.html (The filename, directory name, or volume label syntax is incorrect)

推荐答案

当然,只要我问了一下,我就知道了...

And of course as soon as I ask, I figure it out...

<pattern>%-5level - %replace(%msg){'(?&lt;=api-key:).*', 'xxxx'}%n</pattern>

输出: 1 > api-key:xxxx

从logback文档中获得了格式: https://logback.qos.ch/manual/layouts.html#cwOptions <pattern>%-5level - %replace(%msg){'\d{14,16}', 'XXXX'}%n</pattern>

Got the format from logback documentation: https://logback.qos.ch/manual/layouts.html#cwOptions <pattern>%-5level - %replace(%msg){'\d{14,16}', 'XXXX'}%n</pattern>

正则表达式是我用来掩盖Jenkins日志输出的正则表达式,由于它位于xml文件中,所以用html &lt;代替了左尖括号.

And the regex is the one I'm using to mask Jenkins log output, replacing the left angle bracket with html &lt; due to it being in an xml file.

这篇关于在Logback XML中屏蔽动态文件名的日志输出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆