Skip to content
Snippets Groups Projects
Commit aae9a452 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '5997-no-autocomplete' into 'master'

update ahlogger

See merge request !49
parents 6c00cbd9 39a5313b
No related branches found
No related tags found
1 merge request!49update ahlogger
Pipeline #1477 passed
<?php <?php
/** /**
* ----------------------------------------------------------------------
*
* Debug logging during a client request. * Debug logging during a client request.
* So you can measure any action find bottlenecks in your code. * So you can measure any action find bottlenecks in your code.
* *
* Licence: GNU GPL 3.0
* Source: https://github.com/axelhahn/ahlogger * Source: https://github.com/axelhahn/ahlogger
* Docs: https://www.axel-hahn.de/docs/ahlogger/
* *
* USAGE: * USAGE:<br>
* (1) Trigger a message with add() to add a marker * (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 * (2) The render() method lists all items in a table with time since start
* and the delta to the last message. * and the delta to the last message. <br>
* *
* @author www.axel-hahn.de * @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
* ----------------------------------------------------------------------
*/ */
class logger { class logger {
/**
* @var {array} array of added messages
*/
protected $aMessages = []; protected $aMessages = [];
/**
* @var {bool} flag: show debug infos? default: false
*/
protected $bShowDebug = false; protected $bShowDebug = false;
/**
* @var {int} memory usage on start
*/
protected $_iMemStart = false; protected $_iMemStart = false;
/**
* @var {string} dynamic prefix for used css - it is set in the cronstructor
*/
protected $sCssPrefix = '';
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
/** /**
* constuctor * constuctor
* @param string $sInitMessage init message * @param string $sInitMessage init message
...@@ -32,6 +68,10 @@ class logger { ...@@ -32,6 +68,10 @@ class logger {
return true; return true;
} }
// ----------------------------------------------------------------------
// PUBLIC METHODS
// ----------------------------------------------------------------------
/** /**
* add a logging message * add a logging message
* @param type $sMessage * @param type $sMessage
...@@ -76,6 +116,16 @@ class logger { ...@@ -76,6 +116,16 @@ class logger {
} }
} }
/**
* helper function: prepare array of added massages before output
* - detect warnings and errors
* - detect needed time for each action
* - detect longest action
* - detect maximum of memory usage
* - calculate total time
*
* @return array
*/
protected function _prepareRendering(){ protected function _prepareRendering(){
$iMem=memory_get_usage(); $iMem=memory_get_usage();
$this->add('<hr>'); $this->add('<hr>');
...@@ -158,8 +208,10 @@ class logger { ...@@ -158,8 +208,10 @@ class logger {
* @return {string} * @return {string}
*/ */
protected function _getBar($iVal, $iMax){ protected function _getBar($iVal, $iMax){
$iWidth=$iVal/$iMax*100; return $iMax>0
return '<div class="bar"><div class="progress" style="width: '.$iWidth.'%;">&nbsp;</div></div>'; ? '<div class="bar"><div class="progress" style="width: '.($iVal/$iMax*100).'%;">&nbsp;</div></div>'
: ''
;
} }
/** /**
...@@ -208,7 +260,7 @@ class logger { ...@@ -208,7 +260,7 @@ class logger {
'<td>' . $aLogentry["counter"] . '</td>' . '<td>' . $aLogentry["counter"] . '</td>' .
'<td>' . $aLogentry["level"] . '</td>' . '<td>' . $aLogentry["level"] . '</td>' .
'<td>' . $aLogentry["timer"] . '</td>' . '<td>' . $aLogentry["timer"] . '</td>' .
'<td>' . $this->_getBar($aLogentry["delta"], $aData["maxtime"]*1000). $aLogentry["delta"] .' ms</td>' . '<td>' . $this->_getBar($aLogentry["delta"], $aData["maxtime"]*1000). $aLogentry["delta"] .' ms'.($aLogentry["delta"]==$aData['maxtime']*1000 ? ' ⏱️' : '').'</td>' .
'<td>' . $this->_getBar($aLogentry["memory"], $aData["maxmem"]) . $aLogentry["memory"] .' MB'. '</td>' . '<td>' . $this->_getBar($aLogentry["memory"], $aData["maxmem"]) . $aLogentry["memory"] .' MB'. '</td>' .
'<td>' . $aLogentry["message"] . '</td>' . '<td>' . $aLogentry["message"] . '</td>' .
'</tr>'; '</tr>';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment