PHP 클래스 yii\log\Logger

A Logger instance can be accessed via Yii::getLogger(). You can call the method Logger::log to record a single log message. For convenience, a set of shortcut methods are provided for logging messages of various severity levels via the [[Yii]] class: - [[Yii::trace()]] - [[Yii::error()]] - [[Yii::warning()]] - [[Yii::info()]] - [[Yii::beginProfile()]] - [[Yii::endProfile()]] For more details and usage information on Logger, see the guide article on logging. When the application ends or [[flushInterval]] is reached, Logger will call Logger::flush to send logged messages to different log targets, such as [[FileTarget|file]], [[EmailTarget|email]], or [[DbTarget|database]], with the help of the [[dispatcher]].
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends yii\base\Component
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$dispatcher the message dispatcher
$flushInterval how many messages should be logged before they are flushed from memory and sent to targets. Defaults to 1000, meaning the [[flush]] method will be invoked once every 1000 messages logged. Set this property to be 0 if you don't want to flush messages until the application terminates. This property mainly affects how much memory will be taken by the logged messages. A smaller value means less memory, but will increase the execution time due to the overhead of Logger::flush.
$messages logged messages. This property is managed by Logger::log and Logger::flush. Each log message is of the following structure: [ [0] => message (mixed, can be a string or some complex data, such as an exception object) [1] => level (integer) [2] => category (string) [3] => timestamp (float, obtained by microtime(true)) [4] => traces (array, debug backtrace, contains the application code call stacks) ]
$traceLevel how much call stack information (file name and line number) should be logged for each message. If it is greater than 0, at most that number of call stacks will be logged. Note that only application call stacks are counted.

공개 메소드들

메소드 설명
calculateTimings ( array $messages ) : array Calculates the elapsed time for the given log messages.
flush ( boolean $final = false ) Flushes log messages from memory to targets.
getDbProfiling ( ) : array Returns the statistical results of DB queries.
getElapsedTime ( ) : float Returns the total elapsed time since the start of the current request.
getLevelName ( integer $level ) : string Returns the text display of the specified level.
getProfiling ( array $categories = [], array $excludeCategories = [] ) : array Returns the profiling results.
init ( ) Initializes the logger by registering Logger::flush as a shutdown function.
log ( string | array $message, integer $level, string $category = 'application' ) Logs a message with the given type and category.

메소드 상세

calculateTimings() 공개 메소드

Calculates the elapsed time for the given log messages.
public calculateTimings ( array $messages ) : array
$messages array the log messages obtained from profiling
리턴 array timings. Each element is an array consisting of these elements: `info`, `category`, `timestamp`, `trace`, `level`, `duration`.

flush() 공개 메소드

Flushes log messages from memory to targets.
public flush ( boolean $final = false )
$final boolean whether this is a final call during a request.

getDbProfiling() 공개 메소드

The results returned include the number of SQL statements executed and the total time spent.
public getDbProfiling ( ) : array
리턴 array the first element indicates the number of SQL statements executed, and the second element the total time spent in SQL execution.

getElapsedTime() 공개 메소드

This method calculates the difference between now and the timestamp defined by constant YII_BEGIN_TIME which is evaluated at the beginning of BaseYii class file.
public getElapsedTime ( ) : float
리턴 float the total elapsed time in seconds for current request.

getLevelName() 공개 정적인 메소드

Returns the text display of the specified level.
public static getLevelName ( integer $level ) : string
$level integer the message level, e.g. [[LEVEL_ERROR]], [[LEVEL_WARNING]].
리턴 string the text display of the level

getProfiling() 공개 메소드

By default, all profiling results will be returned. You may provide $categories and $excludeCategories as parameters to retrieve the results that you are interested in.
public getProfiling ( array $categories = [], array $excludeCategories = [] ) : array
$categories array list of categories that you are interested in. You can use an asterisk at the end of a category to do a prefix match. For example, 'yii\db\*' will match categories starting with 'yii\db\', such as 'yii\db\Connection'.
$excludeCategories array list of categories that you want to exclude
리턴 array the profiling results. Each element is an array consisting of these elements: `info`, `category`, `timestamp`, `trace`, `level`, `duration`.

init() 공개 메소드

Initializes the logger by registering Logger::flush as a shutdown function.
public init ( )

log() 공개 메소드

If [[traceLevel]] is greater than 0, additional call stack information about the application code will be logged as well.
public log ( string | array $message, integer $level, string $category = 'application' )
$message string | array the message to be logged. This can be a simple string or a more complex data structure that will be handled by a [[Target|log target]].
$level integer the level of the message. This must be one of the following: `Logger::LEVEL_ERROR`, `Logger::LEVEL_WARNING`, `Logger::LEVEL_INFO`, `Logger::LEVEL_TRACE`, `Logger::LEVEL_PROFILE_BEGIN`, `Logger::LEVEL_PROFILE_END`.
$category string the category of the message.

프로퍼티 상세

$dispatcher 공개적으로 프로퍼티

the message dispatcher
public $dispatcher

$flushInterval 공개적으로 프로퍼티

how many messages should be logged before they are flushed from memory and sent to targets. Defaults to 1000, meaning the [[flush]] method will be invoked once every 1000 messages logged. Set this property to be 0 if you don't want to flush messages until the application terminates. This property mainly affects how much memory will be taken by the logged messages. A smaller value means less memory, but will increase the execution time due to the overhead of Logger::flush.
public $flushInterval

$messages 공개적으로 프로퍼티

logged messages. This property is managed by Logger::log and Logger::flush. Each log message is of the following structure: [ [0] => message (mixed, can be a string or some complex data, such as an exception object) [1] => level (integer) [2] => category (string) [3] => timestamp (float, obtained by microtime(true)) [4] => traces (array, debug backtrace, contains the application code call stacks) ]
public $messages

$traceLevel 공개적으로 프로퍼티

how much call stack information (file name and line number) should be logged for each message. If it is greater than 0, at most that number of call stacks will be logged. Note that only application call stacks are counted.
public $traceLevel