presprog/kirby-monolog

Use the Monolog logger library with Kirby CMS

Installs: 106

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:kirby-plugin

0.1.0 2024-02-09 13:49 UTC

This package is auto-updated.

Last update: 2024-11-09 15:55:41 UTC


README

This plugin adds the Monolog logging library to Kirby.

⚡ Ready for Kirby 4!

🤟Usage

Use the monolog() helper function:

// Write to the default log file
monolog()->log('something happend 😱');

// Log to another channel (only changes the filename for now)
// Will log to "your-log-dir/other-channel-$date.log"
monolog('other-channel')->log('something happend 😱');

// Change the log level (any of \Psr\Log\LogLevel)
monolog()->log('something CRITICAL happend 😱', 'critical');

// …

If you throw and handle exceptions in your own code, you may log them with site()->logException():

try {
    // ..
} catch(\Exception $exception) {
    site()->logException($exception)
}

This will log the exception message with critical level alongside the stack trace.

The plugin also automatically listens to Kirby system.exception hook and logs the exception message as well as the stacktrace to the default log file.

💻 How to install

via Composer (recommended)

$ composer require presprog/kirby-monolog:^0.1

via ZIP archive

Download the ZIP archive, extract it into your plugins folder (defaults to site/plugins) and rename the subfolder to monolog.

✅ To do

  • Define more channels via the config file

Alternatives

There are plenty of alternatives:

Made with ♥️ and ☕ by Present Progressive