diff --git a/docs/how-to/configure-logging.md b/docs/how-to/configure-logging.md index 845c64cd26..198c1b3fb5 100644 --- a/docs/how-to/configure-logging.md +++ b/docs/how-to/configure-logging.md @@ -25,8 +25,8 @@ BlueAPI is configured to handle logging from any python code it executes. ``` import logging -logger = logging.getLogger(__name__) -logger.info("FOO") +LOGGER = logging.getLogger(__name__) +LOGGER.info("FOO") ``` # Kubernetes diff --git a/src/blueapi/cli/cli.py b/src/blueapi/cli/cli.py index c39ff13dff..e70922b9c5 100644 --- a/src/blueapi/cli/cli.py +++ b/src/blueapi/cli/cli.py @@ -42,6 +42,8 @@ from .scratch import setup_scratch from .updates import CliEventRenderer +LOGGER = logging.getLogger(__name__) + @click.group( invoke_without_command=True, context_settings={"auto_envvar_prefix": "BLUEAPI"} @@ -493,7 +495,7 @@ def logout(obj: dict) -> None: except FileNotFoundError: print("Logged out") except ValueError as e: - logging.debug("Invalid login token: %s", e) + LOGGER.debug("Invalid login token: %s", e) raise ClickException( "Login token is not valid - remove before trying again" ) from e diff --git a/src/blueapi/cli/scratch.py b/src/blueapi/cli/scratch.py index e81260326e..5011819f95 100644 --- a/src/blueapi/cli/scratch.py +++ b/src/blueapi/cli/scratch.py @@ -15,6 +15,8 @@ _DEFAULT_INSTALL_TIMEOUT: float = 300.0 +LOGGER = logging.getLogger(__name__) + def setup_scratch( config: ScratchConfig, install_timeout: float = _DEFAULT_INSTALL_TIMEOUT @@ -30,7 +32,7 @@ def setup_scratch( _validate_root_directory(config.root, config.required_gid) - logging.info(f"Setting up scratch area: {config.root}") + LOGGER.info(f"Setting up scratch area: {config.root}") """ fail early """ for repo in config.repositories: @@ -64,12 +66,12 @@ def ensure_repo(remote_url: str, local_directory: Path) -> None: os.umask(stat.S_IWOTH) if not local_directory.exists(): - logging.info(f"Cloning {remote_url}") + LOGGER.info(f"Cloning {remote_url}") Repo.clone_from(remote_url, local_directory) - logging.info(f"Cloned {remote_url} -> {local_directory}") + LOGGER.info(f"Cloned {remote_url} -> {local_directory}") elif local_directory.is_dir(): Repo(local_directory) - logging.info(f"Found {local_directory}") + LOGGER.info(f"Found {local_directory}") else: raise KeyError( f"Unable to open {local_directory} as a git repository because it is a file" @@ -90,7 +92,7 @@ def scratch_install(path: Path, timeout: float = _DEFAULT_INSTALL_TIMEOUT) -> No _validate_directory(path) - logging.info(f"Installing {path}") + LOGGER.info(f"Installing {path}") process = Popen( [ "uv", diff --git a/src/blueapi/client/numtracker.py b/src/blueapi/client/numtracker.py index 3ec7a9ab8c..9fb83ec959 100644 --- a/src/blueapi/client/numtracker.py +++ b/src/blueapi/client/numtracker.py @@ -8,6 +8,8 @@ from blueapi.utils import BlueapiBaseModel +LOGGER = logging.getLogger(__name__) + class DirectoryPath(BlueapiBaseModel): """ @@ -105,5 +107,5 @@ def create_scan( raise RuntimeError(f"Numtracker error: {json['errors']}") new_collection = NumtrackerScanMutationResponse.model_validate(json["data"]) - logging.debug("New NumtrackerNewScan: %s", new_collection) + LOGGER.debug("New NumtrackerNewScan: %s", new_collection) return new_collection diff --git a/src/blueapi/worker/task_worker.py b/src/blueapi/worker/task_worker.py index 06055cc933..62435d2618 100644 --- a/src/blueapi/worker/task_worker.py +++ b/src/blueapi/worker/task_worker.py @@ -273,7 +273,7 @@ def submit_task(self, task: Task) -> str: request_id = get_baggage("correlation_id") # If request id is not a string, we do not pass it into a TrackableTask if not isinstance(request_id, str): - logging.warning(f"Invalid correlation id detected: {request_id}") + LOGGER.warning(f"Invalid correlation id detected: {request_id}") request_id = None trackable_task = TrackableTask( task_id=task_id,