Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logger-36
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
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DEBREUVE Eric
logger-36
Commits
b0f6bbf8
Commit
b0f6bbf8
authored
2 years ago
by
DEBREUVE Eric
Browse files
Options
Downloads
Patches
Plain Diff
added memory usage logging
parent
2d702e7f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
logger_36/__init__.py
+1
-0
1 addition, 0 deletions
logger_36/__init__.py
logger_36/main.py
+36
-5
36 additions, 5 deletions
logger_36/main.py
with
37 additions
and
5 deletions
logger_36/__init__.py
+
1
−
0
View file @
b0f6bbf8
...
...
@@ -35,5 +35,6 @@ from logger_36.main import (
ElapsedTime
,
LogSystemDetails
,
SaveLOGasHTML
,
SetShowMemoryUsage
,
)
from
logger_36.version
import
__version__
This diff is collapsed.
Click to expand it.
logger_36/main.py
+
36
−
5
View file @
b0f6bbf8
...
...
@@ -42,6 +42,22 @@ from rich.console import Console as console_t
from
rich.style
import
Style
as
style_t
from
rich.text
import
Text
as
text_t
try
:
from
psutil
import
Process
as
process_t
_PROCESS
=
process_t
()
_GIGA_SCALING
=
1.0
/
(
1024
**
3
)
def
UsedMemoryInGb
()
->
float
:
""""""
return
round
(
_GIGA_SCALING
*
_PROCESS
.
memory_info
().
rss
,
1
)
except
ModuleNotFoundError
:
_PROCESS
=
None
def
UsedMemoryInGb
()
->
float
:
return
0.0
# This module is certainly imported early. Therefore, the current time should be close enough to the real start time.
_START_TIME
=
time
.
time
()
...
...
@@ -90,16 +106,16 @@ class color_handler_t(lggg.Handler):
formatter
:
lggg
.
Formatter
=
None
console
:
console_t
=
None
show_memory_usage
:
bool
=
False
def
__init__
(
self
,
/
,
*
,
level
=
lggg
.
NOTSET
)
->
None
:
def
__init__
(
self
)
->
None
:
""""""
super
().
__init__
(
level
=
l
evel
)
super
().
__init__
(
level
=
l
ggg
.
NOTSET
)
self
.
formatter
=
lggg
.
Formatter
(
fmt
=
_MESSAGE_FORMAT
,
datefmt
=
_DATE_FORMAT
)
self
.
console
=
console_t
(
record
=
True
,
force_terminal
=
True
,
width
=
1000
,
tab_size
=
5
)
self
.
setFormatter
(
self
.
formatter
)
def
emit
(
self
,
record
:
lggg
.
LogRecord
,
/
)
->
None
:
...
...
@@ -107,14 +123,18 @@ class color_handler_t(lggg.Handler):
cls
=
self
.
__class__
formatted
=
self
.
formatter
.
format
(
record
)
if
self
.
show_memory_usage
:
memory_usage
=
f
"
+mem=
{
UsedMemoryInGb
()
}
"
else
:
memory_usage
=
""
if
"
\n
"
in
formatted
:
lines
=
formatted
.
splitlines
()
highlighted
=
text_t
(
lines
[
0
])
highlighted
.
append
(
f
"
+
{
ElapsedTime
()
}
\n
"
,
style
=
"
green
"
)
highlighted
.
append
(
f
"
+
{
ElapsedTime
()
}
{
memory_usage
}
\n
"
,
style
=
"
green
"
)
highlighted
.
append
(
"
"
+
"
\n
"
.
join
(
lines
[
1
:]))
else
:
highlighted
=
text_t
(
formatted
)
highlighted
.
append
(
f
"
+
{
ElapsedTime
()
}
"
,
style
=
"
green
"
)
highlighted
.
append
(
f
"
+
{
ElapsedTime
()
}
{
memory_usage
}
"
,
style
=
"
green
"
)
highlighted
.
stylize
(
"
dodger_blue2
"
,
end
=
19
)
highlighted
.
highlight_words
(
...
...
@@ -135,6 +155,17 @@ LOGGER.setLevel(lggg.INFO) # Minimum desired level
LOGGER
.
addHandler
(
color_handler_t
())
def
SetShowMemoryUsage
(
show_memory_usage
:
bool
,
/
)
->
None
:
""""""
if
show_memory_usage
and
(
_PROCESS
is
None
):
LOGGER
.
warning
(
'
Cannot show memory usage: Package
"
psutil
"
not installed
'
)
return
for
handler
in
LOGGER
.
handlers
:
if
hasattr
(
handler
,
"
show_memory_usage
"
):
handler
.
show_memory_usage
=
show_memory_usage
def
AddFileHandler
(
file
:
Union
[
str
,
path_t
],
/
)
->
None
:
""""""
if
file
.
exists
():
...
...
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