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

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

Commit Message

Stefan Klug April 11, 2025, 12:36 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>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---

Changes in v2:
- Collected tag
---
 utils/gen-debug-controls.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Paul Elder May 11, 2025, 7:08 p.m. UTC | #1
Quoting Stefan Klug (2025-04-11 14:36:31)
> 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>
> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> 
> ---
> 
> Changes in v2:
> - Collected tag
> ---
>  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
> +    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
>
Isaac Scott May 15, 2025, 1:14 p.m. UTC | #2
Hi Stefan,

Quoting Stefan Klug (2025-04-11 13:36:31)
> 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>
> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 

Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>

> ---
> 
> Changes in v2:
> - Collected tag
> ---
>  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
> +    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