Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -144,7 +143,7 @@ trait Logging {
implicit class LogStringContext(val sc: StringContext) {
def log(args: MDC*): MessageWithContext = {
val processedParts = sc.parts.iterator
val sb = new StringBuilder(processedParts.next())
val sb = new StringBuilder(StringContext.processEscapes(processedParts.next()))
val context = new java.util.HashMap[String, String]()

args.foreach { mdc =>
Expand All @@ -155,7 +154,7 @@ trait Logging {
}

if (processedParts.hasNext) {
sb.append(processedParts.next())
sb.append(StringContext.processEscapes(processedParts.next()))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ class StructuredLoggingSuite extends LoggingSuiteBase {
}""")
assert(pattern1.r.matches(logOutput) || pattern2.r.matches(logOutput))
}

test("process escape sequences") {
assert(log"\n".message == "\n")
assert(log"\t".message == "\t")
assert(log"\b".message == "\b")
assert(log"\r".message == "\r")
assert((log"\r" + log"\n" + log"\t" + log"\b").message == "\r\n\t\b")
assert((log"\r${MDC(LogKeys.EXECUTOR_ID, 1)}\n".message == "\r1\n"))
}
}

object CustomLogKeys {
Expand Down