Priority levels |
:debug | `7` | Low-level debug events. |
:info | `6` | Process flow infos etc. |
:notice, :note | `5` | Lowest priority language notices. |
:warning, :warn | `4` | Warnings. |
:error, :err | `3` | PHP or system error. |
:critical, :crit | `2` | This can't be good. |
:alert, :alrt | `1` | Turn on the bat light. |
:emergency, :emerg | `0` | Someone call the president. |
Source / generator |
:log | | Application origin, normal/manual log calls. |
:sys | | System-level events and errno codes. |
:lang | | Language errors, warnings, notices, etc. |
:exception | | Langauge/runtime exceptions. |
:assert | | `Assert()` warnings. |
Field names |
Any database column / primary field name can be represented as `:token`. It's pretty much only useful to use :vars however to map the following array parameter. |
Aliases |
Besides the prio levels, there are a few more shortened aliases to common fields. Among them :documentation for :doc, :priority for :prio, :help for :doc, :msg for :message, :language for lang, :exc for :exception, :app as :log generator source alias, :trace and :stack as aliases for :backtrace, and :env for :server |
Injector calls |
:backtrace | | Populates backtrace. |
:server | | Inserts $_SERVER array into `context`. |
:file | | Uncovers `file` and `line` from backtrace. |
:version | | Reads out meta data (file/scm version, and section) from script comments. |
:code | | Inserts 3 lines of `code` context. |
:p | | Tries to deduce log event hierarchy from prior calls, sections, and backtraces. (Not yet implemented.) |
Any other `:token` name can be used freely to classify and group your application flow. They'll be used as **section** names.
## Setup
You obviously need a readily available `log.db` SQLite store. Best keep it `DOCUMENT_ROOT`-relative, so it's easy to declare on instantiation:
ł::$db = "$_SERVER[DOCUMENT_ROOT]/config/log.db";
ł::$app = "YourAppID";
You can of course manually load the library. Most autoloaders would already load it implicitly because of the class reference. (Even PSR-x ones, and they'd even be accidentially correct for once with case-sensitive Unicode lookups here).
While you ought to use `:section` names for logging calls, you can also override/update the default throughout your application flow with:
ł::$section = "forum";
Or likewise adapt properties of the global logger group `ł()->section=..`.
#### Default injectors
The `$logger` instance in `ł()` takes a list of default :token options and injectors. You should adapt it directly to enable further features.
$logger = new ł(":log", ':backtrace', ':file', ':version', ':p');
For instance would engage full event population for all/manual logging calls.
#### Avoid complexity
* Yes, you could actually run multiple logger groups, or pass around the `$logger` handler. Don't do it. (Kind of works, but wasn't intended to.)
* The alternative branches and `store()` implementations are meant to be patched in. It makes zero sense to DI / runtime-bind them. You're only going to use one approach in practice, so don't complicate instantiation.
* Take care with leaking information through logs. It's tempting to include a backtrace for all calls. But in particular authorization-sensitive variable states may only be useful for concrete debugging tasks, not in all log events. (That's in important consideration for any logging scheme; but moreso for logStruck due to its much simpler API and utilization.)