英文:
Why is PySpark logger not logging INFO statements?
问题
在以下PySpark代码中,我尝试确保INFO语句被记录。然而,我只看到了WARN、ERROR和FATAL消息。如何更新记录器'Example Processor'的日志级别为INFO,并记录所有内容?
注意:DEBUG日志工作正常,记录DEBUG、INFO、WARN、ERROR和FATAL的所有内容。谢谢!
self.spark = SparkSession.builder \
.master("local[1]") \
.appName("DemoProcessor") \
.getOrCreate()
log4jLogger = self.spark.sparkContext._jvm.org.apache.log4j
self.log = log4jLogger.LogManager.getLogger('Example Processor')
self.log.setLevel(log4jLogger.Level.INFO)
# self.log.setLevel(log4jLogger.Level.DEBUG)
self.log.trace("Trace Message!")
self.log.debug("Debug Message!")
self.log.info("Info Message!")
self.log.warn("Warn Message!")
self.log.error("Error Message!")
self.log.fatal("Fatal Message!")
INFO级别日志:
将默认日志级别设置为"WARN"。
要调整日志级别,请使用sc.setLogLevel(newLevel)。对于SparkR,请使用setLogLevel(newLevel)。
23/02/09 17:22:44 WARN NativeCodeLoader: 无法加载适用于您平台的本机hadoop库...在适用的情况下使用内置的Java类
23/02/09 17:22:44 WARN Example Processor: Warn Message!
23/02/09 17:22:44 ERROR Example Processor: Error Message!
23/02/09 17:22:44 FATAL Example Processor: Fatal Message!
DEBUG级别日志:
将默认日志级别设置为"WARN"。
要调整日志级别,请使用sc.setLogLevel(newLevel)。对于SparkR,请使用setLogLevel(newLevel)。
23/02/09 17:35:00 WARN NativeCodeLoader: 无法加载适用于您平台的本机hadoop库...在适用的情况下使用内置的Java类
23/02/09 17:35:01 INFO Example Processor: Info Message!
23/02/09 17:35:01 DEBUG Example Processor: Debug Message!
23/02/09 17:35:01 WARN Example Processor: Warn Message!
23/02/09 17:35:01 ERROR Example Processor: Error Message!
23/02/09 17:35:01 FATAL Example Processor: Fatal Message!
英文:
In the PySpark code below, I am attempting to ensure INFO statements are logged. However, I am only seeing WARN, ERROR and FATAL messages. How do I update the logger ('Example Processor')
to have a log level of INFO, and log everything out?
Note: DEBUG logging works, and logs everything for DEBUG, INFO, WARN, ERROR, and FATAL. Thanks!
self.spark = SparkSession.builder \
.master("local[1]") \
.appName("DemoProcessor") \
.getOrCreate()
log4jLogger = self.spark.sparkContext._jvm.org.apache.log4j
self.log = log4jLogger.LogManager.getLogger('Example Processor')
self.log.setLevel(log4jLogger.Level.INFO)
# self.log.setLevel(log4jLogger.Level.DEBUG)
self.log.trace("Trace Message!")
self.log.debug("Debug Message!")
self.log.info("Info Message!")
self.log.warn("Warn Message!")
self.log.error("Error Message!")
self.log.fatal("Fatal Message!")
INFO level Log:
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
23/02/09 17:22:44 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
23/02/09 17:22:44 WARN Example Processor: Warn Message!
23/02/09 17:22:44 ERROR Example Processor: Error Message!
23/02/09 17:22:44 FATAL Example Processor: Fatal Message!
DEBUG level log:
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
23/02/09 17:35:00 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
23/02/09 17:35:01 INFO Example Processor: Info Message!
23/02/09 17:35:01 DEBUG Example Processor: Debug Message!
23/02/09 17:35:01 WARN Example Processor: Warn Message!
23/02/09 17:35:01 ERROR Example Processor: Error Message!
23/02/09 17:35:01 FATAL Example Processor: Fatal Message!
答案1
得分: 1
在PySpark代码中,您试图将日志级别设置为log4jLogger.Level.INFO,但似乎没有生效。要检查的一件事是确保日志级别没有在您的代码中的其他地方被覆盖。例如,如果您的脚本中有以下代码,它将把根日志记录器的级别设置为log4jLogger.Level.WARN:
log4jLogger.LogManager.getRootLogger().setLevel(log4jLogger.Level.WARN)
这就解释了为什么您只能看到WARN、ERROR和FATAL消息,即使您已将日志级别设置为'Example Processor'日志记录器的log4jLogger.Level.INFO。要解决此问题,您可以删除设置根日志记录器日志级别的那行代码,或将根日志记录器的日志级别设置为更详细的级别,例如log4jLogger.Level.DEBUG。
英文:
It seems like the logging level is not being set correctly for the logger 'Example Processor'. In the PySpark code, you are trying to set the log level to log4jLogger.Level.INFO, but it's not taking effect.
One thing to check is to make sure that the log level is not being overridden elsewhere in your code. For example, if you have the following code in your script, it will set the log level for the root logger to log4jLogger.Level.WARN:
log4jLogger.LogManager.getRootLogger().setLevel(log4jLogger.Level.WARN)
This would explain why you're only seeing WARN, ERROR, and FATAL messages, even though you set the log level for the 'Example Processor' logger to log4jLogger.Level.INFO.
To resolve the issue, you can either remove the line setting the log level for the root logger or set the log level for the root logger to a more verbose level, such as log4jLogger.Level.DEBUG.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论