PHP code example of scalpel / watch-log

1. Go to this page and download the library: Download scalpel/watch-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

scalpel / watch-log example snippets




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

$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