Fixed logging (Now logging autostarting without special loggerconfig.php). Issue #59.
This commit is contained in:
parent
5a761dcddb
commit
7e2f63142d
6 changed files with 9 additions and 95 deletions
|
|
@ -9,7 +9,6 @@ Getting Started
|
|||
* [Run builds using a worker](workers/worker.md)
|
||||
* [Run builds using cronjob](workers/cron.md)
|
||||
* [Adding PHP Censor Support to Your Projects](configuring_project.md)
|
||||
* [Setting up Logging](logging.md)
|
||||
* Updating PHP Censor (See [README](../../README.md))
|
||||
* [Configuring PHP Censor](configuring.md)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
Setting up Logging
|
||||
==================
|
||||
|
||||
Basics
|
||||
------
|
||||
|
||||
The PHP Censor codebase makes use of the [PSR3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) logging standard. By default we use [Monolog](https://github.com/Seldaek/monolog) to handle the actual work implementing this standard.
|
||||
|
||||
How to Setup Logging (For people running a PHP Censor instance)
|
||||
---------------------------------------------------------------
|
||||
|
||||
The only step required to activate logging is to create a file in the root directory called loggerconfig.php with content like the following:
|
||||
|
||||
```php
|
||||
<?php
|
||||
return [
|
||||
/** Loggers attached to every command */
|
||||
"_" => function () {
|
||||
return [
|
||||
new \Monolog\Handler\StreamHandler('path/to/log', \Monolog\Logger::ERROR),
|
||||
];
|
||||
}
|
||||
];
|
||||
```
|
||||
This file should return an array of key value pairs. Each key tells PHP Censor which command to attach the logger to (the underscore is a special value which matches all commands). For each command an array of [Monolog](https://github.com/Seldaek/monolog) handlers should be returned. In the example above we've used one that simply writes to the file system but in practise this could be any handler written for monolog.
|
||||
|
||||
Once this file is created all plugins and core PHP Censor functionality should start writing to the configured handlers.
|
||||
|
||||
How to write to the Log (For people creating a new plugin)
|
||||
----------------------------------------------------------
|
||||
|
||||
### Using the plugin constructor to get a logger directly
|
||||
|
||||
For plugin creators the simplest way to get hold of an error logger is to add a parameter to the constructor and typehint on 'Psr\Log\LoggerInterface'. The code that loads your plugin will automatically inject the logger when it sees this. For example:
|
||||
```php
|
||||
class ExampleLoggingPlugin implements \PHPCensor\Plugin
|
||||
{
|
||||
protected $log;
|
||||
|
||||
public function __construct(Psr\Log\LoggerInterface $log)
|
||||
{
|
||||
$this->log = $log;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->log->notice("You'll notice this in the log");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Using convenience methods provided by the Builder
|
||||
Your plugin can also call a couple of messages on the Builder object:
|
||||
|
||||
logSuccess()
|
||||
logFailure()
|
||||
log()
|
||||
|
||||
All calls will get piped through to the appropriate logger.
|
||||
Loading…
Add table
Add a link
Reference in a new issue