Created
August 27, 2021 04:20
-
-
Save Nihhaar/83115935c655cdd5065bf18f98f9a6a4 to your computer and use it in GitHub Desktop.
PySpark logging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
import sys | |
class YarnLogger: | |
@staticmethod | |
def setup_logger(): | |
if not 'LOG_DIRS' in os.environ: | |
sys.stderr.write('Missing LOG_DIRS environment variable, pyspark logging disabled') | |
return | |
file = os.environ['LOG_DIRS'].split(',')[0] + '/pyspark.log' | |
logging.basicConfig(filename=file, level=logging.INFO, | |
format='%(asctime)s.%(msecs)03d %(levelname)s %(module)s - %(funcName)s: %(message)s') | |
def __getattr__(self, key): | |
return getattr(logging, key) | |
YarnLogger.setup_logger() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment