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
63b94355
Commit
63b94355
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
fix logger class
parent
ee66aa70
No related branches found
No related tags found
1 merge request
!47
fix logger class
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/deployment/classes/logger.class.php
+292
-462
292 additions, 462 deletions
public_html/deployment/classes/logger.class.php
with
292 additions
and
462 deletions
public_html/deployment/classes/logger.class.php
+
292
−
462
View file @
63b94355
<?php
/**
* ----------------------------------------------------------------------
*
* Debug logging during a client request.
* So you can measure any action find bottlenecks in your code.
*
<<<<<<< public_html/deployment/classes/logger.class.php
* Source: https://github.com/axelhahn/ahlogger
*
* USAGE:
...
...
@@ -21,55 +18,6 @@ class logger {
protected
$aMessages
=
[];
protected
$bShowDebug
=
false
;
protected
$_iMemStart
=
false
;
=======
*
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
*
----------------------------------------------------------------------
*/
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
=
''
;
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
>>>>>>>
public_html
/
deployment
/
classes
/
logger
.
class
.
php
/**
* constuctor
...
...
@@ -84,13 +32,6 @@ class logger {
return
true
;
}
<<<<<<<
public_html
/
deployment
/
classes
/
logger
.
class
.
php
=======
// ----------------------------------------------------------------------
// PUBLIC METHODS
// ----------------------------------------------------------------------
>>>>>>>
public_html
/
deployment
/
classes
/
logger
.
class
.
php
/**
* add a logging message
* @param type $sMessage
...
...
@@ -135,19 +76,6 @@ class logger {
}
}
<<<<<<<
public_html
/
deployment
/
classes
/
logger
.
class
.
php
=======
/**
* 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
*/
>>>>>>>
public_html
/
deployment
/
classes
/
logger
.
class
.
php
protected
function
_prepareRendering
(){
$iMem
=
memory_get_usage
();
$this
->
add
(
'<hr>'
);
...
...
@@ -188,18 +116,6 @@ class logger {
if
(
$iDelta
>
$iMaxtime
)
{
$iMaxtime
=
$iDelta
;
$sMaxRowId
=
$sTrId
;
<<<<<<<
public_html
/
deployment
/
classes
/
logger
.
class
.
php
}
$iMaxmem
=
max
(
$aLogentry
[
"memory"
],
$iMaxmem
);
if
((
$iDelta
>
1
)
||
$aLogentry
[
"level"
]
==
"warning"
)
{
$aReturn
[
'warnings'
]
.
=
'<a href="#'
.
$sTrId
.
'" title="'
.
sprintf
(
"%01.4f"
,
$iDelta
)
.
' s">'
.
$iCounter
.
'</a> '
;
}
if
(
$aLogentry
[
"level"
]
==
"error"
)
{
$aReturn
[
'errors'
]
.
=
'<a href="#'
.
$sTrId
.
'" title="'
.
sprintf
(
"%01.4f"
,
$iDelta
)
.
' s">'
.
$iCounter
.
'</a> '
;
}
=======
}
$iMaxmem
=
max
(
$aLogentry
[
"memory"
],
$iMaxmem
);
...
...
@@ -210,13 +126,11 @@ class logger {
if
(
$aLogentry
[
"level"
]
==
"error"
)
{
$aReturn
[
'errors'
]
.
=
'<a href="#'
.
$sTrId
.
'" title="'
.
sprintf
(
"%01.4f"
,
$iDelta
)
.
' s">'
.
$iCounter
.
'</a> '
;
}
>>>>>>>
public_html
/
deployment
/
classes
/
logger
.
class
.
php
$aReturn
[
'entries'
][]
=
[
'time'
=>
$aLogentry
[
"time"
],
'level'
=>
$aLogentry
[
"level"
],
'message'
=>
$aLogentry
[
"message"
],
'memory'
=>
sprintf
(
"%01.2f"
,
$aLogentry
[
"memory"
]
/
1024
/
1024
),
// MB
<<<<<<<
public_html
/
deployment
/
classes
/
logger
.
class
.
php
'trid'
=>
$sTrId
,
'trclass'
=>
$aLogentry
[
"level"
],
...
...
@@ -299,90 +213,6 @@ class logger {
'<td>'
.
$aLogentry
[
"message"
]
.
'</td>'
.
'</tr>'
;
}
=======
'trid'
=>
$sTrId
,
'trclass'
=>
$aLogentry
[
"level"
],
'counter'
=>
$iCounter
,
'timer'
=>
sprintf
(
"%01.3f"
,
$aLogentry
[
"time"
]
-
$sStarttime
),
'delta'
=>
sprintf
(
"%01.0f"
,
$iDelta
*
1000
),
];
$iLasttime
=
$aLogentry
[
"time"
];
}
$aReturn
[
'level'
]
=
(
$bHasWarning
?
(
$bHasError
?
'error'
:
'warning'
)
:
''
);
$aReturn
[
'maxrowid'
]
=
$sMaxRowId
;
$aReturn
[
'maxtime'
]
=
sprintf
(
"%01.3f"
,
$iMaxtime
);
$aReturn
[
'maxmem'
]
=
sprintf
(
"%01.2f"
,
$iMaxmem
/
1024
/
1024
);
$aReturn
[
'totaltime'
]
=
sprintf
(
"%01.3f"
,
$aLogentry
[
'time'
]
-
$aReturn
[
'entries'
][
0
][
'time'
]);
return
$aReturn
;
}
/**
* get html code for a progressbar with divs
* @param {int|float} $iVal value between 0..max value
* @param {int|float} $iMax max value
* @return {string}
*/
protected
function
_getBar
(
$iVal
,
$iMax
){
$iWidth
=
$iVal
/
$iMax
*
100
;
return
'<div class="bar"><div class="progress" style="width: '
.
$iWidth
.
'%;"> </div></div>'
;
}
/**
* render output of all logging messages
*/
public
function
render
()
{
if
(
!
$this
->
bShowDebug
){
return
false
;
}
$aData
=
$this
->
_prepareRendering
();
/*
Array
(
[totaltime] => 0.006
[errors] =>
[warnings] => 3
[maxrowid] => debugTableRow3
[maxtime] => 0.005
[result] => Array
(
)
[entries] => Array
mit Elementen
Array
(
[time] => 1663959608.2566
[level] => info
[message] => Logger was initialized.
[memory] => 538056
[trid] => debugTableRow1
[trclass] => info
[trstyle] =>
[counter] => 1
[timer] => 0.000
[delta] => 0.000
)
*/
$sOut
=
''
;
// echo '<pre>'; print_r($aData); die();
foreach
(
$aData
[
'entries'
]
as
$aLogentry
){
$sOut
.
=
'<tr class="'
.
$this
->
sCssPrefix
.
'-level-'
.
$aLogentry
[
"level"
]
.
''
.
(
$aLogentry
[
"trid"
]
==
$aData
[
"maxrowid"
]
?
' '
.
$this
->
sCssPrefix
.
'-maxrow'
:
''
)
.
'" '
.
'id="'
.
$aLogentry
[
"trid"
]
.
'">'
.
'<td>'
.
$aLogentry
[
"counter"
]
.
'</td>'
.
'<td>'
.
$aLogentry
[
"level"
]
.
'</td>'
.
'<td>'
.
$aLogentry
[
"timer"
]
.
'</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>'
.
$aLogentry
[
"message"
]
.
'</td>'
.
'</tr>'
;
}
>>>>>>>
public_html
/
deployment
/
classes
/
logger
.
class
.
php
if
(
$sOut
){
$sOut
=
'
<style>
...
...
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