Wallogit.com
2017 © Pedro Peláez
A dependency free PHP logging utility that just friggin' works :)
A dependency free PHP logging utility that just friggin' works :), (*1)
I like projects like Monolog, but they lack basic conveniences I like about the native console.log() in JavaScript; plus I have a niceities baked into Minilog that you may like as well:, (*2)
Open up your favorite CLI and enter the typical composer require command:, (*3)
> composer require gbox/minilog
BOOM! Now get logging!, (*4)
Using Minilog is pretty straightforward. You define a new \Gbox\Minilog() class intance, you pass in the name of the logger context, and you may pass an option associative array of options to configure it for your needs., (*5)
<?php
require "vendor/autoload.php";
use Gbox\Minilog as Logger;
// Minilog($logname [, $options[] ])
Logger::setup('logName', [
// write log entries to the console
'console' => true, // bool : defaults true
// defines where log files should be written to
'dir' => './logs', // string : defaults '.'
// defines the minimum RFC 5424 level to log
'level' => 'DEBUG', // string : defaults 'DEBUG'
// defines whether to log the path and line number of the log call
'linenos' => true, // bool : defaults true
// defines the timestamp format
'timestamp' => '[Y-m-d H:m:s]', // string : you can change this if you want
]);
Logger::debug('testing', 'message', 'here'); // testing message here
Logger::info('testing', 'message', 'here'); // testing message here
Logger::notice('testing', 'message', 'here'); // testing message here
Logger::warning('testing', 'message', 'here'); // testing message here
Logger::error('testing', 'message', 'here'); // testing message here
Logger::critical('testing', 'message', 'here'); // testing message here
Logger::alert('testing', 'message', 'here'); // testing message here
Logger::emergency('testing', 'message', 'here'); // testing message here
You can see a sample of Minilog in action by cloning this repo and running the following commands in your terminal of choice:, (*6)
> php test-minilog.php [2018-07-23 08:07:36] testing_logs.DEBUG: test-minilog.php:15 testing debug messages (BOOL) true [2018-07-23 08:07:36] testing_logs.INFO: test-minilog.php:16 testing info messages (BOOL) true [2018-07-23 08:07:36] testing_logs.NOTICE: test-minilog.php:17 testing notice messages (BOOL) true [2018-07-23 08:07:36] testing_logs.WARNING: test-minilog.php:18 testing warning messages (BOOL) false [2018-07-23 08:07:36] testing_logs.ERROR: test-minilog.php:19 testing error messages (BOOL) false [2018-07-23 08:07:36] testing_logs.CRITICAL: test-minilog.php:20 testing critical messages (BOOL) false [2018-07-23 08:07:36] testing_logs.ALERT: test-minilog.php:21 testing alert messages (BOOL) false [2018-07-23 08:07:36] testing_logs.EMERGENCY: test-minilog.php:22 testing emergency messages (BOOL) false