Skip to content
Use Monolog to log data to files/databases/notifications/...
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
classes
tests
vendor
.coveralls.yml
.editorconfig
.gitignore
.php_cs.dist
.travis.yml
LICENSE
README.md
composer.json
composer.lock
index.php
phpunit.xml

README.md

Kirby 3 Monolog

Release Stars Downloads Issues Build Status Coverage Status Maintainability Demo Gitter Twitter

Use Monolog to log data to files/databases/notifications/...

Quickstart

site/templates/home.php

monolog()->info('test-' . md5((string) time()), [
    'title' => $page->title(), // field will be normalized
    'page' => $page->id(),
]);

site/logs/2019-10-27.log

[2019-10-27 19:10:30] default.INFO: test-d4a22afc0f735f551748d17c959b3339 {"title":"Home","page":"home"} []

Commercial Usage

This plugin is free but if you use it in a commercial project please consider to

Installation

  • unzip master.zip as folder site/plugins/kirby3-monolog or
  • git submodule add https://github.com/bnomei/kirby3-monolog.git site/plugins/kirby3-monolog or
  • composer require bnomei/kirby3-monolog

Similar Plugin

  • Log is simpler and can just write to files

Setup

Use the default channel provided by this plugin or define your own Channels. Monolog comes bundled with a lot of handlers, formatters and processors.

  • write to file or syslogs
  • send mails
  • post to slack
  • insert into local or remote databases
  • format as JSON
  • append file/class/method Introspection
  • append a UUID
  • append URI, post method and IP
  • ... create your own

site/config/config.php

return [
    // other config settings ...
    'bnomei.monolog.channels' => [
        'security' => function() {
            $logger = new \Monolog\Logger('security');
            // add handlers, formatters, processors and then...
            return $logger; 
        }
    ],
];

Usecase

Named Channel => Logger

$log = \Bnomei\Log::singleton()->channel('default');
// or simply
$log = monolog();

// get a logger instance by channel by name
$securityLogger = monolog('security');

Add records to the Logger

Message

$log = monolog();
$log->warning('Foo');

// or with method chaining
monolog()->error('Bar');

Message and Context

monolog('security')->info('Adding a new user', [
    'username' => $user->name(),
]);

// increment Field `visits` in current Page
$page->increment('visits');
monolog()->info('Incrementing Field', [
    'page' => $page->id(),
    'visits' => $page->visits()->toInt(),
]);

Default Channel

The default channel provided by this plugin writes file to the site/logs folder using the filename format date('Y-m-d') . '.log' and normalizes the data to make logging Kirby Objects easier.

HINT: Without normalization you would have to call ->value() or cast as string on every Kirby Field before adding its value as context data.

Dependencies

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

You can’t perform that action at this time.