Skip to content

Commit

Permalink
Adding a README and a composer.json for the Log namespace
Browse files Browse the repository at this point in the history
It will be split into a separate repo afterwards
  • Loading branch information
lorenzo committed Oct 1, 2014
1 parent 348b10e commit 53d9b45
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -52,6 +52,7 @@
"cakephp/utility": "self.version",
"cakephp/core": "self.version",
"cakephp/datasource": "self.version",
"cakephp/cache": "self.version"
"cakephp/cache": "self.version",
"cakephp/log": "self.version"
}
}
73 changes: 73 additions & 0 deletions src/Log/README.md
@@ -0,0 +1,73 @@
# CakePHP Logging Library

The Cache library provides a `Log` service locator for interfacing with multiple logging backends using
a simple interface. With the `Log` class it is possible to send a single message to multiple logging
backends at the same time or just a subset of them based on the log level or context.

By default you can use Files or Syslog as logging backends, but you can use any object implementing
`Psr\Log\LogInterface` as an engine for the `Log` class.

## Usage

You can define as many or as few loggers as your application needs. Loggers should be configured using `Cake\Core\Log.`
An example would be:

```php
use Cake\Cache\Cache;

use Cake\Log\Log;

// Short classname
Log::config('local', [
'className' => 'FileLog',
'levels' => ['notice', 'info', 'debug'],
'file' => '/path/to/file.log',
]);

// Fully namespaced name.
Log::config('production', [
'className' => 'Cake\Log\Engine\SyslogLog',
'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
]);
```

It is also possible to create loggers by providing a closure.


```php
Log::config('special', function() {
// Return any PSR-3 compatible logger
return new MyPSR3CompatibleLogger();
};
```

You can no use the `Log` class to pass messages to the logging backends:

```php
Log::write('debug', 'Something did not work');
```

Only the logging engines subscribed to the log level your are writing to will get the
message passed. In the example above, only the 'local' engine will get the log message.

### Filtering messages with scopes

The Log library supports another level of message filtering. By using scopes, you can limit the
logging engines that receive a particular message.

```php
// Configure /logs/payments.log to receive all levels, but only
// those with `payments` scope.
Log::config('payments', [
'className' => 'FileLog',
'levels' => ['error', 'info', 'warning'],
'scopes' => ['payments'],
'file' => '/logs/payments.log',
]);

Log::warning('this gets written only to payments.log', ['scope' => ['payments']]);
```

## Documentation

Please make sure you check the [official documentation](http://book.cakephp.org/3.0/en/core-libraries/logging.html)
21 changes: 21 additions & 0 deletions src/Log/composer.json
@@ -0,0 +1,21 @@
{
"name": "cakephp/cache",
"description": "CakePHP logging library with support for multiple different streams",
"license": "MIT",
"authors": [
{
"name": "CakePHP Community",
"homepage": "http://cakephp.org"
}
],
"autoload": {
"psr-4": {
"Cake\\Log\\": "."
}
},
"require": {
"cakephp/core": "dev-master",
"psr/log": "1.0"
},
"minimum-stability": "beta"
}

0 comments on commit 53d9b45

Please sign in to comment.