如何将Azure诊断与Python一起使用?

如何将Azure诊断与Python一起使用?,python,visual-studio-2013,azure-diagnostics,Python,Visual Studio 2013,Azure Diagnostics,我使用Visual Studio 2013创建了一个python项目(控制台应用程序),并安装了以下软件: 1) Microsoft Azure SDK for Python 3.4- 2) Visual Studio的Python工具- 我成功地使用Python访问了Azure存储(Blob&Queue)。但是,我无法使用Azure Diagnostics记录消息 有没有一种方法可以将Azure Diagnostics与Python源代码一起使用?Azure Diagnostics可以收集以下

我使用Visual Studio 2013创建了一个python项目(控制台应用程序),并安装了以下软件: 1) Microsoft Azure SDK for Python 3.4- 2) Visual Studio的Python工具-

我成功地使用Python访问了Azure存储(Blob&Queue)。但是,我无法使用Azure Diagnostics记录消息


有没有一种方法可以将Azure Diagnostics与Python源代码一起使用?

Azure Diagnostics可以收集以下类型的遥测数据:

  • IIS日志
  • Azure诊断基础架构日志
  • IIS失败的请求日志
  • Windows事件日志
  • 性能计数器
  • 崩溃转储
  • 自定义错误日志
  • .NET事件源
  • 基于舱单的ETW
然而,使用Python,上述所有内容可能都不可能实现。但是,“azure存储日志”提供了将标准Python日志API的输出发送到Microsoft azure存储(表/队列)的功能

依赖关系 azure 0.9或更新版本

装置 通过pip安装软件包:

pip安装azure存储日志

用法 资料来源:

    LOGGING = {
        'version': 1,
        'formatters': {
            'simple': {
                'format': '%(asctime)s %(message)s',
            },
            'verbose': {
                'format': '%(asctime)s %(levelname)s %(hostname)s %(process)d %(message)s',
            },
            # this is the same as the default, so you can skip configuring it
            'partition_key': {
                'format': '%(asctime)s',
                'datefmt': '%Y%m%d%H%M',
            },
            # this is the same as the default, so you can skip configuring it
            'row_key': {
                'format': '%(asctime)s%(msecs)03d-%(hostname)s-%(process)d-%(rowno)02d',
                'datefmt': '%Y%m%d%H%M%S',
            },
        },
        'handlers': {
            'file': {
                'account_name': 'mystorageaccountname',
                'account_key': 'mystorageaccountkey',
                'protocol': 'https',
                'level': 'DEBUG',
                'class': 'azure_storage_logging.handlers.BlobStorageTimedRotatingFileHandler',
                'formatter': 'verbose',
                'filename': 'example.log',
                'when': 'D',
                'interval': 1,
                'container': 'logs-%(hostname)s',
                'zip_compression': False,
            },
            'queue': {
                'account_name': 'mystorageaccountname',
                'account_key': 'mystorageaccountkey',
                'protocol': 'https',
                'queue': 'logs',
                'level': 'CRITICAL',
                'class': 'azure_storage_logging.handlers.QueueStorageHandler',
                'formatter': 'verbose',
            },
            'table': {
                'account_name': 'mystorageaccountname',
                'account_key': 'mystorageaccountkey',
                'protocol': 'https',
                'table': 'logs',
                'level': 'INFO',
                'class': 'azure_storage_logging.handlers.TableStorageHandler',
                'formatter': 'simple',
                'batch_size': 20,
                'extra_properties': ['%(hostname)s', '%(levelname)s'],
                'partition_key_formatter': 'cfg://formatters.partition_key',
                'row_key_formatter': 'cfg://formatters.row_key',
            },
        },
        'loggers': {
            'example': {
                'handlers': ['file', 'queue', 'table'],
                'level': 'DEBUG',
            },
        }
    }

    import logging
    from logging.config import dictConfig

    dictConfig(LOGGING)
    logger = logging.getLogger('example')
    logger.debug('debug message')
    logger.info('info message')
    logger.warning('warning message')
    logger.error('error message')
    logger.critical('critical message')