如何在数据块中添加登录 Scala 代码?

How to add logging in scala code in databricks?

我知道在数据块上我们得到以下集群日志。

  1. 标准输出
  2. 标准错误
  3. log4j

就像我们使用 sl4j 登录 java 一样,我想知道如何将我的日志添加到 scala notebook 中。

我尝试在笔记本中添加以下代码。但是消息不会打印在 log4j 日志中。

import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory
val logger = Logger(LoggerFactory.getLogger("TheLoggerName"))
logger.debug("****************************************************************** Useful message....")

当您在 databricks 中创建集群时,有一个选项卡,您可以在其中指定日志目录(默认为空)。

日志写在DBFS上,所以你只需要指定你想要的目录。

您可以在 Databricks Notebook 中像下面的代码一样使用。

// creates a custom logger and log messages
var logger = Logger.getLogger(this.getClass())
logger.debug("this is a debug log message")
logger.info("this is a information log message")
logger.warn("this is a warning log message")
logger.trace("this is a TRACE log message")

How to overwrite log4j configurations on Azure Databricks clusters