github-actions[bot] commented on issue #13994: URL: https://github.com/apache/dolphinscheduler/issues/13994#issuecomment-1518925358
### 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 ``` You can hide content for different logs by customizing MessageConverter. First, you need to define an interface for hiding log content: public interface LogContentHider { String hide(String content); } Then, you can implement this interface to hide different log contents. For example, for mobile phone numbers, you can implement the following hiding methods: public class PhoneLogContentHider implements LogContentHider { @Override public String hide(String content) { return content.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); } } Next, you need to implement a custom MessageConverter and use LogContentHider to hide the log content. For example: 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; // other hidden methods } } } @Override public String convert(ILoggingEvent event) { String message = event. getFormattedMessage(); if (logContentHider != null) { message = logContentHider.hide(message); } return message; } } Finally, configure a custom MessageConverter in logback.xml: <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> In this way, you can hide different content by specifying different options during log output. For example: logger.info("Mobile phone number: 13812345678", "phone"); The output log content will be: 12:34:56.789 [main] INFO com.example.MyClass - Mobile Number: 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]
