Skip to content

Commit

Permalink
[MINOR][TESTS] Use SparkContext.setLogLevel in QuietTest
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

This PR proposes to use SparkContext.setLogLevel in QuietTest

### Why are the changes needed?

To avoid the direct update of logger but reuses SparkContext.setLogLevel.

### Does this PR introduce _any_ user-facing change?

No, test-only.

### How was this patch tested?

Manually tested.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #48966 from HyukjinKwon/minor-log-level.

Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: Hyukjin Kwon <[email protected]>
  • Loading branch information
HyukjinKwon committed Nov 26, 2024
1 parent 9054aa2 commit 9bab16a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions python/pyspark/testing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,16 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:

class QuietTest:
def __init__(self, sc):
self.log4j = sc._jvm.org.apache.log4j
self.sc = sc

def __enter__(self):
self.old_level = self.log4j.LogManager.getRootLogger().getLevel()
self.log4j.LogManager.getRootLogger().setLevel(self.log4j.Level.FATAL)
self.old_level = (
self.sc._jvm.org.apache.log4j.LogManager.getRootLogger().getLevel().toString()
)
self.sc.setLogLevel("FATAL")

def __exit__(self, exc_type, exc_val, exc_tb):
self.log4j.LogManager.getRootLogger().setLevel(self.old_level)
self.sc.setLogLevel(self.old_level)


class PySparkTestCase(unittest.TestCase):
Expand Down

0 comments on commit 9bab16a

Please sign in to comment.