您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-日志-通道
发布时间:2022-01-29 20:21:08编辑:雪饮阅读()
上篇中咱們用的日志寫入使用的是默認的default通道,那麽通道配置在config/log.php,例如我們現在新增一個log2的通道后則log.php中的内容如:
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
return [
'default' => [
'handlers' => [
[
'class' => Monolog\Handler\RotatingFileHandler::class,
'constructor' => [
runtime_path() . '/logs/webman.log',
7, //$maxFiles
Monolog\Logger::DEBUG,
],
'formatter' => [
'class' => Monolog\Formatter\LineFormatter::class,
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
// log2通道
'log2' => [
// 处理默认通道的handler,可以设置多个
'handlers' => [
[
// handler类的名字
'class' => Monolog\Handler\RotatingFileHandler::class,
// handler类的构造函数参数
'constructor' => [
runtime_path() . '/logs/log2.log',
Monolog\Logger::DEBUG,
],
// 格式相关
'formatter' => [
// 格式化处理类的名字
'class' => Monolog\Formatter\LineFormatter::class,
// 格式化处理类的构造函数参数
'constructor' => [ null, 'Y-m-d H:i:s', true],
],
]
],
],
];
然後使用該log2通道是在控制器Foo.php中實現如:
<?php
namespace app\controller;
use support\Request;
use support\View;
use support\Log;
class Foo
{
/**
* 该方法会在请求前调用
*/
public function beforeAction(Request $request)
{
echo 'beforeAction';
// 若果想终止执行Action就直接返回Response对象,不想终止则无需return
// return response('终止执行Action');
}
/**
* 该方法会在请求后调用
*/
public function afterAction(Request $request, $response)
{
}
public function index0(){
throw new \Exception("異常出現了!");
}
public function index(Request $request)
{
$level="DEBUG";
$message="騙你玩玩!";
$context=["title"=>"出事了,出大事了!","content"=>"其實也沒有什麽大事啦!"];
$log = Log::channel('log2');
$log->log($level, $message, $context);
$log->debug($message, $context);
$log->info($message,$context);
$log->notice($message, $context);
$log->warning($message, $context);
$log->error($message,$context);
$log->critical($message,$context);
$log->alert($message,$context);
$log->emergency($message, $context);
return response('hello index');
}
public function login(Request $request)
{
$session = $request->session();
$session->set('userinfo', ["user_name"=>"kasumi"]);
return response('login success');
}
public function loginPage(Request $request){
return response("this is loginPage \n");
}
}
那麽該實例運行后被訪問時:
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/index --dump
hello index
[root@localhost ~]# cat /www/wwwroot/webman/webman/runtime/logs/log2-2022-01-29.log
[2022-01-29 20:17:42] log2.DEBUG: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.DEBUG: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.INFO: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.NOTICE: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.WARNING: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.ERROR: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.CRITICAL: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.ALERT: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
[2022-01-29 20:17:42] log2.EMERGENCY: 騙你玩玩! {"title":"出事了,出大事了!","content":"其實也沒有什麽大事啦!"} []
关键字词:webman,日志,通道
上一篇:webman-日志-提供的方法
下一篇:webman-多應用
相关文章
- webman-日志-提供的方法
- webman-日志-使用
- webman-session管理-配置文件-更換session驅動為redis
- webman-session管理-配置文件-redis集群搭建(單宿主機
- webman-session管理-配置文件-更換session驅動為redis
- webman-session管理-助手函数session()-給session賦值
- webman-session管理-助手函数session()-獲取某個值
- webman-session管理-助手函数session()-session實例獲
- webman-session管理-判断对应session数据是否存在
- webman-session管理-删除所有session数据