Skip to content

Commit

Permalink
cleaned logging and added discord option
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Sep 28, 2024
1 parent ffb2648 commit 27eb978
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 195 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
requires-python = ">=3.8"
dependencies = [
"click >=8.1",
"discord",
"fileformats-medimage-extras",
"pydicom >=2.3.1",
"tqdm >=4.64.1",
Expand Down
72 changes: 15 additions & 57 deletions xnat_ingest/cli/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
from xnat_ingest.utils import (
AssociatedFiles,
logger,
LogFile,
LogEmail,
MailServer,
LoggerConfig,
XnatLogin,
set_logger_handling,
)
Expand Down Expand Up @@ -145,63 +143,29 @@
help="Whether to delete the session directories after they have been uploaded or not",
)
@click.option(
"--log-level",
default="info",
type=str,
envvar="XINGEST_LOGLEVEL",
help=("The level of the logging printed to stdout"),
)
@click.option(
"--log-file",
"log_files",
default=None,
type=LogFile.cli_type,
"--logger",
"loggers",
multiple=True,
nargs=2,
metavar="<path> <loglevel>",
envvar="XINGEST_LOGFILE",
help=(
'Location to write the output logs to, defaults to "upload-logs" in the '
"export directory"
),
)
@click.option(
"--log-email",
"log_emails",
type=LogEmail.cli_type,
type=LoggerConfig.cli_type,
envvar="XINGEST_LOGGERS",
nargs=3,
metavar="<address> <loglevel> <subject-preamble>",
multiple=True,
envvar="XINGEST_LOGEMAIL",
help=(
"Email(s) to send logs to. When provided in an environment variable, "
"mail and log level are delimited by ',' and separate destinations by ';'"
),
default=(),
metavar="<logtype> <loglevel> <location>",
help=("Setup handles to capture logs that are generated"),
)
@click.option(
"--add-logger",
"--additional-logger",
"additional_loggers",
type=str,
multiple=True,
default=(),
envvar="XINGEST_LOGGERS",
envvar="XINGEST_ADDITIONAL_LOGGERS",
help=(
"The loggers to use for logging. By default just the 'xnat-ingest' logger is used. "
"But additional loggers can be included (e.g. 'xnat') can be "
"specified here"
),
)
@click.option(
"--mail-server",
type=MailServer.cli_type,
nargs=4,
metavar="<host> <sender-email> <user> <password>",
default=None,
envvar="XINGEST_MAILSERVER",
help=(
"the mail server to send logger emails to. When provided in an environment variable, "
"args are delimited by ';'"
),
)
@click.option(
"--raise-errors/--dont-raise-errors",
default=False,
Expand Down Expand Up @@ -297,11 +261,8 @@ def stage(
resource_field: str,
project_id: str | None,
delete: bool,
log_level: str,
log_files: ty.List[LogFile],
log_emails: ty.List[LogEmail],
add_logger: ty.List[str],
mail_server: MailServer,
loggers: ty.List[LoggerConfig],
additional_loggers: ty.List[str],
raise_errors: bool,
deidentify: bool,
xnat_login: XnatLogin,
Expand All @@ -315,11 +276,8 @@ def stage(
work_dir: Path | None = None,
) -> None:
set_logger_handling(
log_level=log_level,
log_emails=log_emails,
log_files=log_files,
mail_server=mail_server,
add_logger=add_logger,
logger_configs=loggers,
additional_loggers=additional_loggers,
)

if xnat_login:
Expand Down
69 changes: 14 additions & 55 deletions xnat_ingest/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
from xnat_ingest.resource import ImagingResource
from xnat_ingest.utils import (
logger,
LogFile,
LogEmail,
MailServer,
LoggerConfig,
set_logger_handling,
StoreCredentials,
)
Expand Down Expand Up @@ -55,41 +53,19 @@
@click.argument("user", type=str, envvar="XINGEST_USER")
@click.option("--password", default=None, type=str, envvar="XINGEST_PASS")
@click.option(
"--log-level",
default="info",
type=str,
envvar="XINGEST_LOGLEVEL",
help=("The level of the logging printed to stdout"),
)
@click.option(
"--log-file",
"log_files",
default=None,
type=LogFile.cli_type,
nargs=2,
metavar="<path> <loglevel>",
"--logger",
"loggers",
multiple=True,
envvar="XINGEST_LOGFILE",
help=(
'Location to write the output logs to, defaults to "upload-logs" in the '
"export directory"
),
)
@click.option(
"--log-email",
"log_emails",
type=LogEmail.cli_type,
type=LoggerConfig.cli_type,
envvar="XINGEST_LOGGERS",
nargs=3,
metavar="<address> <loglevel> <subject-preamble>",
multiple=True,
envvar="XINGEST_LOGEMAIL",
help=(
"Email(s) to send logs to. When provided in an environment variable, "
"mail and log level are delimited by ',' and separate destinations by ';'"
),
default=(),
metavar="<logtype> <loglevel> <location>",
help=("Setup handles to capture logs that are generated"),
)
@click.option(
"--add-logger",
"--additional-logger",
"additional_loggers",
type=str,
multiple=True,
default=(),
Expand All @@ -100,17 +76,6 @@
"specified here"
),
)
@click.option(
"--mail-server",
type=MailServer.cli_type,
metavar="<host> <sender-email> <user> <password>",
default=None,
envvar="XINGEST_MAILSERVER",
help=(
"the mail server to send logger emails to. When provided in an environment variable, "
"args are delimited by ';'"
),
)
@click.option(
"--always-include",
"-i",
Expand Down Expand Up @@ -215,12 +180,9 @@ def upload(
server: str,
user: str,
password: str,
log_level: str,
log_files: ty.List[LogFile],
log_emails: ty.List[LogEmail],
mail_server: MailServer,
loggers: ty.List[LoggerConfig],
additional_loggers: ty.List[str],
always_include: ty.Sequence[str],
add_logger: ty.List[str],
raise_errors: bool,
store_credentials: StoreCredentials,
temp_dir: ty.Optional[Path],
Expand All @@ -234,11 +196,8 @@ def upload(
) -> None:

set_logger_handling(
log_level=log_level,
log_emails=log_emails,
log_files=log_files,
mail_server=mail_server,
add_logger=add_logger,
logger_configs=loggers,
additional_loggers=additional_loggers,
)

# Set the directory to create temporary files/directories in away from system default
Expand Down
Loading

0 comments on commit 27eb978

Please sign in to comment.