[3/9] utils: gen-debug-controls: Improve log output
diff mbox series

Message ID 20250331144352.736700-4-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Wdr preparations
Related show

Commit Message

Stefan Klug March 31, 2025, 2:43 p.m. UTC
Add log statements for found controls and the file written. This makes
it easier to understand what happens under the hood.

While at it, create nice colored log out put using coloredlogs if
available.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 utils/gen-debug-controls.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Kieran Bingham March 31, 2025, 4:36 p.m. UTC | #1
Quoting Stefan Klug (2025-03-31 15:43:42)
> Add log statements for found controls and the file written. This makes
> it easier to understand what happens under the hood.
> 
> While at it, create nice colored log out put using coloredlogs if
> available.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  utils/gen-debug-controls.py | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/gen-debug-controls.py b/utils/gen-debug-controls.py
> index ff22b986475e..a1c69bbd8294 100755
> --- a/utils/gen-debug-controls.py
> +++ b/utils/gen-debug-controls.py
> @@ -17,8 +17,13 @@ import sys
>  from dataclasses import dataclass
>  from pathlib import Path
>  
> -logger = logging.getLogger(__name__)
> -logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
> +fmt = '%(levelname)s: %(message)s'
> +try:
> +    import coloredlogs

I see this is optional, I guess we don't need to document it as
something to install as a developer dependency?

Anyway, as you're currently the main user and developer of this file ...


Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> +    coloredlogs.install(level=logging.INFO, fmt=fmt)
> +except ImportError:
> +    logging.basicConfig(level=logging.INFO, format=fmt)
> +
>  
>  try:
>      import ruamel.yaml as ruyaml
> @@ -27,6 +32,8 @@ except:
>          f'Failed to import ruamel.yaml. Please install the ruamel.yaml package.')
>      sys.exit(1)
>  
> +logger = logging.getLogger(__name__)
> +
>  @dataclass
>  class FoundMatch:
>      file: os.PathLike
> @@ -106,6 +113,7 @@ def main(argv):
>              continue
>  
>          p = m.file.relative_to(root_dir)
> +        logger.info(f"Found control {m.name} in {p}")
>          desc = {'type': m.type,
>                  'direction': 'out',
>                  'description': f'Debug control {m.name} found in {p}'}
> @@ -165,6 +173,9 @@ def main(argv):
>                   "#\n"))
>          yaml.dump(doc, f)
>  
> +    p = ctrl_file.relative_to(Path.cwd(), walk_up=True)
> +    logger.info(f"Sucessfully updated {p}")
> +
>      return 0
>  
>  
> -- 
> 2.43.0
>

Patch
diff mbox series

diff --git a/utils/gen-debug-controls.py b/utils/gen-debug-controls.py
index ff22b986475e..a1c69bbd8294 100755
--- a/utils/gen-debug-controls.py
+++ b/utils/gen-debug-controls.py
@@ -17,8 +17,13 @@  import sys
 from dataclasses import dataclass
 from pathlib import Path
 
-logger = logging.getLogger(__name__)
-logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
+fmt = '%(levelname)s: %(message)s'
+try:
+    import coloredlogs
+    coloredlogs.install(level=logging.INFO, fmt=fmt)
+except ImportError:
+    logging.basicConfig(level=logging.INFO, format=fmt)
+
 
 try:
     import ruamel.yaml as ruyaml
@@ -27,6 +32,8 @@  except:
         f'Failed to import ruamel.yaml. Please install the ruamel.yaml package.')
     sys.exit(1)
 
+logger = logging.getLogger(__name__)
+
 @dataclass
 class FoundMatch:
     file: os.PathLike
@@ -106,6 +113,7 @@  def main(argv):
             continue
 
         p = m.file.relative_to(root_dir)
+        logger.info(f"Found control {m.name} in {p}")
         desc = {'type': m.type,
                 'direction': 'out',
                 'description': f'Debug control {m.name} found in {p}'}
@@ -165,6 +173,9 @@  def main(argv):
                  "#\n"))
         yaml.dump(doc, f)
 
+    p = ctrl_file.relative_to(Path.cwd(), walk_up=True)
+    logger.info(f"Sucessfully updated {p}")
+
     return 0