Skip to content

[SPARK-26235][Core] Change log level for ClassNotFoundException/NoClassDefFoundError in SparkSubmit to Error #23189

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

Closed
wants to merge 2 commits into from

Conversation

gengliangwang
Copy link
Member

What changes were proposed in this pull request?

In my local setup, I set log4j root category as ERROR (https://stackoverflow.com/questions/27781187/how-to-stop-info-messages-displaying-on-spark-console , first item show up if we google search "set spark log level".) When I run such command

spark-submit --class foo bar.jar 

Nothing shows up, and the script exits.

After quick investigation, I think the log level for ClassNotFoundException/NoClassDefFoundError in SparkSubmit should be ERROR instead of WARN. Since the whole process exit because of the exception/error.

Before #20925, the message is not controlled by log4j.rootCategory.

How was this patch tested?

Manual check.

@gengliangwang
Copy link
Member Author

cc @vanzin

This is really trivial, but can be helpful to user in certain case.

@vanzin
Copy link
Contributor

vanzin commented Nov 30, 2018

Actually the problem is here:

      case e: ClassNotFoundException =>
        logWarning(s"Failed to load $childMainClass.", e)

That particular logWarning is not overridden in the SparkSubmit object:

  override def main(args: Array[String]): Unit = {
    val submit = new SparkSubmit() {
      ...
      override protected def logWarning(msg: => String): Unit = printMessage(s"Warning: $msg")

Probably should instead use the same logWarning call as the other handler below:

      case e: NoClassDefFoundError =>
        logWarning(s"Failed to load $childMainClass: ${e.getMessage()}")

Which should then always print the error regardless of your log4j configuration.

@gengliangwang
Copy link
Member Author

@vanzin The logWarning call as the other handler below is also not overridden:

      case e: NoClassDefFoundError =>
        logWarning(s"Failed to load $childMainClass: ${e.getMessage()}")

My basic point is, the exception/error message should be in the category of ERROR, even previously Spark prints as warning to System.err.

@SparkQA
Copy link

SparkQA commented Nov 30, 2018

Test build #99514 has finished for PR 23189 at commit 158d421.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@vanzin
Copy link
Contributor

vanzin commented Nov 30, 2018

The logWarning call as the other handler below is also not overridden:

It is. I even copied & pasted the code. I made the change locally and this is what happens:

$ ./bin/spark-submit --class foo bar.jar 
Warning: Failed to load foo: foo

With your change, if you are using a file appender instead of a console appender, you'll still not see the error on the terminal. For spark-submit, since it's a user-run script, it's good to print something to the terminal in these cases, regardless of the logging configuration.

If you want to also write the full exception to the logs, that's fine, but the change I suggested is more correct here considering the use.

@gengliangwang
Copy link
Member Author

gengliangwang commented Nov 30, 2018

@vanzin Ah, I see. Thanks for pointing it out!

But I am now thinking overriding logError as calling printMessage("Error..."). What do you think?

@vanzin
Copy link
Contributor

vanzin commented Nov 30, 2018

Sounds ok.

@@ -813,14 +813,14 @@ private[spark] class SparkSubmit extends Logging {
mainClass = Utils.classForName(childMainClass)
} catch {
case e: ClassNotFoundException =>
logWarning(s"Failed to load $childMainClass.", e)
logError(s"Failed to load class $childMainClass.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I tried append e.getMessage to the output, but it seems the error message equals the class name childMainClass. e.g.

Error: Failed to load class foo: foo.

So I think we can output without the exception message.

@SparkQA
Copy link

SparkQA commented Nov 30, 2018

Test build #99525 has finished for PR 23189 at commit 1662a8b.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • logError(s\"Failed to load class $childMainClass.\")

@gengliangwang
Copy link
Member Author

retest this please.

@SparkQA
Copy link

SparkQA commented Dec 1, 2018

Test build #99545 has finished for PR 23189 at commit 1662a8b.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • logError(s\"Failed to load class $childMainClass.\")

@srowen
Copy link
Member

srowen commented Dec 3, 2018

Merged to master

@asfgit asfgit closed this in 6e4e70f Dec 3, 2018
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
…ssDefFoundError in SparkSubmit to Error

## What changes were proposed in this pull request?

In my local setup, I set log4j root category as ERROR (https://stackoverflow.com/questions/27781187/how-to-stop-info-messages-displaying-on-spark-console , first item show up if we google search "set spark log level".) When I run such command
```
spark-submit --class foo bar.jar
```
Nothing shows up, and the script exits.

After quick investigation, I think the log level for ClassNotFoundException/NoClassDefFoundError in SparkSubmit should be ERROR instead of WARN. Since the whole process exit because of the exception/error.

Before apache#20925, the message is not controlled by `log4j.rootCategory`.

## How was this patch tested?

Manual check.

Closes apache#23189 from gengliangwang/changeLogLevel.

Authored-by: Gengliang Wang <gengliang.wang@databricks.com>
Signed-off-by: Sean Owen <sean.owen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants