-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-47659][CORE][TESTS] Improve *LoggingSuite*
#45784
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg and basicMsg are duplicated, we can make full use of basicMsg.
spark/common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala
Line 49 in 11d76c9
| def basicMsg: String = "This is a log message" |
| } | ||
|
|
||
| override def expectedPatternForMsgWithMDCAndException(level: Level): String = { | ||
| compactAndToRegexPattern( |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.