mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
fix logger constructor
This commit is contained in:
parent
80050f11f2
commit
23a6e56478
@ -7,17 +7,17 @@ use Psr\Log\LogLevel;
|
|||||||
use ZM\Logger\ConsoleLogger;
|
use ZM\Logger\ConsoleLogger;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'level' => LogLevel::DEBUG,
|
'level' => LogLevel::INFO,
|
||||||
'logger' => static function (string $title = null): LoggerInterface {
|
'logger' => static function (string $prefix = null): LoggerInterface {
|
||||||
if ($title) {
|
if ($prefix) {
|
||||||
$title = strtoupper($title);
|
$prefix = strtoupper($prefix);
|
||||||
} else {
|
} else {
|
||||||
// 在 Master 中,worker_id 将不存在
|
// 在 Master 中,worker_id 将不存在
|
||||||
$title = app()->has('worker_id') ? '#' . app('worker_id') : 'MST';
|
$prefix = app()->has('worker_id') ? '#' . app('worker_id') : 'MST';
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger = new ConsoleLogger(zm_config('logging.level'));
|
$logger = new ConsoleLogger(zm_config('logging.level'));
|
||||||
$logger::$format = "[%date%] [%level%] [{$title}] %body%";
|
$logger::$format = "[%date%] [%level%] [{$prefix}] %body%";
|
||||||
$logger::$date_format = 'Y-m-d H:i:s';
|
$logger::$date_format = 'Y-m-d H:i:s';
|
||||||
// 如果你喜欢旧版的日志格式,请取消下行注释
|
// 如果你喜欢旧版的日志格式,请取消下行注释
|
||||||
// $logger::$date_format = 'm-d H:i:s';
|
// $logger::$date_format = 'm-d H:i:s';
|
||||||
|
|||||||
@ -79,7 +79,7 @@ class ContainerServicesProvider
|
|||||||
$container->instance('worker_id', Framework::$server->worker_id);
|
$container->instance('worker_id', Framework::$server->worker_id);
|
||||||
|
|
||||||
$container->singleton(AdapterInterface::class, OneBot11Adapter::class);
|
$container->singleton(AdapterInterface::class, OneBot11Adapter::class);
|
||||||
$container->singleton(LoggerInterface::class, ZMConfig::get('logging.logger'));
|
$container->instance(LoggerInterface::class, ZMConfig::get('logging.logger')());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -788,10 +788,10 @@ function is_assoc_array(array $array): bool
|
|||||||
/**
|
/**
|
||||||
* 返回 Logger 实例
|
* 返回 Logger 实例
|
||||||
*/
|
*/
|
||||||
function logger(...$args): LoggerInterface
|
function logger(string $prefix = null): LoggerInterface
|
||||||
{
|
{
|
||||||
if (!app()->has(LoggerInterface::class)) {
|
if (!is_null($prefix) || !app()->has(LoggerInterface::class)) {
|
||||||
return zm_config('logging.logger')(...$args);
|
return zm_config('logging.logger')($prefix);
|
||||||
}
|
}
|
||||||
return resolve(LoggerInterface::class);
|
return resolve(LoggerInterface::class);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user