gyselroth/micro-log

This package is abandoned and no longer maintained. The author suggests using the monolog/monolog package instead.

Simple log implementation

v0.0.3 2018-01-08 12:55 UTC

This package is not auto-updated.

Last update: 2018-01-18 16:24:56 UTC


README

...but no shit

Build Status Scrutinizer Code Quality Latest Stable Version GitHub release GitHub license

Description

Requirements

The library is only >= PHP7.1 compatible.

Download

The package is available at packagist: https://packagist.org/packages/gyselroth/micro-log

To install the package via composer execute:

composer require gyselroth/micro-log

Logger (\Micro\Log)

Description

\Micro\Log is a PSR-3 compatible logger with multiple log adapters.

Initialize

$logger = new Logger(Iterable $options);
$logger->info(string $message, array $context);

Configuration

$logger = new Logger([
  'adapter_name' => [
    'class'  => '\Micro\Log\Adapter\File',
    'config' => [
      'file'        => '/path/to/file',
      'date_format' => 'Y-d-m H:i:s', //http://php.net/manual/en/function.date.php
      'format'      => '{date} {level} {message} {context.category}',
      'level'       => 7 //PSR-3 log levels 1-7
    ],
  ],
  'adapter2_name' => []
]);

Of course you can initialize the logger with a configuration object as well (any any other iterable objects):

<log>
  <adapter_name enabled="1" class="\Micro\Log\Adapter\File">
    <config>
      <file>/path/to/file</file>
      <date_format>Y-d-m H:i:s</date_format>
      <format>{date} {level} {message} {context.category}</format>
      <level>7</level>
    </config
  </adapter_name>
</log>
$config = new \Micro\Config(new \Micro\Config\Xml($path));
$logger = new Logger($config);

Format

The message formate is configured in each adapter separately. Available variables are:

  • {message} - The message iteself
  • {date} - The current timestamp formatted with the configured date_format option
  • {level} - The log level, the configured number will be replaced with a string, for exampe 7 => debug
  • {context.} - You can acces each context option and include them in the message format. For example you have a context ['category' => 'router'] then you can configure {context.category} to include this context value within your message.

Log adapters

  • \Micro\Log\Adapter\File
  • \Micro\Log\Adapter\Blackhole
  • \Micro\Log\Adapter\Stdout
  • \Micro\Log\Adapter\Syslog

You can always create your own log adapter using \Micro\Log\Adapter\AdapterInterface.