Metadata-Version: 2.1
Name: np-logging
Version: 0.1.2
Summary: Pre-configured file, web and email logging for neuropixels projects, repackaging code from mpeconfig.
Author: Ben hardcastle
Author-email: ben.hardcastle@alleninstitute.org
Maintainer: Ben hardcastle
Maintainer-email: ben.hardcastle@alleninstitute.org
Requires-Python: >=3.6,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: kazoo (>=2.8.0,<3.0.0)
Requires-Dist: pyyaml (>=5.3.0,<6.0.0)
Project-URL: Bug Tracker, https://github.com/alleninstitute/np_logging/issues
Project-URL: Repository, https://github.com/alleninstitute/np_logging
Description-Content-Type: text/markdown

```
import np_config
```

`np_config.setup()` will run automatically on import using a default logging config.

- user configs can be specified according to the [`logging` library dict schema](https://docs.python.org/3/library/logging.config.html#logging-config-dictschema)

- the default config is fetched from the
ZooKeeper server `eng-mindscope:2181`
- configs can be added via ZooNavigator webview:
  [http://eng-mindscope:8081](http://eng-mindscope:8081)
- or more conveniently, via an extension for VSCode such as [gaoliang.visual-zookeeper](https://marketplace.visualstudio.com/items?itemName=gaoliang.visual-zookeeper)

ZooKeeper configs can be fetched via their path:
```
test_config: dict = np_config.fetch_zk_config(
    '/projects/np_logging_test/defaults/logging'
)
```

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_config.setup(
    config: dict = test_config,
    project_name = 'test',
)
```

- `project_name` must be supplied to use the web logger
- web log can be viewed at [http://eng-mindscope:8080](http://eng-mindscope:8080)

The default config provides the loggers `web` and `email`, in addition to the default
`root` which includes file handlers
for info and debug logging levels, plus console logging:
```
logging.getLogger('web').info('test message')
logging.getLogger('email').info('test message')
logging.debug('test message to files and console')
```


Other parameters to `np_config.setup()`:
- `log_at_exit` (default `True`)

    - If `True`, a message is logged when the program terminates, reporting total
      elapsed time.

- `email_at_exit` (default `False`)

    - 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.


