Simple PHP solution for enhanced logging.
composer require tintonic/php-elog
This example creates an Elog
instance that will log to a file named elog.log
in the same directory as executing script (__DIR__
). The helper function elog()
logs to the instance of Elog
that was first created.
create_elog();
/*
Logs to the first instance that was created.
Logs to "__DIR__/elog.log"
*/
elog("I am elog.log");
null
is presented as[null]
empty string
is presented as[empty string]
true
is presented as[true]
false
is presented as[false]
object
andarray
is described usingprint_r()
create_elog();
elog(null); // [null]
elog(''); // [empty string]
elog(true); // [true]
elog(false); // [false]
elog((object) [
'id' => 123,
'foo' => 'bar'
]);
/*
stdClass Object
(
[id] => 123
[foo] => bar
)
*/
elog([
'id' => 123,
'foo' => 'bar'
]);
/*
Array
(
[id] => 123
[foo] => bar
)
*/
elog(123, 'Current value', true);
/*
--- Current value {integer} ---
123
*/
This example creates two named Elog
instances – one that logs to _DIR__/first.log
and another that logs to /path/to/log/second_log_file
(without file extension).
create_elog(__DIR__, 'first');
create_elog('/path/to/log', 'second', 'second_log_file', null);
// Log to named instances using elogn().
elogn('first', "I am first.log"); // ———> __DIR__/first.log
elogn('second', "I am second_log_file"); // ———> /path/to/log/second_log_file
Of course you may use the Elog
class directly.
This example also demonstrates how you can configure a default value for $include_type
to always include the data type in the output.
use Tintonic/PhpElog/Elog;
/*
Create an instance named "notes" that logs to "/path/to/log/elog.txt" with data type by default.
*/
$logger = new Elog('/path/to/log', 'notes', 'elog', 'txt');
$logger->set_default_include_type(true);
/*
Log to named instance somewhere else in the application.
*/
Elog::logn('notes', 123);
/*
{integer}
123
*/
Elog::logn('notes' 'bar', 'Foo?');
/*
--- Foo? {string} ---
bar
*/