exs/terminal-bundle

Symfony2 的终端命令日志包

v1.1.2 2017-02-06 12:10 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:00 UTC


README

终端包,用于记录所有命令输出(无论输出缓冲区(echo / print_r / var_dump / ->ln())),锁定命令以防止并发运行,提供命令统计信息(pid,运行时间,错误)并记录数据库中的任何异常/错误。当命令通过 cronjob 运行时,通过 Web 界面控制命令非常有用。快速处理移植到您的 symfony2 应用程序的老旧代码。

作为监听所有异常并将它们记录到数据库中的服务安装包。锁定使用命令别名作为引用的缩略语。当与启用 crontab 的监控程序一起使用时,当出现错误、当前锁定击中时,我们可以向开发团队发出警报,并通过 Web 界面而不是登录到出现问题的特定主机来查看日志。

选项

--output (-o)          Output type (console, db (default: "console")
--lock=true (-l)       Whether or not to lock the console command

在新的 Symfony2 项目中安装 TerminalBundle

所以 TerminalBundle 已经准备好安装了,这是个好消息,但我们应该如何安装它。安装过程实际上非常简单。使用 Composer 设置一个新的 Symfony2 项目。

一旦新项目设置完成,打开 composer.json 文件,并将 exs/terminal-bundle 添加为依赖项

//composer.json
//...
"require": {
        //other bundles
        "exs/terminal-bundle": "dev-master"

保存文件,并通过命令行使用 composer update 更新项目

php composer.phar update

Composer 将更新所有依赖项,你应该能在列表中看到我们的包

  - Installing exs/terminal-bundle (dev-master 463eb20)
    Cloning 463eb2081e7205e7556f6f65224c6ba9631e070a

更新 app/AppKernel.php 和 app/config/routing.yml 以包含我们的包,清除缓存并更新模式

//app/AppKernel.php
//...
    public function registerBundles()
    {
        $bundles = array(
            //Other bundles
            new EXS\TerminalBundle\EXSTerminalBundle()
        );
#app/config/config.yml
#...
exs_terminal:
    email:
        from: from@test.tld
        to: to@test.tld
        subject: Subject

您必须手动使用 doctrine:schema:update 命令更新数据库。

迁移不会工作,因为它们需要创建的表...

php app/console cache:clear
php app/console doctrine:schema:update --force

最后,从 vendor/exs/terminal-bundle/EXS/TerminalBundle/runner 复制包括的 bash 文件:"runner" 到 app/runner,这会将挂钩添加到原始控制台脚本中,而不会更改原始脚本。

cp vendor/exs/terminal-bundle/EXS/TerminalBundle/runner app/runner

确保您的邮件器在 config.yml 和 parameters.yml 中配置正确

#app/config/config.yml
#...
# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

现在您已完成。

如果您想测试它们,请尝试同时在两个终端中打开相同的命令。它们当前每个运行 3 秒

php app/runner terminal:test:lock_sleep --lock=true -o=db
php app/runner terminal:test:lock_sleep --lock=true -o=db

运行上述命令后,您可以通过检查数据库来验证一切是否正常。锁定和日志将在以下表中记录在您的数据库中

  • terminallogs

  • commandlocks

此外,如果您的命令以非 0 状态退出,它可能在 exception5xx 表中记录了一个异常。

贡献

欢迎每个人贡献。

如果您有任何问题或建议,请 告诉我们