Skip to content

Commit

Permalink
Logging & Import Updates (#123)
Browse files Browse the repository at this point in the history
See PR description.
  • Loading branch information
wtgee authored Mar 4, 2020
1 parent 0a0633a commit 4631a2b
Show file tree
Hide file tree
Showing 45 changed files with 581 additions and 950 deletions.
105 changes: 84 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@
[![codecov](https://codecov.io/gh/panoptes/panoptes-utils/branch/develop/graph/badge.svg)](https://codecov.io/gh/panoptes/panoptes-utils)
[![Documentation Status](https://readthedocs.org/projects/panoptes-utils/badge/?version=latest)](https://panoptes-utils.readthedocs.io/en/latest/?badge=latest)

# PANOPTES Utils
PANOPTES Utils
--------------

- [PANOPTES Utils](#panoptes-utils)
- [Getting](#getting)
- [pip](#pip)
- [Docker](#docker)
- [Using](#using)
- [Modules](#modules)
- [Services](#services)
- [Config Server](#config-server)
- [Messaging Hub](#messaging-hub)
- [Logger](#logger)
- [Development](#development)
- [Logging](#logging)

Utility functions for use within the PANOPTES ecosystem and for general astronomical processing.

This library defines a number of modules that contain useful functions as well as a few
[services](#services).

See the full documentation at: https://panoptes-utils.readthedocs.io

# Install
<a href="#" name='install'></a>
## Getting

See [Docker](#docker) for ways to run `panoptes-utils` services without installing to your host computer.

> See [Docker](#docker) for ways to run that `panoptes-utils` without installing
to your host computer.
### pip

To install type:

Expand All @@ -24,21 +41,44 @@ pip install panoptes-utils
There are also a number of optional dependencies, which can be installed as following:

```bash
pip install "panoptes-utils[social,test]"
pip install "panoptes-utils[social,testing]"
# -or-
pip install "panoptes-utils[all]"
```

# Services
<a href="#" name='services'></a>
### Docker

Docker containers are available for running the `panoptes-utils` module and associated services, which also serve as the base container for all other PANOPTES related containers.

See our [Docker documentation](https://panoptes-utils.readthedocs.io/en/latest/docker.html) for details.

## Using
### Modules

The modules can be used as helper utilities anywhere you would like. See the complete documentation for details: [https://panoptes-utils.readthedocs.io/en/latest/](https://panoptes-utils.readthedocs.io/en/latest/).

## Config Server
<a href="#" name='config-server'></a>
### Services

The services can be run either from a [docker](#docker) image or from the installed script, as described below.

#### Config Server

A simple config param server. Runs as a Flask microservice that delivers JSON documents
in response to requests for config key items.

For more details and usage examples, see the [config server README](panoptes/utils/config/README.md).

Can be run from the installed script (defaults to `http://localhost:6563/get-config`):

```bash
$ bin/panoptes-config-server
* Serving Flask app "panoptes.utils.config.server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
```

Or inside a python process:

```python
>>> from panoptes.utils.config.server import config_server
Expand All @@ -52,21 +92,44 @@ For more details and usage examples, see the [config server README](panoptes/uti
>>> server_process.terminate() # Or just exit notebook/console
```

## Messaging Hub
<a href="#" name='messaging-hub'></a>
For more details and usage examples, see the [config server README](panoptes/utils/config/README.md).

#### Messaging Hub

The messaging hub is responsible for relaying zeromq messages between the various components of a
PANOPTES system. Running the Messaging Hub will set up a forwarding service that allows for an arbitrary
number of publishers and subscribers.
The messaging hub is responsible for relaying zeromq messages between the various components of a PANOPTES system. Running the Messaging Hub will set up a forwarding service that allows for an arbitrary number of publishers and subscribers.

```bash
panoptes-messaging-hub --from-config
```

## Docker
<a name="docker"></a>
#### Logger

Docker containers are available for running the `panoptes - utils` module and associated services, which
also serve as the base container for all other PANOPTES related containers.
A basic logger is defined in `panoptes.utils.logger.get_root_logger()`, which configures a [loguru](https://github.com/Delgan/loguru) logger with some defaults that are suitable to [POCS](https://github.com/panoptes/POCS).

See our [Docker documentation](https://panoptes-utils.readthedocs.io/en/latest/docker.html) for details.
For now this will remain part of this repository but may move directly to POCS in the future as it is likely to be unused by others.

## Development

### Logging

The `panoptes-utils` module uses [`loguru`](https://github.com/Delgan/loguru) for logging, which also serves as the basis for the POCS logger (see [Logger](#logger)).

To access the logs for the module, you can import directly from the `logger` module, i.e., `from panoptes.utils.logger import logger`. This is a simple wrapper around `luguru` with no extra configuration:

```python
>>> from panoptes.utils import CountdownTimer
>>> # No logs by default
>>> t0 = CountdownTimer(5)
>>> t0.sleep()
False

>>> # Enable the logs
>>> from panoptes.utils.logger import logger
>>> logger.enable('panoptes')

>>> t1 = CountdownTimer(5)
2020-03-04 06:42:50 | DEBUG | panoptes.utils.time:restart:162 - Restarting Timer (blocking) 5.00/5.00
>>> t1.sleep()
2020-03-04 06:42:53 | DEBUG | panoptes.utils.time:sleep:183 - Sleeping for 2.43 seconds
False
```
5 changes: 3 additions & 2 deletions bin/panoptes-messaging-hub
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import time

from astropy.utils import console
from panoptes.utils.config.client import get_config
from panoptes.utils.logger import get_root_logger
from panoptes.utils.messaging import PanMessaging
from panoptes.utils.logger import logger


the_root_logger = None

Expand Down Expand Up @@ -153,6 +154,6 @@ if __name__ == '__main__':
if not sub_and_pub_pairs:
arg_error('Found no port pairs to forward between.')

the_root_logger = get_root_logger()
the_root_logger = logger

run_forwarders(sub_and_pub_pairs)
56 changes: 37 additions & 19 deletions conda-requirements-amd64.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
astropy
cffi
Flask
jupyter_console
libffi
matplotlib-base
numpy
pip
psycopg2
pyserial
python-dateutil
PyYAML
pyzmq
readline
scikit-image
scikit-learn
scipy
tornado
zeromq
name: panoptes
channels:
- astropy
- conda-forge
dependencies:
- astroplan>=0.6
- astropy>=4.0.0
- codecov
- coverage
- coveralls
- Flask
- ipython
- loguru
- matplotlib-base>=3.0.0
- numpy
- photutils
- pip
- pycodestyle
- pyserial
- pytest-cov
- pytest-remotedata>=0.3.1
- pytest
- python-dateutil
- python-json-logger
- PyYAML
- pyzmq
- readline
- requests
- ruamel.yaml>=0.15
- scikit-image
- scipy
- tweepy
- versioneer
- zeromq
- pip:
- scalpl
- mocket
Loading

0 comments on commit 4631a2b

Please sign in to comment.