Pre-configured file, web, and email logging for Mindscope neuropixels projects, repackaging code from AIBS mpeconfig.
Project description
For use on internal Allen Institute network
import logging
import np_logging
np_logging.setup()
runs automatically on import to add handlers and loggers from a default config,
then the built-in python logging
module can be used as normal.
The default config provides the loggers web
and email
, in addition to the default
root
which includes file handlers for logging.INFO
and logging.DEBUG
levels, plus
console logging.
Usage example:
logging.getLogger('web').info('test: web server')
logging.getLogger('email').info('test: email logger')
logging.debug('test: root logger')
By default, a message is logged reporting the elapsed time and cause of termination. If an exception was raised, the traceback is included.
-
user configs can be specified according to the python logging library dict schema
-
the default config is fetched from the ZooKeeper server
eng-mindscope:2181
-
configs can be added via ZooNavigator webview: http://eng-mindscope:8081
-
or more conveniently, via an extension for VSCode such as gaoliang.visual-zookeeper
ZooKeeper configs can be fetched via their path:
test_config: dict = np_logging.fetch_zk_config(
'/projects/np_logging_test/defaults/logging'
)
If the package can't connect to ZooKeeper, it will alert the user and fall back to a file containing a default logging dict.
Once a logging config dict has been modified as necessary...
test_config['handlers']['email_handler']['toaddrs'] = username@alleninstitute.org
re-run the logging setup with the new config dict:
np_logging.setup(
config: dict = test_config,
project_name = 'test',
)
project_name
should be supplied to use the web logger - if unspecified, the name of the current working directory is used- the web log can be viewed at http://eng-mindscope:8080
Other input arguments to np_logging.setup()
:
-
log_at_exit
(defaultTrue
)- If
True
, a message is logged when the program terminates, reporting total elapsed time.
- If
-
email_at_exit
(defaultFalse
)-
If
True
, an email is sent when the program terminates, reporting the elapsed time and cause of termination. If an exception was raised, the traceback is included. -
If
logging.error
, the email is only sent if the program terminates via an exception.
-
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for np_logging-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d67d029830b1deb53eb5ddca3ffb0be2b0a391416b302735e6e24aad18a4679f |
|
MD5 | f7c09b84eddb6e349caa7ce2600fff51 |
|
BLAKE2b-256 | 45a43cbc45007704f476d579b9459e85b606eff20e71d94c790d6971b189c22b |