您现在的位置是:网站首页>亚博足球比分-PHPPHP

Laravel 中自定义日志目录

左鹏2019-07-05 02:34:34PHP232人已围观

简介https://wiki.amateursfuckin.com/articles/7125/custom-log-directory-in-laravel通过以上思路自己写了个公共类如下

https://wiki.amateursfuckin.com/articles/7125/custom-log-directory-in-laravel


通过以上思路自己写了个公共类如下

        // +---------------------------------------------------------------------- // | CreateTime : 2019/7/5 10:46 // +---------------------------------------------------------------------- // | 使用方式:LogCommon::info('info'); or LogCommon::init(['dir'=>'dir'])->info('info'); // +---------------------------------------------------------------------- namespace App\Services\Admin\Common; class LogCommon { //根目录 protected static $pathRoot = 'logs/'; //默认目录 protected static $path = 'admin/'; //自定义文件夹 protected static $dir = ''; /** * @param array $param * @return LogCommon */ public static function init($param = []){ if(isset($param['path'])){ self::$path = $param['path']; } if(isset($param['dir'])){ self::$dir = $param['dir']; } return new self(); } private static function initLog(){ $monolog = \Log::getMonolog(); $monolog->popHandler(); \Log::useDailyFiles(storage_path(self::$pathRoot.self::$path.self::$dir.'info.log')); } public static function info($str=''){ self::initLog(); \Log::info($str); } public static function error($str=''){ self::initLog(); \Log::error($str); } /** * @param string $dir */ public static function setDir(string $dir) { self::$dir = $dir; } /** * @param string $path */ public static function setPath(string $path) { self::$path = $path; } }


站点信息

  • 建站时间:2018-09-18
  • 网站程序:Laravel
  • 主题模板:《今夕何夕》
  • 文章统计:73条
  • 统计数据
  • 微信公众号:扫描二维码,关注我们