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
12c48d1a
Commit
12c48d1a
authored
Jul 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored logging.
parent
689e5d16
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
38 additions
and
127 deletions
+38
-127
main.php
apps/advanced/backend/config/main.php
+1
-2
main.php
apps/advanced/console/config/main.php
+1
-3
main-local.php
apps/advanced/environments/dev/backend/config/main-local.php
+1
-1
main-local.php
.../advanced/environments/dev/frontend/config/main-local.php
+1
-1
main.php
apps/advanced/frontend/config/main.php
+1
-3
console.php
apps/basic/config/console.php
+1
-2
web.php
apps/basic/config/web.php
+1
-3
Application.php
framework/yii/base/Application.php
+10
-0
Module.php
framework/yii/base/Module.php
+0
-1
classes.php
framework/yii/classes.php
+6
-6
LogTarget.php
framework/yii/debug/LogTarget.php
+1
-1
Module.php
framework/yii/debug/Module.php
+1
-1
Logger.php
framework/yii/log/Logger.php
+13
-5
Router.php
framework/yii/log/Router.php
+0
-98
No files found.
apps/advanced/backend/config/main.php
View file @
12c48d1a
...
...
@@ -27,10 +27,9 @@ return array(
'bundles'
=>
require
(
__DIR__
.
'/assets.php'
),
),
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
array
(
'class'
=>
'yii\log
ging
\FileTarget'
,
'class'
=>
'yii\log\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
...
...
apps/advanced/console/config/main.php
View file @
12c48d1a
...
...
@@ -12,7 +12,6 @@ return array(
'id'
=>
'app-console'
,
'basePath'
=>
dirname
(
__DIR__
),
'vendorPath'
=>
dirname
(
dirname
(
__DIR__
))
.
'/vendor'
,
'preload'
=>
array
(
'log'
),
'controllerNamespace'
=>
'console\controllers'
,
'modules'
=>
array
(
),
...
...
@@ -20,10 +19,9 @@ return array(
'db'
=>
$params
[
'components.db'
],
'cache'
=>
$params
[
'components.cache'
],
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
array
(
'class'
=>
'yii\log
ging
\FileTarget'
,
'class'
=>
'yii\log\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
...
...
apps/advanced/environments/dev/backend/config/main-local.php
View file @
12c48d1a
...
...
@@ -9,7 +9,7 @@ return array(
'log'
=>
array
(
'targets'
=>
array
(
// array(
// 'class' => 'yii\log
ging
\DebugTarget',
// 'class' => 'yii\log\DebugTarget',
// )
),
),
...
...
apps/advanced/environments/dev/frontend/config/main-local.php
View file @
12c48d1a
...
...
@@ -9,7 +9,7 @@ return array(
'log'
=>
array
(
'targets'
=>
array
(
// array(
// 'class' => 'yii\log
ging
\DebugTarget',
// 'class' => 'yii\log\DebugTarget',
// )
),
),
...
...
apps/advanced/frontend/config/main.php
View file @
12c48d1a
...
...
@@ -12,7 +12,6 @@ return array(
'id'
=>
'app-frontend'
,
'basePath'
=>
dirname
(
__DIR__
),
'vendorPath'
=>
dirname
(
dirname
(
__DIR__
))
.
'/vendor'
,
'preload'
=>
array
(
'log'
),
'controllerNamespace'
=>
'frontend\controllers'
,
'modules'
=>
array
(
),
...
...
@@ -27,10 +26,9 @@ return array(
'bundles'
=>
require
(
__DIR__
.
'/assets.php'
),
),
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
array
(
'class'
=>
'yii\log
ging
\FileTarget'
,
'class'
=>
'yii\log\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
...
...
apps/basic/config/console.php
View file @
12c48d1a
...
...
@@ -13,10 +13,9 @@ return array(
'class'
=>
'yii\caching\FileCache'
,
),
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
array
(
'class'
=>
'yii\log
ging
\FileTarget'
,
'class'
=>
'yii\log\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
...
...
apps/basic/config/web.php
View file @
12c48d1a
...
...
@@ -3,7 +3,6 @@
return
array
(
'id'
=>
'bootstrap'
,
'basePath'
=>
dirname
(
__DIR__
),
'preload'
=>
array
(
'log'
),
'components'
=>
array
(
'cache'
=>
array
(
'class'
=>
'yii\caching\FileCache'
,
...
...
@@ -16,10 +15,9 @@ return array(
'bundles'
=>
require
(
__DIR__
.
'/assets.php'
),
),
'log'
=>
array
(
'class'
=>
'yii\logging\Router'
,
'targets'
=>
array
(
array
(
'class'
=>
'yii\log
ging
\FileTarget'
,
'class'
=>
'yii\log\FileTarget'
,
'levels'
=>
array
(
'error'
,
'warning'
),
),
),
...
...
framework/yii/base/Application.php
View file @
12c48d1a
...
...
@@ -141,6 +141,16 @@ abstract class Application extends Module
}
/**
* Loads components that are declared in [[preload]].
* @throws InvalidConfigException if a component or module to be preloaded is unknown
*/
public
function
preloadComponents
()
{
$this
->
getComponent
(
'log'
);
parent
::
preloadComponents
();
}
/**
* Registers error handlers.
*/
public
function
registerErrorHandlers
()
...
...
framework/yii/base/Module.php
View file @
12c48d1a
...
...
@@ -459,7 +459,6 @@ abstract class Module extends Component
if
(
$this
->
_components
[
$id
]
instanceof
Object
)
{
return
$this
->
_components
[
$id
];
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading component:
$id
"
,
__METHOD__
);
return
$this
->
_components
[
$id
]
=
Yii
::
createObject
(
$this
->
_components
[
$id
]);
}
}
...
...
framework/yii/classes.php
View file @
12c48d1a
...
...
@@ -41,12 +41,12 @@ return array(
'yii\web\AssetBundle'
=>
YII_PATH
.
'/web/AssetBundle.php'
,
'yii\web\AssetConverter'
=>
YII_PATH
.
'/web/AssetConverter.php'
,
'yii\web\HeaderCollection'
=>
YII_PATH
.
'/web/HeaderCollection.php'
,
'yii\log\Target'
=>
YII_PATH
.
'/log
ging
/Target.php'
,
'yii\log\DebugTarget'
=>
YII_PATH
.
'/log
ging
/DebugTarget.php'
,
'yii\log\Logger'
=>
YII_PATH
.
'/log
ging
/Logger.php'
,
'yii\log\EmailTarget'
=>
YII_PATH
.
'/log
ging
/EmailTarget.php'
,
'yii\log\DbTarget'
=>
YII_PATH
.
'/log
ging
/DbTarget.php'
,
'yii\log\FileTarget'
=>
YII_PATH
.
'/log
ging
/FileTarget.php'
,
'yii\log\Target'
=>
YII_PATH
.
'/log/Target.php'
,
'yii\log\DebugTarget'
=>
YII_PATH
.
'/log/DebugTarget.php'
,
'yii\log\Logger'
=>
YII_PATH
.
'/log/Logger.php'
,
'yii\log\EmailTarget'
=>
YII_PATH
.
'/log/EmailTarget.php'
,
'yii\log\DbTarget'
=>
YII_PATH
.
'/log/DbTarget.php'
,
'yii\log\FileTarget'
=>
YII_PATH
.
'/log/FileTarget.php'
,
'yii\widgets\ActiveField'
=>
YII_PATH
.
'/widgets/ActiveField.php'
,
'yii\widgets\Captcha'
=>
YII_PATH
.
'/widgets/Captcha.php'
,
'yii\widgets\ListPager'
=>
YII_PATH
.
'/widgets/ListPager.php'
,
...
...
framework/yii/debug/LogTarget.php
View file @
12c48d1a
...
...
@@ -30,7 +30,7 @@ class LogTarget extends Target
if
(
!
is_dir
(
$path
))
{
mkdir
(
$path
);
}
$file
=
$path
.
'/'
.
Yii
::
getLogger
()
->
getTag
()
.
'.log'
;
$file
=
$path
.
'/'
.
Yii
::
$app
->
getLog
()
->
getTag
()
.
'.log'
;
$data
=
array
(
'messages'
=>
$messages
,
'_SERVER'
=>
$_SERVER
,
...
...
framework/yii/debug/Module.php
View file @
12c48d1a
...
...
@@ -39,7 +39,7 @@ class Module extends \yii\base\Module
/** @var View $view */
$id
=
'yii-debug-toolbar'
;
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
'debug/default/toolbar'
,
array
(
'tag'
=>
Yii
::
getLogger
()
->
tag
,
'tag'
=>
Yii
::
$app
->
getLog
()
->
getTag
()
,
));
$view
=
$event
->
sender
;
$view
->
registerJs
(
"yii.debug.load('
$id
', '
$url
');"
);
...
...
framework/yii/log/Logger.php
View file @
12c48d1a
...
...
@@ -7,8 +7,9 @@
namespace
yii\log
;
use
\yii\base\Component
;
use
\yii\base\InvalidConfigException
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\InvalidConfigException
;
/**
* Logger records logged messages in memory and sends them to different targets as needed.
...
...
@@ -141,6 +142,11 @@ class Logger extends Component
public
function
init
()
{
parent
::
init
();
foreach
(
$this
->
targets
as
$name
=>
$target
)
{
if
(
!
$target
instanceof
Target
)
{
$this
->
targets
[
$name
]
=
Yii
::
createObject
(
$target
);
}
}
register_shutdown_function
(
array
(
$this
,
'flush'
),
true
);
}
...
...
@@ -177,13 +183,15 @@ class Logger extends Component
/**
* Flushes log messages from memory to targets.
* This method will trigger an [[EVENT_FLUSH]] or [[EVENT_FINAL_FLUSH]] event depending on the $final value.
* @param boolean $final whether this is a final call during a request.
*/
public
function
flush
(
$final
=
false
)
{
if
(
$this
->
router
)
{
$this
->
router
->
dispatch
(
$this
->
messages
,
$final
);
/** @var Target $target */
foreach
(
$this
->
targets
as
$target
)
{
if
(
$target
->
enabled
)
{
$target
->
collect
(
$this
->
messages
,
$final
);
}
}
$this
->
messages
=
array
();
}
...
...
framework/yii/log/Router.php
deleted
100644 → 0
View file @
689e5d16
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\log
;
use
Yii
;
use
yii\base\Component
;
/**
* Router manages [[Target|log targets]] that record log messages in different media.
*
* For example, a [[FileTarget|file log target]] records log messages
* in files; an [[EmailTarget|email log target]] sends log messages
* to specific email addresses. Each log target may specify filters on
* message levels and categories to record specific messages only.
*
* Router and the targets it manages may be configured in application configuration,
* like the following:
*
* ~~~
* array(
* // preload log component when application starts
* 'preload' => array('log'),
* 'components' => array(
* 'log' => array(
* 'class' => 'yii\log\Router',
* 'targets' => array(
* 'file' => array(
* 'class' => 'yii\log\FileTarget',
* 'levels' => array('trace', 'info'),
* 'categories' => array('yii\*'),
* ),
* 'email' => array(
* 'class' => 'yii\log\EmailTarget',
* 'levels' => array('error', 'warning'),
* 'emails' => array('admin@example.com'),
* ),
* ),
* ),
* ),
* )
* ~~~
*
* Each log target can have a name and can be referenced via the [[targets]] property
* as follows:
*
* ~~~
* Yii::$app->log->targets['file']->enabled = false;
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Router
extends
Component
{
/**
* @var Target[] list of log target objects or configurations. If the latter, target objects will
* be created in [[init()]] by calling [[Yii::createObject()]] with the corresponding object configuration.
*/
public
$targets
=
array
();
/**
* Initializes this application component.
* This method is invoked when the Router component is created by the application.
* The method attaches the [[processLogs]] method to both the [[Logger::EVENT_FLUSH]] event
* and the [[Logger::EVENT_FINAL_FLUSH]] event.
*/
public
function
init
()
{
parent
::
init
();
foreach
(
$this
->
targets
as
$name
=>
$target
)
{
if
(
!
$target
instanceof
Target
)
{
$this
->
targets
[
$name
]
=
Yii
::
createObject
(
$target
);
}
}
Yii
::
getLogger
()
->
router
=
$this
;
}
/**
* Dispatches log messages to [[targets]].
* This method is called by [[Logger]] when its [[Logger::flush()]] method is called.
* It will forward the messages to each log target registered in [[targets]].
* @param array $messages the messages to be processed
* @param boolean $final whether this is the final call during a request cycle
*/
public
function
dispatch
(
$messages
,
$final
=
false
)
{
foreach
(
$this
->
targets
as
$target
)
{
if
(
$target
->
enabled
)
{
$target
->
collect
(
$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