-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48490][CORE][FOLLOWUP] Fix Unescape about MessageWithContext #47029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ package org.apache.spark.internal | |
|
|
||
| import scala.jdk.CollectionConverters._ | ||
|
|
||
| import org.apache.commons.text.StringEscapeUtils | ||
| import org.apache.logging.log4j.{CloseableThreadContext, Level, LogManager} | ||
| import org.apache.logging.log4j.core.{Filter, LifeCycle, LogEvent, Logger => Log4jLogger, LoggerContext} | ||
| import org.apache.logging.log4j.core.appender.ConsoleAppender | ||
|
|
@@ -100,7 +99,7 @@ case class MessageWithContext(message: String, context: java.util.HashMap[String | |
| * Companion class for lazy evaluation of the MessageWithContext instance. | ||
| */ | ||
| class LogEntry(messageWithContext: => MessageWithContext) { | ||
| def message: String = StringEscapeUtils.unescapeJava(messageWithContext.message) | ||
| def message: String = messageWithContext.message | ||
|
|
||
| def context: java.util.HashMap[String, String] = messageWithContext.context | ||
| } | ||
|
|
@@ -161,8 +160,17 @@ trait Logging { | |
|
|
||
| MessageWithContext(sb.toString(), context) | ||
| } | ||
|
|
||
| def log(c: Char): MessageWithContext = { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have provided |
||
| MessageWithContext(s"$c", new java.util.HashMap[String, String]()) | ||
| } | ||
| } | ||
|
|
||
| private final val LF_CHAR: Char = '\n' | ||
| private final val TAB_CHAR: Char = '\t' | ||
| final val LF = MessageWithContext(s"$LF_CHAR", new java.util.HashMap[String, String]()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait..are you suggesting that we should use this constant in log messages? If so, I would prefer
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| final val TAB = MessageWithContext(s"$TAB_CHAR", new java.util.HashMap[String, String]()) | ||
|
|
||
| protected def withLogContext(context: java.util.HashMap[String, String])(body: => Unit): Unit = { | ||
| val threadContext = CloseableThreadContext.putAll(context) | ||
| try { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ trait LoggingSuiteBase | |
| def basicMsgWithEscapeChar: String = "This is a log message\nThis is a new line \t other msg" | ||
|
|
||
| def basicMsgWithEscapeCharMDC: LogEntry = | ||
| log"This is a log message\nThis is a new line \t other msg" | ||
| log"This is a log message" + LF + log"This is a new line " + TAB + log" other msg" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although the above writing may seem |
||
|
|
||
| def msgWithMDC: LogEntry = log"Lost executor ${MDC(LogKeys.EXECUTOR_ID, "1")}." | ||
|
|
||
|
|
||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we maybe simply try-catch, and return the original string if it fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows users are arguably less in any event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and logging shouldn't fail the application anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm..., this may have
successfully unescaped, but the resultdoes notmeet expectations, such as:We may expect it to output as:
Actual, its output is:
So it's better not to execute the
unescapeoperation and let the user manually use the method I wrote inUTto achieve its expected behavior, although it does look a bit ugly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can use
try ... catchtemporarily fixes it, but it has some of my flaws mentioned above.Or should we do this (use
try ... catch) first and letbuild_sparkr_windowpass?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this approach but I think we need @gengliangwang 's look at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, let's wait for @gengliangwang's review.
Thanks!