【问题标题】:How to capture logs from databricks notebook and store them to data lake gen2如何从 databricks 笔记本中捕获日志并将它们存储到数据湖 gen2
【发布时间】:2022-01-21 14:32:41
【问题描述】:

如何从 Databricks Notebook 代码中捕获日志并将其存储到 Azure 数据湖 gen 2 中的文件中?

我想为我的 Scala 语言代码实现自定义日志。

【问题讨论】:

  • 这与 Scala 有什么关系?你刚才在这里问的不是问题。这是一个写书的请求。

标签: scala logging log4j databricks azure-databricks


【解决方案1】:

您可以使用 Python azure-storage-logging 库。

azure-storage-logging 提供从 Microsoft Azure 存储的标准 Python 日志记录 API。

import logging
from azure_storage_logging.handlers import TableStorageHandler

# configure the handler and add it to the logger
logger = logging.getLogger('example')
handler = TableStorageHandler(account_name='mystorageaccountname',
                              account_key='mystorageaccountkey',
                              extra_properties=('%(hostname)s',
                                                '%(levelname)s'))
logger.addHandler(handler)

# output log messages
logger.info('info message')
logger.warning('warning message')
logger.error('error message')

参考:https://pypi.org/project/azure-storage-logging/

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 2021-03-26
    • 1970-01-01
    • 2019-04-22
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    相关资源
    最近更新 更多