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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
f1316131
Commit
f1316131
authored
May 15, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug toolbar WIP
parent
909bbe62
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
14 deletions
+35
-14
DebugTarget.php
yii/logging/DebugTarget.php
+11
-6
Logger.php
yii/logging/Logger.php
+20
-6
Target.php
yii/logging/Target.php
+4
-2
No files found.
yii/logging/DebugTarget.php
View file @
f1316131
...
@@ -23,6 +23,16 @@ class DebugTarget extends Target
...
@@ -23,6 +23,16 @@ class DebugTarget extends Target
*/
*/
public
function
export
(
$messages
)
public
function
export
(
$messages
)
{
{
$path
=
Yii
::
$app
->
getRuntimePath
()
.
'/debug'
;
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
);
}
$file
=
$path
.
'/'
.
Yii
::
getLogger
()
->
getTag
()
.
'.log'
;
$data
=
array
(
'messages'
=>
$messages
,
'globals'
=>
$GLOBALS
,
);
file_put_contents
(
$file
,
json_encode
(
$data
));
}
}
/**
/**
...
@@ -36,13 +46,8 @@ class DebugTarget extends Target
...
@@ -36,13 +46,8 @@ class DebugTarget extends Target
public
function
collect
(
$messages
,
$final
)
public
function
collect
(
$messages
,
$final
)
{
{
$this
->
messages
=
array_merge
(
$this
->
messages
,
$this
->
filterMessages
(
$messages
));
$this
->
messages
=
array_merge
(
$this
->
messages
,
$this
->
filterMessages
(
$messages
));
$count
=
count
(
$this
->
messages
);
if
(
$final
)
{
if
(
$count
>
0
&&
(
$final
||
$this
->
exportInterval
>
0
&&
$count
>=
$this
->
exportInterval
))
{
if
((
$context
=
$this
->
getContextMessage
())
!==
''
)
{
$this
->
messages
[]
=
array
(
$context
,
Logger
::
LEVEL_INFO
,
'application'
,
YII_BEGIN_TIME
);
}
$this
->
export
(
$this
->
messages
);
$this
->
export
(
$this
->
messages
);
$this
->
messages
=
array
();
}
}
}
}
}
}
yii/logging/Logger.php
View file @
f1316131
...
@@ -82,11 +82,7 @@ class Logger extends Component
...
@@ -82,11 +82,7 @@ class Logger extends Component
* @var Router the log target router registered with this logger.
* @var Router the log target router registered with this logger.
*/
*/
public
$router
;
public
$router
;
/**
* @var string a tag that uniquely identifies the current request. This can be used
* to differentiate the log messages for different requests.
*/
public
$tag
;
/**
/**
* Initializes the logger by registering [[flush()]] as a shutdown function.
* Initializes the logger by registering [[flush()]] as a shutdown function.
...
@@ -94,7 +90,6 @@ class Logger extends Component
...
@@ -94,7 +90,6 @@ class Logger extends Component
public
function
init
()
public
function
init
()
{
{
parent
::
init
();
parent
::
init
();
$this
->
tag
=
date
(
'Ymd-His'
,
microtime
(
true
));
register_shutdown_function
(
array
(
$this
,
'flush'
),
true
);
register_shutdown_function
(
array
(
$this
,
'flush'
),
true
);
}
}
...
@@ -143,6 +138,25 @@ class Logger extends Component
...
@@ -143,6 +138,25 @@ class Logger extends Component
}
}
/**
/**
* @return string a tag that uniquely identifies the current request.
*/
public
function
getTag
()
{
if
(
$this
->
_tag
===
null
)
{
$this
->
_tag
=
date
(
'Ymd-His'
,
microtime
(
true
));
}
return
$this
->
_tag
;
}
/**
* @param string $tag a tag that uniquely identifies the current request.
*/
public
function
setTag
(
$tag
)
{
$this
->
_tag
=
$tag
;
}
/**
* Returns the total elapsed time since the start of the current request.
* Returns the total elapsed time since the start of the current request.
* This method calculates the difference between now and the timestamp
* This method calculates the difference between now and the timestamp
* defined by constant `YII_BEGIN_TIME` which is evaluated at the beginning
* defined by constant `YII_BEGIN_TIME` which is evaluated at the beginning
...
...
yii/logging/Target.php
View file @
f1316131
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
yii\logging
;
namespace
yii\logging
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
...
@@ -109,8 +110,9 @@ abstract class Target extends Component
...
@@ -109,8 +110,9 @@ abstract class Target extends Component
protected
function
getContextMessage
()
protected
function
getContextMessage
()
{
{
$context
=
array
();
$context
=
array
();
if
(
$this
->
logUser
&&
(
$user
=
\Yii
::
$app
->
getComponent
(
'user'
,
false
))
!==
null
)
{
if
(
$this
->
logUser
&&
(
$user
=
Yii
::
$app
->
getComponent
(
'user'
,
false
))
!==
null
)
{
$context
[]
=
'User: '
.
$user
->
getName
()
.
' (ID: '
.
$user
->
getId
()
.
')'
;
/** @var $user \yii\web\User */
$context
[]
=
'User: '
.
$user
->
getId
();
}
}
foreach
(
$this
->
logVars
as
$name
)
{
foreach
(
$this
->
logVars
as
$name
)
{
...
...
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