jotweh/codeception-monolog

Codeception 的 Monolog 扩展

1.1.0 2015-02-13 15:18 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:41:30 UTC


README

这是什么?

默认的 Codeception Logger 扩展(见 http://codeception.com/addons)始终使用 RotatingFileHandler 进行日志记录,将内容写入到 codeception-<date>.log 文件。这对我来说还不够,所以我创建了此可配置的 Monolog 日志扩展。它允许使用具有自定义配置的多个日志处理程序(下面有示例)。目前仅支持不要求构造函数参数中包含对象的日志处理程序,例如

  • NativeMailHandler
  • FirePHPHandler
  • RotatingFileHandler
  • HipChatHandler
  • ErrorLogHandler
  • ...

目前只有在测试失败的情况下才会触发日志处理程序。

安装

目前无法通过 Packagist 获取,所以您需要将其添加到您的 composer.json

  ...
  "repositories": [
    {
      "type": "vcs",
      "url": "git@github.com:jotweh/codeception-monolog.git"
    }
  ],
  "require": {
    "jotweh/codeception-monolog": "dev-master",
    ...
  }
  ...

配置

在您的 codeception.yaml 中启用扩展,如下所示

extensions:
    enabled:
        - Codeception\Extension\CodeceptionMonolog

您可以在 codeception.yaml 中配置多个日志处理程序

extensions:
    enabled:
        - Codeception\Extension\CodeceptionMonolog
    config:
            Codeception\Extension\CodeceptionMonolog:
                message: "Test %s failed. Please check. Error Message: %s."
                handlers:
                    NativeMailerHandler:
                          to: 'test@example.com,othertest@example.com'
                          subject: 'Email Subject'
                          from: 'Monitoring'
                          level: 400 #error log level
                    HipChatHandler:
                          token: 'somecryptichipchattoken'
                          room: 'HipChatRoomName'
                          name: 'Notifier'
                          notify: true
                          level: 400 #error log level

handlers 部分,每个键是 Monolog 处理程序类名。值是处理程序的构造函数参数。在上面的示例中,使用了 HipChatHandler 和 NativeMailerHandler。因此,当测试失败时,会发送电子邮件和 hipchat 通知。