Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
aae9a452
Commit
aae9a452
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Plain Diff
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
!49
update ahlogger
Pipeline
#1477
passed
2 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/deployment/classes/logger.class.php
+344
-292
344 additions, 292 deletions
public_html/deployment/classes/logger.class.php
with
344 additions
and
292 deletions
public_html/deployment/classes/logger.class.php
+
344
−
292
View file @
aae9a452
<?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
.
'%;"> </div></div>'
;
?
'<div class="bar"><div class="progress" style="width: '
.
(
$iVal
/
$iMax
*
100
)
.
'%;"> </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>'
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment