fuchanghai opened a new issue, #13994:
URL: https://github.com/apache/dolphinscheduler/issues/13994

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/dolphinscheduler/issues?q=is%3Aissue) and 
found no similar feature requirement.
   
   
   ### Description
   
   
   If I want to use different rules for different tasks, the following is the 
answer chatGPT gave me, I'm going to try to do it.any one have any other or 
better ideas? @EricGao888 @rickchengx @caishunfeng @ruanwenjun @SbloodyS 
   ```
   
   你可以通过自定义MessageConverter来实现针对不同日志的内容隐藏。
   
   首先,你需要定义一个接口,用于隐藏日志内容:
   
   public interface LogContentHider {
       String hide(String content);
   }
   然后,你可以实现该接口,针对不同的日志内容进行隐藏。例如,对于手机号码,你可以实现如下的隐藏方式:
   
   public class PhoneLogContentHider implements LogContentHider {
       @Override
       public String hide(String content) {
           return content.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
       }
   }
   接下来,你需要实现自定义的MessageConverter,使用LogContentHider来隐藏日志内容。例如:
   
   public class CustomMessageConverter extends ClassicConverter {
       private LogContentHider logContentHider;
   
       @Override
       public void start() {
           String option = getFirstOption();
           if (option != null) {
               switch (option) {
                   case "phone":
                       logContentHider = new PhoneLogContentHider();
                       break;
                   // 其他隐藏方式
               }
           }
       }
   
       @Override
       public String convert(ILoggingEvent event) {
           String message = event.getFormattedMessage();
           if (logContentHider != null) {
               message = logContentHider.hide(message);
           }
           return message;
       }
   }
   最后,在logback.xml中配置自定义的MessageConverter:
   
   <configuration>
       <conversionRule conversionWord="custom" 
converterClass="com.example.CustomMessageConverter" />
       <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
           <encoder>
               <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - 
%custom{phone}%n</pattern>
           </encoder>
       </appender>
       <root level="debug">
           <appender-ref ref="console" />
       </root>
   </configuration>
   这样,你就可以在日志输出时,通过指定不同的option来隐藏不同的内容了。例如:
   
   logger.info("手机号码:13812345678", "phone");
   输出的日志内容将会是:
   
   12:34:56.789 [main] INFO  com.example.MyClass - 手机号码:138
   
   
   ```
   
   ### Use case
   
   _No response_
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to