Skip to content

Clean up logging #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
982ee32
Clean up first example
nezgrath Jul 24, 2025
6feb8c8
Reduce spam
nezgrath Jul 24, 2025
635a625
Tweaking the settings
nezgrath Jul 24, 2025
838f65d
Allow custom message logging
nezgrath Jul 24, 2025
6faeef5
Clean up stop message
nezgrath Jul 24, 2025
e1e9535
Allow verbosity config in example
nezgrath Jul 24, 2025
f971920
Adjust example options
nezgrath Jul 24, 2025
dc3ad30
Add shared function to figure out the log level
nezgrath Jul 24, 2025
79c80e5
Adjust messaging
nezgrath Jul 24, 2025
9907df9
Fail model gen on frist error
nezgrath Jul 25, 2025
d9c05ef
Add operation handler
nezgrath Jul 25, 2025
5840488
Adjust formatting
nezgrath Jul 29, 2025
8b59a71
Add setter/gettter
nezgrath Jul 29, 2025
fc065af
Add async operation handler
nezgrath Jul 29, 2025
983fbb9
Rework the handling using expand argument
nezgrath Jul 29, 2025
c7d186c
Adjust handler naming
nezgrath Jul 30, 2025
0879d17
Adjust log settings
nezgrath Jul 30, 2025
4ecf4cc
Remove tmp message
nezgrath Jul 30, 2025
0bf64af
Get rid of progress mode
nezgrath Jul 31, 2025
af6c15f
Working
nezgrath Aug 4, 2025
382dc3e
Clean up async client shutdown
nezgrath Aug 4, 2025
648a67c
Test adjustments
nezgrath Aug 4, 2025
9113995
Adjust log output for tests
nezgrath Aug 4, 2025
640649d
Revert last change
nezgrath Aug 4, 2025
7620e01
Extra output in case of handler failures
nezgrath Aug 4, 2025
9d9a492
Test corrections
nezgrath Aug 4, 2025
e72c724
Fix async client
nezgrath Aug 4, 2025
d01125f
Remove duplicate log type
nezgrath Aug 5, 2025
13aa496
Fix stderr redirect
nezgrath Aug 5, 2025
9a1d1be
Style corrections
nezgrath Aug 5, 2025
04a70ed
Add binary download progress information
nezgrath Aug 6, 2025
d11013e
Adjust worker download message
nezgrath Aug 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,4 @@ cython_debug/
build_info.*
doc/source/api/_autosummary
test_run/
**/dt_download/worker/**
21 changes: 7 additions & 14 deletions examples/basic/00_file_operations_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
import typer
from typing_extensions import Annotated

from ansys.hps.data_transfer.client import Client, DataTransferApi
from ansys.hps.data_transfer.client import Client, DataTransferApi, get_log_level
from ansys.hps.data_transfer.client.authenticate import authenticate
from ansys.hps.data_transfer.client.models.msg import SrcDst, StoragePath


log = logging.getLogger(__name__)

####################################
Expand All @@ -56,11 +57,6 @@ def file_operations(api: DataTransferApi, local_path: str, remote_path: Optional
if not remote_path:
remote_path = Path(local_path).parent.name

log.info("Query storages ...")
storages = api.storages()
storage_names = [f"{storage['name']}({storage['type']})" for storage in storages]
log.info(f"Available storages: {storage_names}")

log.info("Creating a directory ...")
base_dir = "basic-example"
mkdir_op = api.mkdir([StoragePath(path=f"{base_dir}")])
Expand All @@ -73,12 +69,10 @@ def file_operations(api: DataTransferApi, local_path: str, remote_path: Optional

op = api.copy([SrcDst(src=src, dst=dst) for src, dst in zip(srcs, dsts)])
op = api.wait_for([op.id])
log.info(f"Operation {op[0].state}")

log.info("Listing files ...")
op = api.list([StoragePath(path=base_dir)])
op = api.wait_for([op.id])
log.info(f"Operation {op[0].state}")
log.info(f"Files in {base_dir}: {op[0].result}")

log.info("Getting metadata ...")
Expand All @@ -90,7 +84,6 @@ def file_operations(api: DataTransferApi, local_path: str, remote_path: Optional
log.info("Removing files ...")
op = api.rmdir([StoragePath(path=base_dir)])
op = api.wait_for([op.id])
log.info(f"Operation {op[0].state}")

####################################
# Define the main function
Expand All @@ -99,16 +92,15 @@ def main(
local_path: Annotated[str, typer.Option(help="Path to the files or directory to transfer. Supports wildcards.")],
remote_path: Annotated[str, typer.Option(help="Optional path to the remote directory to transfer files to.")] = None,
debug: Annotated[bool, typer.Option(help="Enable debug logging.")] = False,
verbosity: Annotated[int, typer.Option(help="Increase verbosity")] = 1,
url: Annotated[str, typer.Option(help="HPS URL to connect to.")] = "https://localhost:8443/hps",
username: Annotated[str, typer.Option(help="Username to authenticate with.")] = "repadmin",
password: Annotated[
str, typer.Option(prompt=True, hide_input=True, help="Password to authenticate with.")
] = "repadmin",
):
logging.basicConfig(format="%(levelname)8s > %(message)s", level=get_log_level(verbosity, debug))

logging.basicConfig(
format="[%(asctime)s | %(levelname)s] %(message)s", level=logging.DEBUG if debug else logging.INFO
)

dt_url = f"{url}/dt/api/v1"
auth_url = f"{url}/auth/realms/rep"
Expand All @@ -121,8 +113,9 @@ def main(
client = Client(clean=True)

client.binary_config.update(
verbosity=3,
debug=False,
verbosity=verbosity,
debug=debug,
log=debug,
insecure=True,
token=token,
data_transfer_url=dt_url,
Expand Down
17 changes: 6 additions & 11 deletions examples/basic/01_async_data_transfer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,23 @@
import typer
from typing_extensions import Annotated

from ansys.hps.data_transfer.client import AsyncClient, AsyncDataTransferApi
from ansys.hps.data_transfer.client import AsyncClient, AsyncDataTransferApi, get_log_level
from ansys.hps.data_transfer.client.authenticate import authenticate
from ansys.hps.data_transfer.client.models.msg import SrcDst, StoragePath

log = logging.getLogger(__name__)
logger = logging.getLogger()
logging.basicConfig(format="%(asctime)s %(levelname)8s > %(message)s", level=logging.DEBUG)


async def main(
debug: Annotated[bool, typer.Option(help="Enable debug logging")] = False,
verbosity: Annotated[int, typer.Option(help="Increase verbosity")] = 1,
url: Annotated[str, typer.Option(help="HPS URL to connect to")] = "https://localhost:8443/hps",
username: Annotated[str, typer.Option(help="Username to authenticate with")] = "repadmin",
password: Annotated[
str, typer.Option(prompt=True, hide_input=True, help="Password to authenticate with")
] = "repadmin",
):

log = logging.getLogger()
logging.basicConfig(format="%(levelname)8s > %(message)s", level=get_log_level(verbosity, debug))

dt_url = f"{url}/dt/api/v1"
auth_url = f"{url}/auth/realms/rep"
token = authenticate(username=username, password=password, verify=False, url=auth_url)
Expand All @@ -75,7 +74,7 @@ async def main(
client = AsyncClient(clean=True)

client.binary_config.update(
verbosity=3,
verbosity=verbosity,
debug=debug,
insecure=True,
token=token,
Expand Down Expand Up @@ -113,20 +112,17 @@ async def main(

op = await api.copy([SrcDst(src=src, dst=dst) for src, dst in zip(srcs, dsts)])
op = await api.wait_for([op.id])
log.info(f"Operation {op[0].state}")

files = glob.glob(os.path.join(os.path.dirname(__file__), "*.txt"))
srcs = [StoragePath(path=file, remote="local") for file in files]
dsts = [StoragePath(path=f"{os.path.basename(file)}") for file in files]

op = await api.copy([SrcDst(src=src, dst=dst) for src, dst in zip(srcs, dsts)])
op = await api.wait_for([op.id])
log.info(f"Operation {op[0].state}")

log.info("Listing files ...")
op = await api.list([StoragePath(path=base_dir)])
op = await api.wait_for([op.id])
log.info(f"Operation {op[0].state}")
log.info(f"Files in {base_dir}: {op[0].result}")

log.info("Getting metadata ...")
Expand All @@ -138,7 +134,6 @@ async def main(
log.info("Removing files ...")
op = await api.rmdir([StoragePath(path=base_dir)])
op = await api.wait_for([op.id])
log.info(f"Operation {op[0].state}")

await client.stop()

Expand Down
11 changes: 5 additions & 6 deletions examples/permissions/set_permissions_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import typer
from typing_extensions import Annotated

from ansys.hps.data_transfer.client import Client, DataTransferApi
from ansys.hps.data_transfer.client import Client, DataTransferApi, get_log_level
from ansys.hps.data_transfer.client.authenticate import authenticate
from ansys.hps.data_transfer.client.models.msg import SrcDst, StoragePath
from ansys.hps.data_transfer.client.models.permissions import (
Expand Down Expand Up @@ -235,15 +235,14 @@ def permissions(api: DataTransferApi, url: str):
# ========================
def main(
debug: Annotated[bool, typer.Option(help="Enable debug logging")] = False,
verbosity: Annotated[int, typer.Option(help="Increase verbosity")] = 1,
url: Annotated[str, typer.Option(help="HPS URL to connect to")] = "https://localhost:8443/hps",
username: Annotated[str, typer.Option(help="Username to authenticate with")] = "repadmin",
password: Annotated[
str, typer.Option(prompt=True, hide_input=True, help="Password to authenticate with")
] = "repadmin",
):
logging.basicConfig(
format="[%(asctime)s | %(levelname)s] %(message)s", level=logging.DEBUG if debug else logging.INFO
)
logging.basicConfig(format="%(levelname)8s > %(message)s", level=get_log_level(verbosity, debug))

dt_url = f"{url}/dt/api/v1"
auth_url = f"{url}/auth/realms/rep"
Expand All @@ -256,8 +255,8 @@ def main(
client = Client(clean=True)

client.binary_config.update(
verbosity=3,
debug=False,
verbosity=verbosity,
debug=debug,
insecure=True,
token=token,
data_transfer_url=dt_url,
Expand Down
26 changes: 18 additions & 8 deletions examples/startup/data_transfer_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@
import typer
from typing_extensions import Annotated

from ansys.hps.data_transfer.client import Client, DataTransferApi
from ansys.hps.data_transfer.client import Client, DataTransferApi, get_log_level
from ansys.hps.data_transfer.client.authenticate import authenticate


def main(
debug: Annotated[bool, typer.Option(help="Enable debug logging")] = False,
verbosity: Annotated[int, typer.Option(help="Increase verbosity")] = 1,
url: Annotated[str, typer.Option(help="HPS URL to connect to")] = "https://localhost:8443/hps",
username: Annotated[str, typer.Option(help="Username to authenticate with")] = "repadmin",
password: Annotated[
Expand All @@ -55,34 +56,43 @@ def main(

auth_url = f"{url}/auth/realms/rep"
log = logging.getLogger()
logging.basicConfig(format="%(levelname)8s > %(message)s", level=logging.DEBUG)
logging.basicConfig(format="%(levelname)8s > %(message)s", level=get_log_level(verbosity, debug))

user_token = authenticate(username=username, password=password, verify=False, url=auth_url)
user_token = user_token.get("access_token", None)
assert user_token is not None

client = Client()
client.binary_config.update(
verbosity=3,
debug=debug,
insecure=True,
token=user_token,
verbosity=verbosity,
)
if debug:
client.binary_config.update(verbosity=3, debug=True)

client.binary_config.debug = True
client.start()
api = DataTransferApi(client)
s = api.status(wait=True)
log.info("Status: %s" % s)

log.info("--- Worker info ---")
log.info(f"Ready: {s.ready}")
log.info(f"Build info:")
for k, v in s.build_info.__dict__.items():
log.info(f" {k}: {v}")
log.info(f"Features:")
for k, v in s.features.__dict__.items():
log.info(f" {k}: {v}")
log.info("Available storage:")
for d in api.storages():
log.info(f"- {json.dumps(d, indent=4)}")
log.info(f" name={d['name']} type={d['type']} priority={d['priority']}")

for i in range(10):
log.info("--- Idling for a while ---")
for i in range(5):
log.info("Idling for a while...")
time.sleep(2)

log.info("--- Stopping ---")
client.stop()


Expand Down
Loading