scalpel/watch-log

该软件包最新版本(0.1.0)的许可证信息不可用。

0.1.0 2019-07-02 08:41 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:25 UTC


README

用于监听服务器日志文件变化,类似于 web 版本的多文件同屏 tail -f file 效果,
主要用于像我一样喜欢基于日志文件进行开发调试的用户

注意:可以监听任何文件,可以点击选择要监听的文件,为了您的安全,请仅在测试环境下运行,或者自行增加防火墙规则以安全访问

安装

composer install scalpel/watch-log:*

配置

创建配置文件以设置相关参数,配置 logs 以监听多个日志文件,

使用 --config configFilePath 设置配置文件路径,
默认配置文件为 project_root/config-watchLog.php

简单配置:

<?php

return [
    'server' => '0.0.0.0',
    'port' => 9504,
    'logs' => [
        __DIR__ . '/tmp/test.log'
    ]
];

DirectoryIterator 类自动遍历日志目录:

$opts = getopt("p");
$isPre = false;
if (isset($opts['p'])) {
    $isPre = true;
}

$logs = [];
if ($isPre) {
    $port = 9506;
    $dir = new DirectoryIterator(dirname(__DIR__) . "/tmp/log/");
} else {
    $port = 9505;
    $dir = new DirectoryIterator(__DIR__ . "/tmp/log/");
}

foreach ($dir as $file) {
    if (!$file->isDot() && $file->isFile() && strpos($file->getFilename(), '.') !== 0) {
        $logs[] = $file->getPathname();
    }
}

/*
 eg:   [
            'server' => '127.0.0.1',
            'port' => 9505,
            'logs' => [
                '/mnt/d/testComposer/tmp/log/error.log',
                '/mnt/d/testComposer/tmp/log/sql.log'
            ]
        ];
*/
return [
    'server' => '127.0.0.1',
    'port' => $port,
    'logs' => $logs
];

运行

php vendor/bin/WatchLog.php -v

帮助

php vendor/bin/WatchLog.php -h

php WatchLog.php [options]

Options:
    -h, print this message
    -v, debug mode
    
    -d, run as a daemonize mode
    -a <action>, 
        stop: stop the server 
        restart: restart the server
    
    --config value, config file path, 
        default: project_root/config-watchLog.php

使用

http://your_server:port (如:http://127.0.0.1:9505/)