【问题标题】:How to output custom log to terminal when doing spark-submit?spark-submit 时如何将自定义日志输出到终端?
【发布时间】:2019-04-10 15:35:34
【问题描述】:

我在机器 A 上有一个单节点 Spark,我在另一台机器 B 上执行 spark-submit,这就是我运行 spark-submit 的方式:

spark-submit \
  --class com.foo.misc.spark.WordCount \
  --master yarn \
  --deploy-mode cluster \
  --executor-memory 1G \
  --num-executors 5 \
  wordcount.jar \
  file:///root/input01.txt \
  hdfs://os74gcc52-c6cfd5d5:9000/test/output9

这很好用,我可以看到按字数生成的 output9。

只有这样,在查看终端(我运行 spark-submit 的那个)时,我找不到我的日志信息,我看到的只是类似 spark 的日志

2018-11-07 15:41:36 INFO  Client:54 - Application report for application_1541562152848_0010 (state: RUNNING)
2018-11-07 15:41:37 INFO  Client:54 - Application report for application_1541562152848_0010 (state: RUNNING)
2018-11-07 15:41:38 INFO  Client:54 - Application report for application_1541562152848_0010 (state: RUNNING)
2018-11-07 15:41:39 INFO  Client:54 - Application report for application_1541562152848_0010 (state: RUNNING)
2018-11-07 15:41:40 INFO  Client:54 - Application report for application_1541562152848_0010 (state: FINISHED)

这就是我在 WordCount.java 中的登录方式,

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
...

public class WordCount {
    private static final Logger log = LogManager.getLogger(WordCount.class);

    public static void main(String[] args) {
        log.warn("start foooooooooooooooooooo");
        ...

是因为我使用的是集群部署模式吗?还是因为其他原因?

【问题讨论】:

    标签: java apache-spark logging terminal log4j


    【解决方案1】:

    从资源管理器获取 spark 作业的应用程序 id。使用 yarn 命令获取应用程序 id 的日志。你会发现你的信息是使用日志管理器打印的。 如果应用程序是在客户端模式下提交的,我认为这些可以在作业运行时在控制台上看到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多