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
e96fd0ea
Commit
e96fd0ea
authored
May 15, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug tool bar WIP
parent
490c57f5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
9 deletions
+101
-9
main.php
apps/bootstrap/protected/config/main.php
+7
-4
yii.debug.js
yii/assets/yii.debug.js
+1
-1
Toolbar.php
yii/debug/Toolbar.php
+2
-3
DefaultController.php
yii/debug/controllers/DefaultController.php
+13
-0
toolbar.php
yii/debug/views/default/toolbar.php
+39
-0
DebugTarget.php
yii/logging/DebugTarget.php
+39
-1
No files found.
apps/bootstrap/protected/config/main.php
View file @
e96fd0ea
...
@@ -5,9 +5,9 @@ return array(
...
@@ -5,9 +5,9 @@ return array(
'basePath'
=>
dirname
(
__DIR__
),
'basePath'
=>
dirname
(
__DIR__
),
'preload'
=>
array
(
'log'
),
'preload'
=>
array
(
'log'
),
'modules'
=>
array
(
'modules'
=>
array
(
'debug'
=>
array
(
//
'debug' => array(
'class'
=>
'yii\debug\Module'
,
//
'class' => 'yii\debug\Module',
)
//
)
),
),
'components'
=>
array
(
'components'
=>
array
(
'cache'
=>
array
(
'cache'
=>
array
(
...
@@ -23,10 +23,13 @@ return array(
...
@@ -23,10 +23,13 @@ return array(
'log'
=>
array
(
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
'targets'
=>
array
(
'file'
=>
array
(
array
(
'class'
=>
'yii\logging\FileTarget'
,
'class'
=>
'yii\logging\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
// array(
// 'class' => 'yii\logging\DebugTarget',
// )
),
),
),
),
),
),
...
...
yii/assets/yii.debug.js
View file @
e96fd0ea
...
@@ -18,7 +18,7 @@ yii.debug = (function ($) {
...
@@ -18,7 +18,7 @@ yii.debug = (function ($) {
//dataType: 'json',
//dataType: 'json',
success
:
function
(
data
)
{
success
:
function
(
data
)
{
var
$e
=
$
(
'#'
+
id
);
var
$e
=
$
(
'#'
+
id
);
$e
.
html
(
data
);
$e
.
html
(
data
)
.
show
()
;
}
}
});
});
}
}
...
...
yii/debug/Toolbar.php
View file @
e96fd0ea
...
@@ -17,12 +17,11 @@ use yii\helpers\Html;
...
@@ -17,12 +17,11 @@ use yii\helpers\Html;
*/
*/
class
Toolbar
extends
Widget
class
Toolbar
extends
Widget
{
{
public
$debugAction
=
'debug'
;
public
$debugAction
=
'debug/default/toolbar'
;
public
$enabled
=
YII_DEBUG
;
public
function
run
()
public
function
run
()
{
{
if
(
$this
->
enabled
)
{
if
(
Yii
::
$app
->
hasModule
(
'debug'
)
)
{
$id
=
'yii-debug-toolbar'
;
$id
=
'yii-debug-toolbar'
;
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$this
->
debugAction
,
array
(
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$this
->
debugAction
,
array
(
'tag'
=>
Yii
::
getLogger
()
->
tag
,
'tag'
=>
Yii
::
getLogger
()
->
tag
,
...
...
yii/debug/controllers/DefaultController.php
View file @
e96fd0ea
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
yii\debug\controllers
;
namespace
yii\debug\controllers
;
use
Yii
;
use
yii\web\Controller
;
use
yii\web\Controller
;
/**
/**
...
@@ -19,4 +20,15 @@ class DefaultController extends Controller
...
@@ -19,4 +20,15 @@ class DefaultController extends Controller
{
{
echo
$tag
;
echo
$tag
;
}
}
public
function
actionToolbar
(
$tag
)
{
$file
=
Yii
::
$app
->
getRuntimePath
()
.
"/debug/
$tag
.log"
;
if
(
preg_match
(
'/^[\w\-]+$/'
,
$tag
)
&&
is_file
(
$file
))
{
$data
=
json_decode
(
file_get_contents
(
$file
),
true
);
echo
$this
->
renderPartial
(
'toolbar'
,
$data
);
}
else
{
echo
"Unable to find debug data tagged with '
$tag
'."
;
}
}
}
}
\ No newline at end of file
yii/debug/views/default/toolbar.php
0 → 100644
View file @
e96fd0ea
<?php
use
yii\helpers\Html
;
echo
Html
::
style
(
"
#yii-debug-toolbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background-color: #eee;
border-top: 1px solid #ccc;
margin: 0;
padding: 5px 10px;
z-index: 1000000;
font: 11px Verdana, Arial, sans-serif;
text-align: left;
}
.yii-debug-toolbar-block {
float: left;
margin: 0 10px;
"
);
?>
<div
class=
"yii-debug-toolbar-block"
>
</div>
<div
class=
"yii-debug-toolbar-block"
>
Peak memory:
<?php
echo
sprintf
(
'%.2fMB'
,
$memory
/
1048576
);
?>
</div>
<div
class=
"yii-debug-toolbar-block"
>
Time spent:
<?php
echo
sprintf
(
'%.3fs'
,
$time
);
?>
</div>
<div
class=
"yii-debug-toolbar-block"
>
</div>
<div
class=
"yii-debug-toolbar-block"
>
</div>
yii/logging/DebugTarget.php
View file @
e96fd0ea
...
@@ -15,6 +15,8 @@ use Yii;
...
@@ -15,6 +15,8 @@ use Yii;
*/
*/
class
DebugTarget
extends
Target
class
DebugTarget
extends
Target
{
{
public
$maxLogFiles
=
20
;
/**
/**
* Exports log messages to a specific destination.
* Exports log messages to a specific destination.
* Child classes must implement this method.
* Child classes must implement this method.
...
@@ -30,7 +32,14 @@ class DebugTarget extends Target
...
@@ -30,7 +32,14 @@ class DebugTarget extends Target
$file
=
$path
.
'/'
.
Yii
::
getLogger
()
->
getTag
()
.
'.log'
;
$file
=
$path
.
'/'
.
Yii
::
getLogger
()
->
getTag
()
.
'.log'
;
$data
=
array
(
$data
=
array
(
'messages'
=>
$messages
,
'messages'
=>
$messages
,
'globals'
=>
$GLOBALS
,
'_SERVER'
=>
$_SERVER
,
'_GET'
=>
$_GET
,
'_POST'
=>
$_POST
,
'_COOKIE'
=>
$_COOKIE
,
'_FILES'
=>
empty
(
$_FILES
)
?
array
()
:
$_FILES
,
'_SESSION'
=>
empty
(
$_SESSION
)
?
array
()
:
$_SESSION
,
'memory'
=>
memory_get_peak_usage
(),
'time'
=>
microtime
(
true
)
-
YII_BEGIN_TIME
,
);
);
file_put_contents
(
$file
,
json_encode
(
$data
));
file_put_contents
(
$file
,
json_encode
(
$data
));
}
}
...
@@ -45,9 +54,38 @@ class DebugTarget extends Target
...
@@ -45,9 +54,38 @@ class DebugTarget extends Target
*/
*/
public
function
collect
(
$messages
,
$final
)
public
function
collect
(
$messages
,
$final
)
{
{
if
(
Yii
::
$app
->
getModule
(
'debug'
,
false
)
!==
null
)
{
return
;
}
$this
->
messages
=
array_merge
(
$this
->
messages
,
$this
->
filterMessages
(
$messages
));
$this
->
messages
=
array_merge
(
$this
->
messages
,
$this
->
filterMessages
(
$messages
));
if
(
$final
)
{
if
(
$final
)
{
$this
->
export
(
$this
->
messages
);
$this
->
export
(
$this
->
messages
);
$this
->
gc
();
}
}
protected
function
gc
()
{
if
(
mt_rand
(
0
,
10000
)
>
100
)
{
return
;
}
$iterator
=
new
\DirectoryIterator
(
Yii
::
$app
->
getRuntimePath
()
.
'/debug'
);
$files
=
array
();
foreach
(
$iterator
as
$file
)
{
if
(
preg_match
(
'/^[\d\-]+\.log$/'
,
$file
->
getFileName
())
&&
$file
->
isFile
())
{
$files
[]
=
$file
->
getPathname
();
}
}
sort
(
$files
);
if
(
count
(
$files
)
>
$this
->
maxLogFiles
)
{
$n
=
count
(
$files
)
-
$this
->
maxLogFiles
;
foreach
(
$files
as
$i
=>
$file
)
{
if
(
$i
<
$n
)
{
unlink
(
$file
);
}
else
{
break
;
}
}
}
}
}
}
}
}
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