From e5d73a372e2f71fba5bd5d7c471072e72bc4197d Mon Sep 17 00:00:00 2001 From: zhao Date: Wed, 11 Mar 2020 20:20:59 +0800 Subject: [PATCH] login browse log --- app/common/model/User.php | 2 ++ app/index/middleware.php | 1 + app/middleware/Browse.php | 17 +++++++++++++++++ config/log.php | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 app/middleware/Browse.php diff --git a/app/common/model/User.php b/app/common/model/User.php index 5102c79..6718e01 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -5,6 +5,7 @@ use think\Model; use think\model\concern\SoftDelete; use think\facade\Db; use think\facade\Session; +use think\facade\Log; use taoler\com\Api; class User extends Model @@ -70,6 +71,7 @@ class User extends Model 'last_login_time' => time() ] ); + Log::channel('login')->info('login:{user} {ip}:{city}',['user'=>$user['name'],'ip'=>$ip,'city'=>$city]); //查询结果1表示有用户,用户名密码正确 return 1; diff --git a/app/index/middleware.php b/app/index/middleware.php index 2e1f495..3cdfe4f 100644 --- a/app/index/middleware.php +++ b/app/index/middleware.php @@ -2,6 +2,7 @@ return [ \app\middleware\Install::class, + \app\middleware\Browse::class, //app\middleware\LoginCheck::class, //app\middleware\CheckRegister::class, //'logedcheck' => \app\middleware\logedCheck::class, diff --git a/app/middleware/Browse.php b/app/middleware/Browse.php new file mode 100644 index 0000000..b919d1b --- /dev/null +++ b/app/middleware/Browse.php @@ -0,0 +1,17 @@ +info('browse:{agent} {ip} {url}',['agent'=>$agent,'url'=>$url,'ip'=>$ip]); + return $next($request); + } +} diff --git a/config/log.php b/config/log.php index ea24ff9..ef8af09 100644 --- a/config/log.php +++ b/config/log.php @@ -40,6 +40,38 @@ return [ 'realtime_write' => false, ], // 其它日志通道配置 + 'login' => [ + // 日志记录方式 + 'type' => 'File', + // 日志保存目录 + 'path' => '../runtime/log/login/', + // 单文件日志写入 + 'single' => false, + // 最大日志文件数量 + 'max_files' => 0, + // 日志处理 + 'processor' => null, + // 日志输出格式化 + 'format' => '[%s][%s] %s', + // 是否实时写入 + 'realtime_write' => true, + ], + 'browse' => [ + // 日志记录方式 + 'type' => 'File', + // 日志保存目录 + 'path' => '../runtime/log/browse/', + // 单文件日志写入 + 'single' => false, + // 最大日志文件数量 + 'max_files' => 0, + // 日志处理 + 'processor' => null, + // 日志输出格式化 + 'format' => '[%s][%s] %s', + // 是否实时写入 + 'realtime_write' => true, + ], ], ];