1. Go to this page and download the library: Download volador2/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/ */
volador2 / log example snippets
use Volador\Log\Logger;
use Volador\Log\LogConfig;
class Bootstrap
{
function ___init() {
LogConfig::logfile("/var/log/a.log");
LogConfig::template("{DATETIME} [{REQUEST_ID}][{LEVEL}] {FILE}:{LINE} {CONTENT}");
// 设置日志模版中KEY的值
LogConfig::setTemplateVal('REQUEST_ID', $REQUEST_ID);
}
}
use Volador\Log\Logger;
class DemoController
{
function indexAction()
{
Logger::debug('hello, {name}', ['name' => 'Lin{name}']);
}
}
use Volador\Log\Logger;
use Volador\Log\LogConfig;
class Daemon
{
function __construct()
{
LogConfig::logfile('/path/debug.log');
LogConfig::template('{DATETIME} [{REQUEST_ID}][{LEVEL}] {FILE}:{LINE} {CONTENT}');
}
public function run()
{
for (;;) {
LogConfig::setTemplateVal('REQUEST_ID', $REQUEST_ID);
Logger::debug('hello, {name}', ['name' => 'Lin{name}']);
Logger::fflush();
}
}
}