how to hide "py4j.java_gateway:Received command c on object id p0"?
Asked Answered
S

4

28

Once logging is started in INFO level I keep getting bunch of py4j.java_gateway:Received command c on object id p0 on your logs. How can I hide it?

Sparteine answered 16/5, 2016 at 11:11 Comment(0)
S
47

using the logging module run:

logging.getLogger("py4j").setLevel(logging.ERROR)

Sparteine answered 16/5, 2016 at 11:11 Comment(1)
happy to help, stackoverflow rocksSparteine
B
6

None of these answers have worked for me. Even after using the above solutions, I was still getting the logging errors.

After a long search I came across the following that solved my issue.

import logging
logger = spark._jvm.org.apache.log4j
logging.getLogger("py4j.java_gateway").setLevel(logging.ERROR)

I found this solution in the Databricks Knowledge base article

Bastia answered 21/2, 2022 at 6:51 Comment(1)
why do we need this line logger = spark._jvm.org.apache.log4j? it do not change or update anythingPunch
S
1

The best way to control pyspark and py4j logging is by setting the following snippet:

import logging
logging.getLogger("py4j").setLevel(<pyspark-level>)
logging.getLogger('pyspark').setLevel(<py4j-level>)
logger = logging.getLogger('pyspark')

For your case you should write:

import logging
logging.getLogger("py4j").setLevel(logging.INFO)
logging.getLogger('pyspark').setLevel(logging.ERROR)
logger = logging.getLogger('pyspark')
Sentimentality answered 17/5, 2021 at 11:29 Comment(0)
I
0

For me it was nosetests overwriting all these levels. The only solution that worked was passing --logging-level=INFO as argument to nose. Ref: http://nose.readthedocs.io/en/latest/plugins/logcapture.html#cmdoption-logging-level

Inexact answered 27/10, 2022 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.