Zero-dependency global `kirbylog()` helper for any content

Installs: 1 632

Dependents: 1

Suggesters: 0

Security: 0

Stars: 22

Watchers: 3

Forks: 1

Open Issues: 0

Type:kirby-plugin

1.4.7 2023-11-16 13:27 UTC

This package is auto-updated.

Last update: 2024-12-16 15:46:43 UTC


README

Kirbylog

Kirbylog

The most simple, Kirby-esque way to log content to file.

Most of the time, I just want to log some string or array to a file. That's what this plugin does. The given input:

// Anywhere in your code
kirbylog('Something happened');

… will produce this example output site/logs/2023-08-23.log:

[2023-08-23 09:28:04] INFO Something happened

Key features

  • 🪃 Global kirbylog() helper usable anywhere
  • 💬 Arrays will be converted to JSON
  • 🧩 Dependency-free, based solely on Kirby internals
  • 🔢 Supports logging levels

Installation

Composer

composer require johannschopplich/kirbylog

Download

Download and copy this repository to /site/plugins/kirbylog.

Usage

This plugin registers a global kirbylog function, callable anywhere.

kirbylog('Log this to file');

Logging level

Pass the logging level of your choice as the second parameter (upper or lower case is irrelevant). By default, content will be logged with the INFO level. This plugin uses logging levels described by RFC 5424. Of course, you can tailor them to your needs.

kirbylog($response->code(), 'error');

Generated log file:

[2023-08-23 12:43:56] ERROR 401

Options

All options have to prefixed with johannschopplich.kirbylog. in your config.php.

Configuration example for your site/config/config.php file:

return [
    'johannschopplich.kirbylog' => [
        'filename' => 'test.log'
    ]
]

Alternatives

License

MIT License © 2022-PRESENT Johann Schopplich