diff --git a/src/docs/frontend/bareui.md b/src/docs/frontend/bareui.md index 7d3f007e..8fb70be0 100644 --- a/src/docs/frontend/bareui.md +++ b/src/docs/frontend/bareui.md @@ -196,4 +196,4 @@ To include a sub-template in a template, you can use the `$template::render()` m ``` -All BareUI templates have access to the `$template` variable, which is an instance of the BareUI engine. Calling the `render()` method on this variable will include the specified sub-template in the current template. +All BareUI templates have access to the `$template` variable, which holds the BareUI class name, so `$template::render()` is a static call. Calling `render()` this way will include the specified sub-template in the current template. diff --git a/src/docs/routing/error-handling.md b/src/docs/routing/error-handling.md index 118dfbd1..60c54c32 100644 --- a/src/docs/routing/error-handling.md +++ b/src/docs/routing/error-handling.md @@ -151,6 +151,23 @@ app()->config([ ]); ``` +You can change how each entry is formatted with the `log.style` configuration option. It accepts `leaf` (the default) or `linux`: + +```php +app()->config([ + 'log.enabled' => true, + 'log.style' => 'linux' +]); +``` + +With `leaf`, the timestamp sits on its own line above the message. With `linux`, each entry is a single line, like a system log: + +```text:no-line-numbers +[2026-11-13 09:31:40] ERROR - Something went wrong +``` + +By default new entries are appended to the end of the file. If you prefer the old newest-first layout, set `log.mode` to `prepend` (this rewrites the whole file on every entry, so avoid it on busy production apps). + ::: ::: details Usage with Leaf MVC @@ -169,6 +186,18 @@ That's it! Leaf will no longer log errors or exceptions for your app. ::: +### Writing your own log entries + +Once logging is enabled, `app()->logger()` gives you the logger instance, so you can log your own messages and not only errors: + +```php +app()->logger()->info('User signed up', ['id' => 12]); +app()->logger()->warning('Disk space is low'); +app()->logger()->error('Payment failed'); +``` + +Each level method (`debug`, `info`, `notice`, `warning`, `error`, `critical`, `alert`, `emergency`) writes to the log file you configured. If logging isn't enabled or the logger module isn't installed, `app()->logger()` triggers an error telling you to set `log.enabled` and install the module. + ## Rescue Helper Leaf provides a shorter way to handle exceptions using the `rescue()` function. It runs your callback, catches anything thrown inside it, reports the exception to Crash, and returns a default value. This way, you can use try-catch with a more inline syntax.