Metadata-Version: 2.4
Name: zfl
Version: 0.1.7
Summary: Data server via HTTPS POST
Author-email: Patrick Holthaus <patrick.holthaus@googlemail.com>
License-Expression: BSD-2-Clause
Project-URL: Homepage, https://gitlab.com/robothouse/rh-projects/hospital-at-home/data-server/
Project-URL: Bug Tracker, https://gitlab.com/robothouse/rh-projects/hospital-at-home/data-server/issues/
Classifier: Programming Language :: Python
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: cherrypy
Requires-Dist: filelock
Requires-Dist: pydantic
Requires-Dist: ztl>=0.3.2
Dynamic: license-file

# Federated Data Logger

This project enables federated logging based on ZTL/ZMQ. It provides the `zfl` package on pypi.

## Installation

Install `zfl` in your python virtual environment:

```
pip install zfl
```

## Configuration

To use the logging service, the client needs a configuration file to specify how to reach the logging server. Refer to https://gitlab.com/robothouse/rh-projects/hospital-at-home/documentation/-/wikis/Reference-System for the hospital@home study setup. Here, we will use `147.197.166.151` as the host as it is currently configured as the test system in the lab.

Check the file `~/.config/zmq-remotes.yaml` for `federation` endpoints. If you don't have this file, run the following command:

```bash
cat <<'EOF'>> ~/.config/zmq-remotes.yaml 
remotes:
  federation:
    host: "147.197.166.151"
    port: 5678
    scope: "/log"
publishers:
  federation:
    host: "147.197.166.151"
    port: 5778
    scope: "/log"
EOF
```

If you don't have access to an existing logging service, you can spawn your own server by running the service yourself. You need to adjust the above configuration file accordingly. Note that this example does not enable remote logging in the cloud, only local file logging and cache:

```bash
zfl_logging_service
```

## Usage

Import `SystemState` from the `zfl` package and use it:

```python
from zfl.logging.state import SystemState
state = SystemState()
```

To log your component's state, use `update_state()` with a `dict`. Use the `cloud` parameter to enable federated logging in the cloud:

```python
state.update_state(
    {
        "my-component":
            {
                "example": 2,
                "state": "enabled"
            }
    },
    cloud = True)
```

To get the most recent state, use `get_state()`:

```python
curent_state = state.get_state()
print(current_state)
```

Check the [example](src/zfl/examples/main_logging_example.py) for an up-to-date usage example, including callback registration.
