-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from bsc-dom/logger-config
client config logger
- Loading branch information
Showing
7 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ dataClay | |
main-concepts | ||
alien-objects | ||
advanced-usage | ||
logging | ||
examples/index | ||
|
||
.. toctree:: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
======= | ||
Logging | ||
======= | ||
|
||
DataClay offers logging to allow code debugging and information collection. | ||
|
||
When dataclay is imported, the logging is first initialized with a basic configuration in the config.py file: | ||
|
||
.. code-block:: python | ||
:caption: config.py | ||
... | ||
class Settings(BaseSettings): | ||
... | ||
loglevel: Annotated[str, StringConstraints(strip_whitespace=True, to_upper=True)] = "INFO" | ||
... | ||
settings = Settings() | ||
... | ||
def logger_config(**kwargs): | ||
logging.basicConfig(**kwargs) | ||
logger_config(level=settings.loglevel) | ||
If the user wants to configure its own logging, it can be done by importing the logging library and modifying | ||
the basicConfig. When client.start() function is called, then logger_config() is executed again, and if the argument | ||
"force" is True then the logging configuration is overwritten. | ||
|
||
.. warning:: | ||
When modifying the basicConfig remember that the **force=True** parameter is mandatory. Otherwise, this new | ||
configuration will be obviated. | ||
|
||
An example is available in `GitHub <https://github.com/bsc-dom/dataclay/tree/main/examples/client-logger-config>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import logging | ||
import os | ||
|
||
from model.client_model import ClientModel | ||
|
||
from dataclay import Client | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
logger.debug("First Debug log") | ||
logger.info("First Info log") | ||
|
||
logging.basicConfig(force=True, level=getattr(logging, os.getenv("LOG_LEVEL", "DEBUG").upper())) | ||
dclogger = logging.getLogger("dataclay") | ||
dclogger.setLevel(logging.INFO) | ||
grpclogger = logging.getLogger("grpc") | ||
grpclogger.setLevel(logging.INFO) | ||
|
||
client = Client(host="127.0.0.1", username="testuser", password="s3cret", dataset="testdata") | ||
client.start() | ||
|
||
client_mod = ClientModel("Client") | ||
client_mod.make_persistent("alias") | ||
|
||
name = client_mod.get_name() | ||
logger.debug("My name is : %s", name) | ||
logger.info("My name is : %s", name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
services: | ||
|
||
redis: | ||
image: redis:latest | ||
ports: | ||
- 6379:6379 | ||
|
||
metadata-service: | ||
image: "ghcr.io/bsc-dom/dataclay:dev" | ||
depends_on: | ||
- redis | ||
ports: | ||
- 16587:16587 | ||
environment: | ||
- DATACLAY_KV_HOST=redis | ||
- DATACLAY_KV_PORT=6379 | ||
- DATACLAY_ID | ||
- DATACLAY_PASSWORD=s3cret | ||
- DATACLAY_USERNAME=testuser | ||
- DATACLAY_DATASET=testdata | ||
- DATACLAY_METADATA_PORT=16587 | ||
- DATACLAY_LOGLEVEL=DEBUG | ||
command: python -m dataclay.metadata | ||
|
||
backend: | ||
image: "ghcr.io/bsc-dom/dataclay:dev" | ||
depends_on: | ||
- redis | ||
ports: | ||
- 6867:6867 | ||
environment: | ||
- DATACLAY_KV_HOST=redis | ||
- DATACLAY_KV_PORT=6379 | ||
- DATACLAY_BACKEND_ID | ||
- DATACLAY_BACKEND_NAME | ||
- DATACLAY_BACKEND_PORT=6867 | ||
- DATACLAY_LOGLEVEL=DEBUG | ||
command: python -m dataclay.backend | ||
volumes: | ||
- ./model:/workdir/model:ro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from dataclay import DataClayObject, activemethod | ||
|
||
|
||
class ClientModel(DataClayObject): | ||
|
||
name: str | ||
|
||
@activemethod | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
@activemethod | ||
def change_name(self, name): | ||
self.name = name | ||
|
||
@activemethod | ||
def get_name(self): | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters