Lumen custom error log file and lumen Log File

Source: Internet
Author: User

Lumen custom error log file and lumen Log File

Customize error log files and rebuild new methods

<? Phpnamespace App; use Monolog \ Logger; use Monolog \ Handler \ StreamHandler; use Monolog \ Formatter \ LineFormatter; class LogLib {// define static log instance. protected static $ _ log_instance;/*** Get log instance ** @ 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 callto the object. ** @ param string $ method available methods: debug | info | notice | warning | error | critical | alert | for callable methods of emergency, see Monolog \ Logger class * @ param array $ args call parameter * @ return mixed * @ author Sphenginx */public static function _ callStatic ($ method, $ args) {$ instance = static: getLogInstance (); // organization parameter information $ message = $ args [0]; // record the context log $ context = isset ($ args [1])? $ Args [1]: []; // defines the log file $ path = isset ($ args [2])? $ Args [2]: '/notice/'; // set the log processing handle. The default value is to write files (mail, console, db, redis, and other methods, for details, see the Monolog \ handler directory) $ handler = new StreamHandler (storage_path ($ path ). date ('Y-m-d '). '. log', Logger: toMonologLevel ($ method), $ bubble = true, $ filePermission = 0777); // set the output format LineFormatter (Monolog \ Formatter \ LineFormatter ), ignore context and extra $ handler-> setFormatter (new LineFormatter (null, null, true, true); $ instance-> setHandlers ([$ handler]); $ instance-> $ method ($ message, $ context );}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.