[ https://issues.apache.org/jira/browse/JAMES-2171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16716421#comment-16716421 ]
ASF GitHub Bot commented on JAMES-2171: --------------------------------------- Github user chibenwa commented on a diff in the pull request: https://github.com/apache/james-project/pull/145#discussion_r240499676 --- Diff: mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java --- @@ -52,18 +52,81 @@ * or mark it as finished. */ private final Logger logger; + private final LogLevel logLevel; private boolean passThrough = true; - private boolean headers = true; - private boolean body = true; - private int bodyMax = 0; - private String comment = null; + private boolean headers; + private boolean body; + private int bodyMax; + private String comment; + private List<String> specificHeaders; + private List<String> specificAttributes; + + private StringBuffer logBuffer = new StringBuffer(); + + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Logger logger; + private List<String> specificHeaders; + private List<String> specificAttributes; + private boolean headers; + private boolean body; + private LogLevel logLevel; + + private Builder(){ + logger = LOGGER; + specificHeaders = new LinkedList<>(); + specificAttributes = new LinkedList<>(); + body = false; + headers = false; + } + + public Builder logger(final Logger logger) { + this.logger = logger; + return this; + } + + public Builder logLevel(final LogLevel logLevel) { + this.logLevel = logLevel; + return this; + } + + public Builder specificHeaders(List<String> headers) { + this.specificHeaders.addAll(headers); + return this; + } + + public Builder specificAttributes(List<String> attributes) { + this.specificAttributes.addAll(attributes); + return this; + } + + public Builder hasHeaders(boolean headers) { + this.headers = headers; + return this; + } + + public Builder hasBody(boolean body) { + this.body = body; + return this; + } + + public LogMessage build(){ + return new LogMessage(logger,logLevel,specificHeaders,specificAttributes,headers,body); + } - public LogMessage(Logger logger) { - this.logger = logger; } - public LogMessage() { - this(LOGGER); + private LogMessage(Logger logger, LogLevel logLevel, List<String> specificHeaders, List<String> specificAttributes, boolean headers, boolean body){ --- End diff -- While having a builder is clearly valuable, James needs to be able to 'inject' fields in that mailet. So, we need to read the LogLevel, specificHeaders, specificAttributes headers & body parameters from the configuration, in the `init` method. > LogMessage mailet improvments > ----------------------------- > > Key: JAMES-2171 > URL: https://issues.apache.org/jira/browse/JAMES-2171 > Project: James Server > Issue Type: Improvement > Components: Mailet Contributions > Affects Versions: master > Reporter: Tellier Benoit > Priority: Major > Labels: easyfix, newbie > > Today, one can use the LogMessage to generate log messages upon mail reception > But the LogMessage have the following limits: > - It do not let you configure the warn level > - It does generate several logs. One would be simpler to review. > - It does add some unneeded informations, like mail name already carried by > the MDC > - It does not allow logging of specific headers or specific attributeNames. > This leads to missing information as well as "to much information". > - The code quality of the mailet is poor. > You will: > - Ensure a single log message will be generated. For this you will call the > logger one time and concatenate log messages parts. > - Remove the log line with mail name. > - Add a **level** configuration option. It can takes value **warn**, > **info**, **debug** or **error**. It will be used to set the logger log level. > - Add a **specificHeaders** configuration option. It takes a comma separated > list of header names to include in the log message. By default it is empty. > - Add a **specificAttributes** configuration option. It takes a comma > separated list of attribute names to be included in the log message. By > default it is empty. > - **body** configuration option should be false by default > - **header** configuration option should be false by default > - **init** should propagate exception while initilizing (Integer parse > exception, also passing a negative max body should throw.) > - Remove inlined affectation for field. They can be unset on their > declaration and set when init is called. > Correct *LogMessageTest* accordingly. > Don't hesitate to reach us on the *gitter* chat if you have any question. -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org