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
e54fc6f4
Commit
e54fc6f4
authored
Jul 17, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`yii\mongodb\log\MongoDbTarget` log target added
parent
61b627a6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
1 deletion
+75
-1
CHANGELOG.md
extensions/mongodb/CHANGELOG.md
+1
-0
MongoDbTarget.php
extensions/mongodb/log/MongoDbTarget.php
+72
-0
DbTarget.php
framework/log/DbTarget.php
+2
-1
No files found.
extensions/mongodb/CHANGELOG.md
View file @
e54fc6f4
...
...
@@ -10,6 +10,7 @@ Yii Framework 2 mongodb extension Change Log
-
Enh #3778: Gii generator for Active Record model added (klimov-paul)
-
Enh #3947: Migration support added (klimov-paul)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
-
Enh #4335:
`yii\mongodb\log\MongoDbTarget`
log target added (klimov-paul)
2.0.0-beta April 13, 2014
...
...
extensions/mongodb/log/MongoDbTarget.php
0 → 100644
View file @
e54fc6f4
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\mongodb\log
;
use
yii\base\InvalidConfigException
;
use
yii\di\Instance
;
use
yii\helpers\VarDumper
;
use
yii\log\Target
;
use
yii\mongodb\Connection
;
/**
* MongoDbTarget stores log messages in a MongoDB collection.
*
* By default, MongoDbTarget stores the log messages in a MongoDB collection named 'log'.
* The collection can be changed by setting the [[logCollection]] property.
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
MongoDbTarget
extends
Target
{
/**
* @var Connection|string the MongoDB connection object or the application component ID of the MongoDB connection.
* After the MongoDbTarget object is created, if you want to change this property, you should only assign it
* with a MongoDB connection object.
*/
public
$db
=
'mongodb'
;
/**
* @var string|array the name of the MongoDB collection that stores the session data.
* Please refer to [[Connection::getCollection()]] on how to specify this parameter.
* This collection is better to be pre-created with fields 'id' and 'expire' indexed.
*/
public
$logCollection
=
'log'
;
/**
* Initializes the MongoDbTarget component.
* This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection.
* @throws InvalidConfigException if [[db]] is invalid.
*/
public
function
init
()
{
parent
::
init
();
$this
->
db
=
Instance
::
ensure
(
$this
->
db
,
Connection
::
className
());
}
/**
* Stores log messages to MongoDB collection.
*/
public
function
export
()
{
$collection
=
$this
->
db
->
getCollection
(
$this
->
logCollection
);
foreach
(
$this
->
messages
as
$message
)
{
list
(
$text
,
$level
,
$category
,
$timestamp
)
=
$message
;
if
(
!
is_string
(
$text
))
{
$text
=
VarDumper
::
export
(
$text
);
}
$collection
->
insert
([
'level'
=>
$level
,
'category'
=>
$category
,
'log_time'
=>
$timestamp
,
'prefix'
=>
$this
->
getMessagePrefix
(
$message
),
'message'
=>
$text
,
]);
}
}
}
\ No newline at end of file
framework/log/DbTarget.php
View file @
e54fc6f4
...
...
@@ -11,6 +11,7 @@ use Yii;
use
yii\db\Connection
;
use
yii\base\InvalidConfigException
;
use
yii\di\Instance
;
use
yii\helpers\VarDumper
;
/**
* DbTarget stores log messages in a database table.
...
...
@@ -80,7 +81,7 @@ class DbTarget extends Target
foreach
(
$this
->
messages
as
$message
)
{
list
(
$text
,
$level
,
$category
,
$timestamp
)
=
$message
;
if
(
!
is_string
(
$text
))
{
$text
=
var_export
(
$text
,
true
);
$text
=
VarDumper
::
export
(
$text
);
}
$command
->
bindValues
([
':level'
=>
$level
,
...
...
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