zoukankan      html  css  js  c++  java
  • lumen 自定义错误日志文件

    自定义错误日志文件,改造新的方法

    <?php
    namespace App;
    use MonologLogger;
    use MonologHandlerStreamHandler;
    use MonologFormatterLineFormatter;
    
    class LogLib
    {
        //define static log instance.
        protected static $_log_instance;
        /**
         * 获取log实例
         *
         * @return obj
         * @author Sphenginx
         **/
        public static function getLogInstance()
        {
            if (static::$_log_instance === null) {
                static::$_log_instance = new Logger('NOTICE');
            }
            return static::$_log_instance;
        }
        /**
         * Handle dynamic, static calls to the object.
         *
         * @param  string  $method 可用方法: debug|info|notice|warning|error|critical|alert|emergency 可调用的方法详见 MonologLogger 类
         * @param  array   $args 调用参数
         * @return mixed
         * @author Sphenginx
         */
        public static function __callStatic($method, $args)
        {
            $instance = static::getLogInstance();
            //组织参数信息
            $message = $args[0];
            //记录上下文日志
            $context = isset($args[1]) ? $args[1] : [];
            //定义记录日志文件
            $path    = isset($args[2]) ? $args[2] : '/notice/';
            //设置日志处理手柄,默认为写入文件(还有mail、console、db、redis等方式,详见Monologhandler 目录)
            $handler = new StreamHandler(storage_path($path) . date('Y-m-d').'.log', Logger::toMonologLevel($method), $bubble = true, $filePermission = 0777);
            //设置输出格式LineFormatter(MonologFormatterLineFormatter), ignore context and extra
            $handler->setFormatter(new LineFormatter(null, null, true, true));
            $instance->setHandlers([$handler]);
            $instance->$method($message, $context);
        }
    }
  • 相关阅读:
    python基础集结号
    3,jieba gensim 最好别分家之最简单的相似度实现
    2,PyAudio 实现录音 自动化交互实现问答
    1,百度云接口
    16,Flask-Migrate
    移动端web开发 尽量哪些标签 常用标签及注意事项
    flex布局
    -webkit-box
    网页图片jpg,gif,png对比。
    原生判断是否存在某个类,手机端事件,手机端测试
  • 原文地址:https://www.cnblogs.com/rcltocode/p/7246568.html
Copyright © 2011-2022 走看看