-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#==============================================================# | ||
# Composer dependencies are used for development comfort only. # | ||
# They should always be ignored in the repository. # | ||
#=============================================================== | ||
|
||
.idea/ | ||
vendor/ | ||
composer.lock | ||
tests/_log/* | ||
tests/_output/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013-2014 Ivan Koptiev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace kop\y2le; | ||
|
||
use Monolog\Handler\LogEntriesHandler; | ||
use Monolog\Logger; | ||
use yii\base\InvalidCallException; | ||
use yii\log\Logger as YiiLogger; | ||
use yii\log\Target; | ||
|
||
/** | ||
* LogentriesTarget sends log messages to the [Logentries log management service](https://logentries.com/). | ||
* | ||
* The log destination is specified via [[logToken]] property. Please refer to | ||
* [Logentries docs for PHP applications](https://logentries.com/doc/php/) for more details. | ||
* | ||
* @link http://kop.github.io/yii2-logentries Y2LE project page. | ||
* @license https://github.com/kop/yii2-logentries/blob/master/LICENSE.md MIT | ||
* | ||
* @author Ivan Koptiev <[email protected]> | ||
* @version 1.0.0 | ||
*/ | ||
class LogentriesTarget extends Target | ||
{ | ||
/** | ||
* @var string $accessToken Logentries log token. | ||
* @see https://logentries.com/doc/php/ | ||
*/ | ||
public $logToken; | ||
|
||
/** | ||
* @var array $_monologLevels Monolog messages levels. | ||
*/ | ||
private $_monologLevels = [ | ||
YiiLogger::LEVEL_TRACE => Logger::INFO, | ||
YiiLogger::LEVEL_INFO => Logger::INFO, | ||
YiiLogger::LEVEL_WARNING => Logger::WARNING, | ||
YiiLogger::LEVEL_ERROR => Logger::ERROR | ||
]; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
// Make sure log token is given | ||
if (empty($this->logToken)) { | ||
$className = get_class($this); | ||
throw new InvalidCallException("{$className} requires \"\$logToken\" attribute to be set."); | ||
} | ||
} | ||
|
||
/** | ||
* Writes log messages to a LogEntriesHandler Monolog handler. | ||
*/ | ||
public function export() | ||
{ | ||
$monolog = new Logger('Logentries'); | ||
$monolog->pushHandler(new LogEntriesHandler($this->logToken)); | ||
|
||
foreach ($this->messages as $message) { | ||
if (array_key_exists($message[1], $this->_monologLevels)) { | ||
$monolog->addRecord($this->_monologLevels[$message[1]], $this->formatMessage($message), $message[4]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Yii2 Logentries | ||
=============== | ||
|
||
[Yii2 Logentries (Y2LE)](http://kop.github.io/yii2-logentries) adds a `LogentriesTarget` class that sends Yii2 log | ||
messages to the [Logentries log management service](https://logentries.com/). | ||
|
||
## Requirements | ||
|
||
- Yii 2.0 (dev-master) | ||
- PHP 5.4 | ||
|
||
> Note: | ||
This extension mandatorily requires [Yii Framework 2](https://github.com/yiisoft/yii2). | ||
The framework is under active development and the first stable release of Yii 2 is expected in early 2014. | ||
|
||
|
||
## Installation | ||
|
||
The preferred way to install this extension is through [Composer](http://getcomposer.org/). | ||
|
||
Either run | ||
|
||
``` php composer.phar require kop/yii2-logentries "dev-master" ``` | ||
|
||
or add | ||
|
||
``` "kop/yii2-logentries": "dev-master"``` | ||
|
||
to the `require` section of your `composer.json` file. | ||
|
||
|
||
## Usage | ||
|
||
Add Logentries target to your log component config: | ||
|
||
```php | ||
return [ | ||
... | ||
'components' => [ | ||
'log' => [ | ||
'traceLevel' => YII_DEBUG ? 3 : 0, | ||
'targets' => [ | ||
'file' => [ | ||
'class' => 'yii\log\FileTarget', | ||
'levels' => ['error', 'warning'], | ||
], | ||
'logentries' => [ | ||
'class' => 'kop\y2le\LogentriesTarget', | ||
'levels' => ['error', 'warning', 'info'], | ||
'categories' => ['application'], | ||
'logToken' => '<<< YOUR KEY HERE >>>', | ||
], | ||
], | ||
], | ||
], | ||
... | ||
]; | ||
``` | ||
|
||
|
||
## Configuration | ||
|
||
The log destination is specified via `$logToken` property. Please refer to | ||
[Logentries docs for PHP applications](https://logentries.com/doc/php/) for more details. | ||
|
||
|
||
## Report | ||
|
||
- Report any issues [on the GitHub](https://github.com/kop/yii2-logentries/issues). | ||
|
||
|
||
## License | ||
|
||
**yii2-logentries** is released under the MIT License. See the bundled `LICENSE.md` for details. | ||
|
||
|
||
## Resources | ||
|
||
- [Project Page](http://kop.github.io/yii2-logentries) | ||
- [Packagist Package](https://packagist.org/packages/kop/yii2-logentries) | ||
- [Source Code](https://github.com/kop/yii2-logentries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "kop/yii2-logentries", | ||
"description": "Logentries log target for Yii2 framework", | ||
"homepage": "http://kop.github.io/yii2-logentries/", | ||
"keywords": ["yii", "yii2", "log", "logentries", "target"], | ||
"type": "yii2-extension", | ||
"license": "MIT", | ||
"support": { | ||
"issues": "https://github.com/kop/yii2-logentries/issues", | ||
"source": "https://github.com/kop/yii2-logentries" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Ivan Koptiev", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=5.4.0", | ||
"yiisoft/yii2": "*", | ||
"logentries/logentries-monolog-handler": "~2.0" | ||
}, | ||
"require-dev": { | ||
"codeception/codeception": "~2.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"kop\\y2le\\": "" | ||
} | ||
} | ||
} |