Skip to content
Snippets Groups Projects
Commit 2637f3c9 authored by Felipe Delestro Matos's avatar Felipe Delestro Matos
Browse files

log import updated

parent f83ffcf9
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:24c15e5d tags:
%% Cell type:markdown id:ae2a75fe tags:
# Logging system for qim3d
Using proper logging instead of print statements is a recommended practice in software development for a variety of reasons.
While print statements can be helpful for quick debugging, logging provides a more powerful and versatile approach.
Using proper logging instead of print statements is a recommended practice.
Logging allows for better control over output, with options to configure log levels, filter messages, and redirect output to different destinations.
While print statements can be helpful for quick debugging, logging provides a more powerful and versatile approach. Logging allows for better control over output, with options to configure log levels, filter messages, and redirect output to different destinations.
%% Cell type:code id:a31b2245 tags:
``` python
import qim3d
log = qim3d.log
from qim3d import log
```
%% Cell type:code id:8a2b7c0e tags:
%% Cell type:code id:94022824 tags:
``` python
# Here we test by sending one message for each level
# Note that DEBUG and INFO do not appear
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
warning level message
error level message
critical level message
%% Cell type:code id:b0856333 tags:
``` python
# Change the level to debug
qim3d.io.logger.set_level_DEBUG()
# Now all the levels get logged
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
debug level message
info level message
warning level message
error level message
critical level message
%% Cell type:code id:2824aa8a tags:
%% Cell type:code id:eb542404 tags:
``` python
# Change the level to error
qim3d.io.logger.set_level_ERROR()
# And now only above ERROR is shown
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
error level message
critical level message
%% Cell type:code id:af3cc812 tags:
``` python
# We can increase the level of detail
qim3d.io.logger.set_detailed_output()
# Note that DEBUG and INFO are still not shown
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
ERROR 3224913348.py:8 error level message
CRITICAL 3224913348.py:9 critical level message
%% Cell type:code id:d7239b1b tags:
``` python
# We can switch back to the simple output mode
qim3d.io.logger.set_simple_output()
# Now we see all the levels on simple mode
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
error level message
critical level message
%% Cell type:code id:20857afc tags:
%% Cell type:code id:eaceb5b6 tags:
``` python
# Change back to detailed and DEBUG level
qim3d.io.logger.set_detailed_output()
qim3d.io.logger.set_level_DEBUG()
log.debug('debug level message')
log.info('info level message')
log.warning('warning level message')
log.error('error level message')
log.critical('critical level message')
```
%% Output
DEBUG 4221232047.py:5 debug level message
INFO 4221232047.py:6 info level message
WARNING 4221232047.py:7 warning level message
ERROR 4221232047.py:8 error level message
CRITICAL 4221232047.py:9 critical level message
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment