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

[jira] [Comment Edited] (LOG4J2-3537) Ansi escape code for highlight is generated wrong

    [ https://issues.apache.org/jira/browse/LOG4J2-3537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17570358#comment-17570358 ] 

Robert Papp edited comment on LOG4J2-3537 at 7/23/22 7:26 PM:
--------------------------------------------------------------

[~pkarwasz] [~Pavel_K] as much as you were concerned with backwards compatibility... it slipped through
{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, but it feels like this was not intended based on the conversation thread on this ticket...
{code:java}
-%style{%message}{bright white}
+%style{%message}{bright_white}
{code}


was (Author: twisterrob):
[~pkarwasz] [~Pavel_K] as much as you were concerned with backwards compatibility... it slipped through

{code}
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}
<?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_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, but it feels like this was not intended based on the conversation thread on this ticket...
{code}
-%style{%message}{bright white}
+%style{%message}{bright_white}
{code}

> Ansi escape code for highlight is generated wrong
> -------------------------------------------------
>
>                 Key: LOG4J2-3537
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3537
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.14.1
>            Reporter: Pavel_K
>            Priority: Minor
>             Fix For: 2.18.0
>
>         Attachments: Screenshot from 2022-06-14 16-09-30.png, Screenshot from 2022-06-14 16-13-13.png
>
>
> This is a test pattern layout:
> {code:java}
>  <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight{[%level]}{FATAL=red bright, ERROR=red bright, WARN=yellow bright, INFO=magenta bright, DEBUG=green, TRACE=blue bright} [%t] %logger{36} - %msg%n" disableAnsi="false"/>
> {code}
> As you see for TRACE level is `blue bright`. However, this is a generated code:
> [TRACE] . As you see we have [SGR|https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters] function with two parameters: 34 is color and 1 is bold. 
> For example linux terminal will render it this way:
>  !Screenshot from 2022-06-14 16-09-30.png! 
> We see, that it is not `bright blue` but `bold blue`. At the same time in [manual|https://logging.apache.org/log4j/2.x/manual/layouts.html] they speak about different colors:
>  !Screenshot from 2022-06-14 16-13-13.png! 
> And if we want bright blue, generated escape code should be `[TRACE]` - see the link to SGR function I provided.



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