Select Git revision
check_iml_backup_server
-
Hahn Axel (hahn) authoredHahn Axel (hahn) authored
logger.class.php 14.22 KiB
<?php
/**
* ----------------------------------------------------------------------
*
* Debug logging during a client request.
* So you can measure any action find bottlenecks in your code.
*
* Licence: GNU GPL 3.0
* Source: https://github.com/axelhahn/ahlogger
* Docs: https://www.axel-hahn.de/docs/ahlogger/
*
* USAGE:<br>
* (1) Trigger a message with add() to add a marker<br>
* (2) The render() method lists all items in a table with time since start
* and the delta to the last message. <br>
*
* @author www.axel-hahn.de
*
* ----------------------------------------------------------------------
* 2016-02-26 init
* 2016-11-19 add memory usage
* (...)
* 2022-09-25 add memory tracking, add cli renderer
* 2022-09-27 css updates
* 2022-10-02 add emoji chars
* 2022-10-16 mark longest action with an icon
* 2022-12-15 make it compatible to PHP 8.2; add doc + comments
* 2023-05-15 fix _getBar() - division by zero
* 2024-07-12 php8 only: use variable types; update phpdocs
* 2024-09-04 fix short array syntax
* ----------------------------------------------------------------------
*/
class logger
{
/**
* @var {array} array of added messages
*/
protected $aMessages = [];
/**
* @var {bool} flag: show debug infos? default: false
*/
protected $bShowDebug = false;
/**
* @var {int} memory usage on start
*/
protected $_iMemStart = false;
/**
* @var {string} dynamic prefix for used css - it is set in the cronstructor
*/
protected $sCssPrefix = '';
protected $sSourceUrl = 'https://github.com/axelhahn/ahlogger';
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
/**
* Constuctor
* @param string $sInitMessage init message
*/
public function __construct(string $sInitMessage = "Logger was initialized.")
{
$this->_iMemStart = memory_get_usage();
$this->enableDebug(true);