You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Piotr Karwasz (Jira)" <ji...@apache.org> on 2022/07/28 07:37:00 UTC

[jira] [Resolved] (LOG4J2-3561) Ansi color with spaces in style pattern not supported

     [ https://issues.apache.org/jira/browse/LOG4J2-3561?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Piotr Karwasz resolved LOG4J2-3561.
-----------------------------------
      Assignee: Piotr Karwasz
    Resolution: Fixed

Hi [~twisterrob],

I have submitted a change to the latest {{2.18.1-SNAPSHOT}} (you can find it at [https://repository.apache.org/snapshots]) that allows space separated lists in a {{%style}} pattern. Can you check if it solves your problem and close the issue?

For completeness' sake, {{{}%style{bright white{}}}} never worked in 2.17.2. The only thing that changed in 2.18.0 is that before the problem was ignored, now a warning is issued. Thank you for noticing the warning.

> Ansi color with spaces in style pattern not supported
> -----------------------------------------------------
>
>                 Key: LOG4J2-3561
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3561
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Layouts
>    Affects Versions: 2.18.0
>            Reporter: Robert Papp
>            Assignee: Piotr Karwasz
>            Priority: Minor
>
> _Extracted from https://issues.apache.org/jira/browse/LOG4J2-3537?focusedCommentId=17570358&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17570358 comment._
> After updating from 2.17.2 to 2.18.0 this exception started coming up:
> {code:java}
> WARN The style attribute bright white is incorrect. java.lang.IllegalArgumentException: No enum constant org.apache.logging.log4j.core.pattern.AnsiEscape.BRIGHT WHITE
>     at java.base/java.lang.Enum.valueOf(Enum.java:240)
>     at org.apache.logging.log4j.util.EnglishEnums.valueOf(EnglishEnums.java:67)
>     at org.apache.logging.log4j.util.EnglishEnums.valueOf(EnglishEnums.java:50)
>     at org.apache.logging.log4j.core.pattern.AnsiEscape.createSequence(AnsiEscape.java:486)
>     at org.apache.logging.log4j.core.pattern.StyleConverter.newInstance(StyleConverter.java:96)
> {code}
> for config:
> {code:java}
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration
> 	xmlns="http://logging.apache.org/log4j/2.0/config"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	strict="true"
> 	status="warn"
> 	xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/apache/logging-log4j2/master/log4j-core/src/main/resources/Log4j-config.xsd"
> >
> 	<Properties>
>  	 	<Property name="pattern_level_colors">
>  	 	 	FATAL=bright magenta, ERROR=bright red, WARN=bright yellow, INFO=dim white, DEBUG=bright black, TRACE=cyan
>  	 	</Property>
>  	 	<Property name="pattern_styled">%highlight{%date{ISO8601} %-5level [%thread] %logger(%file:%line)}{${
> 		pattern_level_colors}} %style{%message}{bright white}%n%style{%throwable}{BG_red,white}
> 		</Property>
> 	</Properties>
> 	<Appenders>
> 		<Appender type="Console" name="color-console">
> 			<Layout type="PatternLayout" pattern="${pattern_styled}" />
> 		</Appender>
> 	</Appenders>
> {code}
> doing this fixed the issue:
> {code:java}
> -%style{%message}{bright white}
> +%style{%message}{bright_white}
> {code}
> [~pkarwasz] said 
> {quote}The problem you are having is not with the highlight pattern, but the style pattern:
>  * the highlight pattern separates the keywords with white space: e.g. "INFO=bright white",
>  * the style pattern separates the keywords with commas: e.g. "bright, white".
> I agree that this is inconsistent, but it is easily fixable: instead of just using commas as separators in the style pattern, we can use commas or white space. This way we take care of backward compatibility and bring some consistency to the two patterns.{quote}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)