【Laravel3.0.0源码阅读分析】日志类log.php
作者:互联网
<?php namespace Laravel;
// 日志类
class Log {
/**
* Log an exception to the log file.
* 将异常记录到日志文件中。
* @param Exception $e
* @return void
*/
public static function exception($e)
{
static::write('error', static::format($e));
}
/**
* Format a log friendly message from the given exception.
* 从给定的异常格式化日志友好消息。
* @param Exception $e
* @return string
*/
protected static function format($e)
{
return $e->getMessage().' in '.$e->getFile().' on line '.$e->getLine();
}
/**
* Write a message to the log file.
* 将消息写入日志文件。
* <code>
* // Write an "error" messge to the log file
* Log::write('error', 'Something went horribly wrong!');
*
* // Write an "error" message using the class' magic method
* Log::error('Something went horribly wrong!');
* </code>
*
* @param string $type
* @param string $message
* @return void
*/
public static function write($type, $message)
{
$message = date('Y-m-d H:i:s').' '.Str::upper($type)." - {$message}".PHP_EOL;
File::append(path('storage').'logs/'.date('Y-m-d').'.log', $message);
}
/**
* Dynamically write a log message.
* 动态写日志消息。
* <code>
* // Write an "error" message to the log file
* Log::error('This is an error!');
*
* // Write a "warning" message to the log file
* Log::warning('This is a warning!');
* </code>
*/
public static function __callStatic($method, $parameters)
{
static::write($method, $parameters[0]);
}
}
github地址: https://github.com/liu-shilong/laravel3-scr
标签:log,Laravel3.0,Write,源码,file,error,message,Log 来源: https://blog.csdn.net/qq2942713658/article/details/117383921