You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "fuchanghai (via GitHub)" <gi...@apache.org> on 2023/04/23 02:43:35 UTC

[GitHub] [dolphinscheduler] fuchanghai opened a new issue, #13994: [Feature][Log] Different tasks should not share the same log hiding strategy

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: commits-unsubscribe@dolphinscheduler.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [dolphinscheduler] github-actions[bot] commented on issue #13994: [Feature][Log] Different tasks should not share the same log hiding strategy

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [dolphinscheduler] github-actions[bot] commented on issue #13994: [Feature][Log] Different tasks should not share the same log hiding strategy

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #13994:
URL: https://github.com/apache/dolphinscheduler/issues/13994#issuecomment-1518925391

   Thank you for your feedback, we have received your issue, Please wait patiently for a reply.
   * In order for us to understand your request as soon as possible, please provide detailed information, version or pictures.
   * If you haven't received a reply for a long time, you can [join our slack](https://s.apache.org/dolphinscheduler-slack) and send your question to channel `#troubleshooting`


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [dolphinscheduler] fuchanghai closed issue #13994: [Feature][Log] Different tasks should not share the same log hiding strategy

Posted by "fuchanghai (via GitHub)" <gi...@apache.org>.
fuchanghai closed issue #13994: [Feature][Log] Different tasks should not share the same log hiding strategy
URL: https://github.com/apache/dolphinscheduler/issues/13994


-- 
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: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org