mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-18 05:04:51 +08:00
add logging config (#127)
This commit is contained in:
parent
87bbffefc3
commit
5cbeee6e86
21
config/logging.php
Normal file
21
config/logging.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use ZM\Logger\ConsoleLogger;
|
||||
|
||||
return [
|
||||
'level' => LogLevel::DEBUG,
|
||||
'logger' => static function (): LoggerInterface {
|
||||
$worker_id = app('worker_id');
|
||||
|
||||
$logger = new ConsoleLogger(zm_config('logging.level'));
|
||||
$logger::$format = "[%date%] [%level%] [#{$worker_id}] %body%";
|
||||
$logger::$date_format = 'Y-m-d H:i:s';
|
||||
// 如果你喜欢旧版的日志格式,请取消下行注释
|
||||
// $logger::$date_format = 'm-d H:i:s';
|
||||
return $logger;
|
||||
},
|
||||
];
|
||||
@ -9,6 +9,7 @@ namespace ZM\Event\SwooleEvent;
|
||||
use Error;
|
||||
use Exception;
|
||||
use PDO;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Database\PDOConfig;
|
||||
@ -316,6 +317,8 @@ class OnWorkerStart implements SwooleEvent
|
||||
$container->instance('worker_id', $server->worker_id);
|
||||
|
||||
$container->singleton(AdapterInterface::class, OneBot11Adapter::class);
|
||||
|
||||
$container->singleton(LoggerInterface::class, ZMConfig::get('logging.logger'));
|
||||
}
|
||||
|
||||
private function gatherWorkerStartStatus()
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Swoole\Atomic;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Coroutine as Co;
|
||||
@ -589,7 +590,7 @@ function zm_error($obj): void
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function zm_config(string $name, ?string $key = null)
|
||||
function zm_config(string $name, string $key = '')
|
||||
{
|
||||
return ZMConfig::get($name, $key);
|
||||
}
|
||||
@ -781,6 +782,14 @@ function is_assoc_array(array $array): bool
|
||||
return !empty($array) && array_keys($array) !== range(0, count($array) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 Logger 实例
|
||||
*/
|
||||
function logger(): LoggerInterface
|
||||
{
|
||||
return resolve(LoggerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以下为废弃的函数,将于未来移除
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user