[SPARK-47659][CORE][TESTS] Improve *LoggingSuite*#45784
Conversation
| def msgWithMDCAndException: LogEntry = log"Error in executor ${MDC(EXECUTOR_ID, "1")}." | ||
|
|
||
| def expectedPatternForBasicMsg(level: String): String | ||
| def expectedPatternForBasicMsg(level: Level): String |
There was a problem hiding this comment.
Using 'Level' instead of 'String' may be more reasonable
| def expectedPatternForMsgWithMDCAndException(level: Level): String | ||
|
|
||
| test("Basic logging") { | ||
| val msg = "This is a log message" |
There was a problem hiding this comment.
msg and basicMsg are duplicated, we can make full use of basicMsg.
| } | ||
|
|
||
| override def expectedPatternForMsgWithMDCAndException(level: Level): String = { | ||
| compactAndToRegexPattern( |
There was a problem hiding this comment.
This line is too long,
Show it in pretty json to developers,
This can also eliminate the comment scalastyle:off line.size.limit
| override def afterAll(): Unit = Logging.enableStructuredLogging() | ||
|
|
||
| override def expectedPatternForBasicMsg(level: String): String = | ||
| s""".*$level PatternLoggingSuite: This is a log message\n""" |
There was a problem hiding this comment.
Let's make full use of the variable className to eliminate hard coding text PatternLoggingSuite
| override def expectedPatternForBasicMsg(level: String): String = | ||
| s"""\\{"ts":"[^"]+","level":"$level","msg":"This is a log message","logger":"$className"}\n""" | ||
| private val jsonMapper = new ObjectMapper().registerModule(DefaultScalaModule) | ||
| private def compactAndToRegexPattern(json: String): String = { |
There was a problem hiding this comment.
In testing, this method compactAndToRegexPattern will ultimately be used to compact the output JSON and convert it into a regex pattern for matching and validation.
|
|
||
| // Returns the first line in the log file that contains the given substring. | ||
| protected def captureLogOutput(f: () => Unit): String = { | ||
| // Return the newly added log contents in the log file after executing the function `f` |
There was a problem hiding this comment.
Obviously, the using of the function is:
Return the newly added log contents in the log file after executing the function f
|
Thanks, merging to master |
What changes were proposed in this pull request?
The pr aims to improve
UTrelated tostructured logs, including:LoggingSuiteBase,StructuredLoggingSuiteandPatternLoggingSuite.Why are the changes needed?
Enhance readability and make it more elegant.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No.