Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
be1bca74
Verified
Commit
be1bca74
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' into table-error
parents
98b70f5c
9d8a3f82
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!22
Release 0.3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+2
-1
2 additions, 1 deletion
CHANGELOG.md
src/caosadvancedtools/serverside/helper.py
+0
-70
0 additions, 70 deletions
src/caosadvancedtools/serverside/helper.py
src/caosadvancedtools/webui_formatter.py
+95
-0
95 additions, 0 deletions
src/caosadvancedtools/webui_formatter.py
with
97 additions
and
71 deletions
CHANGELOG.md
+
2
−
1
View file @
be1bca74
...
...
@@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ###
-
the suppression module is now a logging filter
-
The suppression module is now a logging filter.
-
The WebUIHandler is now a python logging formatter.
-
instead of
`get_entity`
, type-specific functions are used in
`cfood.py`
when the type of the entity in question is known.
-
Logger is used instead of
`print`
for errors in
`crawler.py`
.
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/serverside/helper.py
+
0
−
70
View file @
be1bca74
...
...
@@ -23,7 +23,6 @@ from __future__ import absolute_import
import
argparse
import
datetime
import
json
import
logging
import
sys
import
caosdb
as
db
...
...
@@ -141,75 +140,6 @@ def print_error(text):
print_bootstrap
(
"
<b>ERROR:</b>
"
+
text
,
kind
=
"
danger
"
,
file
=
sys
.
stderr
)
class
WebUI_Handler
(
logging
.
StreamHandler
):
"""
allows to make logging to be nicely displayed in the WebUI
You can enable this as follows:
logger = logging.getLogger(
"
<LoggerName>
"
)
logger.addHandler(WebUI_Handler())
"""
def
__init__
(
self
,
*
args
,
full_file
=
None
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
max_elements
=
100
self
.
counter
=
0
self
.
full_file
=
full_file
def
format
(
self
,
record
):
"""
Return the HTML formatted log record for display on a website.
Implementation of the format function as defined by
logging.StreamHandler.
Parameters
----------
record :
Raises
------
RuntimeError
If the log level of the record is not supported. Supported log
levels include logging.DEBUG, logging.INFO, logging.WARNING,
logging.ERROR, and logging.CRITICAL.
Returns
-------
str
The formatted log record.
"""
self
.
counter
+=
1
if
self
.
counter
==
self
.
max_elements
:
return
wrap_bootstrap_alert
(
"
<b>Warning:</b> Due to the large number of messages, the
"
"
output is stopped here. You can see the full log
"
"
<a href=
'
{}
'
>here</a>.
"
.
format
(
self
.
full_file
),
kind
=
"
warning
"
)
if
self
.
counter
>
self
.
max_elements
:
return
""
text
=
str
(
record
.
getMessage
()).
replace
(
"
\n
"
,
r
"
</br>
"
)
text
=
text
.
replace
(
"
\t
"
,
r
"
"
*
4
)
if
record
.
levelno
==
logging
.
DEBUG
:
return
wrap_bootstrap_alert
(
str
(
record
.
getMessage
()),
kind
=
"
info
"
)
elif
record
.
levelno
==
logging
.
INFO
:
return
wrap_bootstrap_alert
(
"
<b>Info:</b>
"
+
text
,
kind
=
"
info
"
)
elif
record
.
levelno
==
logging
.
WARNING
:
return
wrap_bootstrap_alert
(
"
<b>Warning:</b>
"
+
text
,
kind
=
"
warning
"
)
elif
record
.
levelno
==
logging
.
ERROR
:
return
wrap_bootstrap_alert
(
"
<b>ERROR:</b>
"
+
text
,
kind
=
"
danger
"
)
elif
record
.
levelno
==
logging
.
CRITICAL
:
return
wrap_bootstrap_alert
(
"
<b>CRITICAL ERROR:</b>
"
+
text
,
kind
=
"
danger
"
)
else
:
raise
RuntimeError
(
"
Unsupported log level: {}
"
.
format
(
record
.
levelno
))
class
DataModelError
(
RuntimeError
):
"""
DataModelError indicates that the server-side script cannot work as
intended due to missing datat model entities or an otherwise incompatible
...
...
This diff is collapsed.
Click to expand it.
src/caosadvancedtools/webui_formatter.py
0 → 100644
+
95
−
0
View file @
be1bca74
# encoding: utf-8
#
# Copyright (C) 2019, 2020 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2019, 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
import
logging
from
.serverside.helper
import
wrap_bootstrap_alert
class
WebUI_Formatter
(
logging
.
Formatter
):
"""
allows to make logging to be nicely displayed in the WebUI
You can enable this as follows:
logger = logging.getLogger(
"
<LoggerName>
"
)
formatter = WebUI_Formatter(full_file=
"
path/to/file
"
)
handler = logging.Handler()
handler.setFormatter(formatter)
logger.addHandler(handler)
"""
def
__init__
(
self
,
*
args
,
full_file
=
None
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
max_elements
=
100
self
.
counter
=
0
self
.
full_file
=
full_file
def
format
(
self
,
record
):
"""
Return the HTML formatted log record for display on a website.
This essentially wraps the text formatted by the parent class in html.
Parameters
----------
record :
Raises
------
RuntimeError
If the log level of the record is not supported. Supported log
levels include logging.DEBUG, logging.INFO, logging.WARNING,
logging.ERROR, and logging.CRITICAL.
Returns
-------
str
The formatted log record.
"""
msg
=
super
().
format
(
record
)
self
.
counter
+=
1
if
self
.
counter
==
self
.
max_elements
:
return
wrap_bootstrap_alert
(
"
<b>Warning:</b> Due to the large number of messages, the
"
"
output is stopped here. You can see the full log
"
"
<a href=
'
{}
'
>here</a>.
"
.
format
(
self
.
full_file
),
kind
=
"
warning
"
)
if
self
.
counter
>
self
.
max_elements
:
return
""
text
=
msg
.
replace
(
"
\n
"
,
r
"
</br>
"
)
text
=
text
.
replace
(
"
\t
"
,
r
"
"
*
4
)
if
record
.
levelno
==
logging
.
DEBUG
:
return
wrap_bootstrap_alert
(
msg
,
kind
=
"
info
"
)
elif
record
.
levelno
==
logging
.
INFO
:
return
wrap_bootstrap_alert
(
"
<b>Info:</b>
"
+
text
,
kind
=
"
info
"
)
elif
record
.
levelno
==
logging
.
WARNING
:
return
wrap_bootstrap_alert
(
"
<b>Warning:</b>
"
+
text
,
kind
=
"
warning
"
)
elif
record
.
levelno
==
logging
.
ERROR
:
return
wrap_bootstrap_alert
(
"
<b>ERROR:</b>
"
+
text
,
kind
=
"
danger
"
)
elif
record
.
levelno
==
logging
.
CRITICAL
:
return
wrap_bootstrap_alert
(
"
<b>CRITICAL ERROR:</b>
"
+
text
,
kind
=
"
danger
"
)
else
:
raise
Exception
(
"
unknown level
"
)
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