Giter Site home page Giter Site logo

kirbylog's Introduction

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/2021-08-23.log:

[2021-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

Download

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

Git submodule

git submodule add https://github.com/johannschopplich/kirbylog.git site/plugins/kirbylog

Composer

composer require johannschopplich/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:

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

Options

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

Option Default Type Description
dir fn () => kirby()->root('logs') string or function Root directory for your logs. Note: Wrap kirby() calls in a function, because Kirby hasn't initialized in config.php yet.
filename date('Y-m-d') . '.log' string Filename to write logged content to.
defaultLevel info string Default logging level to use. Doesn't need to be case sensitive.
levels Source reference array List of logging levels. By default, kirbylog supports the logging levels described by RFC 5424.

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

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

Alternatives

License

MIT License ยฉ 2022 Johann Schopplich

kirbylog's People

Contributors

johannschopplich avatar

Stargazers

Aleksejs Skurjats avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.