From e99e151fc2a8f1255e844b5ec78b02a20b6e05c3 Mon Sep 17 00:00:00 2001 From: Ricky Ng-Adam Date: Wed, 28 Aug 2024 10:22:37 -0400 Subject: [PATCH] Fixes #3202: new suppress banner and replace print by logging statements Signed-off-by: Ricky Ng-Adam --- .../anoncreds/default/did_indy/registry.py | 2 +- .../anoncreds/default/did_web/registry.py | 5 ++- .../anoncreds/default/legacy_indy/registry.py | 2 +- acapy_agent/config/argparse.py | 8 +++++ acapy_agent/core/conductor.py | 35 ++++++++++--------- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/acapy_agent/anoncreds/default/did_indy/registry.py b/acapy_agent/anoncreds/default/did_indy/registry.py index 567d90ccce..5bef819f82 100644 --- a/acapy_agent/anoncreds/default/did_indy/registry.py +++ b/acapy_agent/anoncreds/default/did_indy/registry.py @@ -41,7 +41,7 @@ def supported_identifiers_regex(self) -> Pattern: async def setup(self, context: InjectionContext): """Setup.""" - print("Successfully registered DIDIndyRegistry") + LOGGER.info("Successfully registered DIDIndyRegistry") async def get_schema(self, profile: Profile, schema_id: str) -> GetSchemaResult: """Get a schema from the registry.""" diff --git a/acapy_agent/anoncreds/default/did_web/registry.py b/acapy_agent/anoncreds/default/did_web/registry.py index 63382f3606..0585e2b924 100644 --- a/acapy_agent/anoncreds/default/did_web/registry.py +++ b/acapy_agent/anoncreds/default/did_web/registry.py @@ -1,5 +1,6 @@ """DID Web Registry.""" +import logging import re from typing import Optional, Pattern, Sequence @@ -17,6 +18,8 @@ ) from ...models.anoncreds_schema import AnonCredsSchema, GetSchemaResult, SchemaResult +LOGGER = logging.getLogger(__name__) + class DIDWebRegistry(BaseAnonCredsResolver, BaseAnonCredsRegistrar): """DIDWebRegistry.""" @@ -40,7 +43,7 @@ def supported_identifiers_regex(self) -> Pattern: async def setup(self, context: InjectionContext): """Setup.""" - print("Successfully registered DIDWebRegistry") + LOGGER.info("Successfully registered DIDWebRegistry") async def get_schema(self, profile, schema_id: str) -> GetSchemaResult: """Get a schema from the registry.""" diff --git a/acapy_agent/anoncreds/default/legacy_indy/registry.py b/acapy_agent/anoncreds/default/legacy_indy/registry.py index e173bbde32..892a9d17fe 100644 --- a/acapy_agent/anoncreds/default/legacy_indy/registry.py +++ b/acapy_agent/anoncreds/default/legacy_indy/registry.py @@ -144,7 +144,7 @@ def supported_identifiers_regex(self) -> Pattern: async def setup(self, context: InjectionContext): """Setup.""" - print("Successfully registered LegacyIndyRegistry") + LOGGER.info("Successfully registered LegacyIndyRegistry") @staticmethod def make_schema_id(schema: AnonCredsSchema) -> str: diff --git a/acapy_agent/config/argparse.py b/acapy_agent/config/argparse.py index ec0d3d95e1..0d231f2307 100644 --- a/acapy_agent/config/argparse.py +++ b/acapy_agent/config/argparse.py @@ -1028,6 +1028,13 @@ def add_arguments(self, parser: ArgumentParser): "('debug', 'info', 'warning', 'error', 'critical')" ), ) + parser.add_argument( + "--no-banner", + action="store_true", + env_var="ACAPY_NO_BANNER", + default=False, + help=("Suppress banner in logs"), + ) def get_settings(self, args: Namespace) -> dict: """Extract logging settings.""" @@ -1038,6 +1045,7 @@ def get_settings(self, args: Namespace) -> dict: settings["log.file"] = args.log_file if args.log_level: settings["log.level"] = args.log_level + settings["log.banner"] = not args.no_banner return settings diff --git a/acapy_agent/core/conductor.py b/acapy_agent/core/conductor.py index d9db66ad7a..b27b0973de 100644 --- a/acapy_agent/core/conductor.py +++ b/acapy_agent/core/conductor.py @@ -318,24 +318,25 @@ async def start(self) -> None: # Get agent label default_label = context.settings.get("default_label") - if context.settings.get("transport.disabled"): - LoggingConfigurator.print_banner( - default_label, - None, - None, - self.setup_public_did and self.setup_public_did.did, - self.admin_server, - ) - else: - LoggingConfigurator.print_banner( - default_label, - self.inbound_transport_manager.registered_transports, - self.outbound_transport_manager.registered_transports, - self.setup_public_did and self.setup_public_did.did, - self.admin_server, - ) + if context.settings.get("log.banner", True): + if context.settings.get("transport.disabled"): + LoggingConfigurator.print_banner( + default_label, + None, + None, + self.setup_public_did and self.setup_public_did.did, + self.admin_server, + ) + else: + LoggingConfigurator.print_banner( + default_label, + self.inbound_transport_manager.registered_transports, + self.outbound_transport_manager.registered_transports, + self.setup_public_did and self.setup_public_did.did, + self.admin_server, + ) - LoggingConfigurator.print_notices(context.settings) + LoggingConfigurator.print_notices(context.settings) # record ACA-Py version in Wallet, if needed from_version_storage = None