Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
41ba44b7
Commit
41ba44b7
authored
Jan 20, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adjusted logger event.
parent
fb75c958
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
11 deletions
+23
-11
Logger.php
framework/logging/Logger.php
+18
-4
Router.php
framework/logging/Router.php
+5
-7
No files found.
framework/logging/Logger.php
View file @
41ba44b7
...
@@ -25,9 +25,13 @@ use yii\base\Exception;
...
@@ -25,9 +25,13 @@ use yii\base\Exception;
class
Logger
extends
\yii\base\Component
class
Logger
extends
\yii\base\Component
{
{
/**
/**
* @event Event an event that is triggered when
messages are being flushed from memory to targets
* @event Event an event that is triggered when
[[flush()]] is called.
*/
*/
const
EVENT_FLUSH
=
'flush'
;
const
EVENT_FLUSH
=
'flush'
;
/**
* @event Event an event that is triggered when [[flush()]] is called at the end of application.
*/
const
EVENT_FINAL_FLUSH
=
'finalFlush'
;
/**
/**
* Error message level. An error message is one that indicates the abnormal termination of the
* Error message level. An error message is one that indicates the abnormal termination of the
...
@@ -88,6 +92,15 @@ class Logger extends \yii\base\Component
...
@@ -88,6 +92,15 @@ class Logger extends \yii\base\Component
public
$messages
=
array
();
public
$messages
=
array
();
/**
/**
* Initializes the logger by registering [[flush()]] as a shutdown function.
*/
public
function
init
()
{
parent
::
init
();
register_shutdown_function
(
array
(
$this
,
'flush'
),
true
);
}
/**
* Logs a message with the given type and category.
* Logs a message with the given type and category.
* If `YII_DEBUG` is true and `YII_TRACE_LEVEL` is greater than 0, then additional
* If `YII_DEBUG` is true and `YII_TRACE_LEVEL` is greater than 0, then additional
* call stack information about application code will be appended to the message.
* call stack information about application code will be appended to the message.
...
@@ -120,11 +133,12 @@ class Logger extends \yii\base\Component
...
@@ -120,11 +133,12 @@ class Logger extends \yii\base\Component
/**
/**
* Flushes log messages from memory to targets.
* Flushes log messages from memory to targets.
* This method will trigger a [[flush]] event.
* This method will trigger a [[flush]] or [[finalFlush]] event depending on the $final value.
* @param boolean $final whether this is a final call during a request.
*/
*/
public
function
flush
()
public
function
flush
(
$final
=
false
)
{
{
$this
->
trigger
(
'flush'
);
$this
->
trigger
(
$final
?
'finalFlush'
:
'flush'
);
$this
->
messages
=
array
();
$this
->
messages
=
array
();
}
}
...
...
framework/logging/Router.php
View file @
41ba44b7
...
@@ -83,23 +83,21 @@ class Router extends Component
...
@@ -83,23 +83,21 @@ class Router extends Component
}
}
Yii
::
getLogger
()
->
on
(
Logger
::
EVENT_FLUSH
,
array
(
$this
,
'processMessages'
));
Yii
::
getLogger
()
->
on
(
Logger
::
EVENT_FLUSH
,
array
(
$this
,
'processMessages'
));
if
(
Yii
::
$application
!==
null
)
{
Yii
::
getLogger
()
->
on
(
Logger
::
EVENT_FINAL_FLUSH
,
array
(
$this
,
'processMessages'
));
Yii
::
$application
->
on
(
Application
::
EVENT_AFTER_REQUEST
,
array
(
$this
,
'processMessages'
));
}
}
}
/**
/**
* Retrieves and processes log messages from the system logger.
* Retrieves and processes log messages from the system logger.
* This method mainly serves the event handler to [[Logger::
onF
lush]]
* This method mainly serves the event handler to [[Logger::
f
lush]]
* and [[Application::
onE
ndRequest]] events.
* and [[Application::
e
ndRequest]] events.
* It will retrieve the available log messages from the [[Yii::getLogger|system logger]]
* It will retrieve the available log messages from the [[Yii::getLogger
()
|system logger]]
* and invoke the registered [[targets|log targets]] to do the actual processing.
* and invoke the registered [[targets|log targets]] to do the actual processing.
* @param \yii\base\Event $event event parameter
* @param \yii\base\Event $event event parameter
*/
*/
public
function
processMessages
(
$event
)
public
function
processMessages
(
$event
)
{
{
$messages
=
Yii
::
getLogger
()
->
messages
;
$messages
=
Yii
::
getLogger
()
->
messages
;
$final
=
$event
->
name
===
Application
::
EVENT_AFTER_REQUEST
;
$final
=
$event
->
name
===
Logger
::
EVENT_FINAL_FLUSH
;
foreach
(
$this
->
targets
as
$target
)
{
foreach
(
$this
->
targets
as
$target
)
{
if
(
$target
->
enabled
)
{
if
(
$target
->
enabled
)
{
$target
->
processMessages
(
$messages
,
$final
);
$target
->
processMessages
(
$messages
,
$final
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment