Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thiagodp/logger

A very simple logger for PHP. No magic configuration required. Just the basic features you need most.
https://github.com/thiagodp/logger

log logger php phputil

Last synced: 1 day ago
JSON representation

A very simple logger for PHP. No magic configuration required. Just the basic features you need most.

Awesome Lists containing this project

README

        

# Logger

A very simple logger for PHP. No magic configuration required. Just the basic features you need most.

Provided interfaces and classes:

* [phputil\Logger](https://github.com/thiagodp/logger/blob/master/lib/Logger.php) interface
* [phputil\BaseLogger](https://github.com/thiagodp/logger/blob/master/lib/BaseLogger.php) abstract class
* [phputil\TextFileLogger](https://github.com/thiagodp/logger/blob/master/lib/TextFileLogger.php) class
* [phputil\FakeLogger](https://github.com/thiagodp/logger/blob/master/lib/FakeLogger.php) class (v1.1+)
* [phputil\EchoLogger](https://github.com/thiagodp/logger/blob/master/lib/EchoLogger.php) class (v1.3+)

Available log methods:

* `bool debug( string $message, Exception $e = null, array $context = array() );`
* `bool info( string $message, Exception $e = null, array $context = array() );`
* `bool warn( string $message, Exception $e = null, array $context = array() );`
* `bool error( string $message, Exception $e = null, array $context = array() );`
* `bool log( string $logType, string $message, Exception $e = null, array $context = array() );`

### Installation

```command
composer require phputil/logger
```

### Example 1

```php
info( 'Something will happen' );
$logger->debug( 'Something happened.' );
$logger->warn( 'Wait!' );
$logger->error( 'Ouch.' );

$logger->log( Logger::DEBUG, "That's awesome!" );
?>
```

### Example 2

```php
info( 'Something will happen' );
try {
throw new \Exception( 'Hummm... something bad happened.' );
} catch ( \Exception $e ) {
// Logs message and trace
$logger->error( 'Ouch, I did not expect that!', $e );
}

$logger->log( Logger::DEBUG, "That's awesome!" );
?>
```

### Example 3

```php
info( 'It can log to the console too!' );
?>
```