Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better logging #1161

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

better logging #1161

wants to merge 2 commits into from

Conversation

azizb-xlnx
Copy link
Collaborator

@azizb-xlnx azizb-xlnx commented Aug 15, 2024

This is to add a project wide logger.

Features

  1. Use python logging module
  2. Brief console log
  3. More detailed file log
  4. Accessible configuration
  5. Decorators for easy function call logs

Usage

Internal logging

The logger can be used internally in all finn modules.

       from logger import finn_logger, log_func, log_func_perf
       logger = finn_logger.get_logger(__name__)

       def my_function():
           logger.info("Hello, world!")
           logger.warning("This is a warning!")
           logger.error("This is an error!")
           logger.debug("This is a debug message!")
           return 42

Add decorators to functions for more detailed and easy logging

       @log_func(__name__)
       @log_func_perf(__name__)
       def step_tidy_up ():
             # lots of code
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Starting step_tidy_up [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:110]
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Finished step_tidy_up in 0.0363 seconds [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:115]

Control verbosity with argparser

control verbosity any where,

    from finn.util.logger import finn_logger 
    parser.add_argument('-v', '--verbose', action='count', default=0, help="Increase verbosity level (use -v, -vv, or -vvv)")
    args = parser.parse_args()
    
    # Configure logging based on verbosity
    finn_logger.configure_logging(args.verbose)
    logger = finn_logger.get_logger('main')

    logger.info("Applying FINN steps on " + args.onnx)

Console output gets brief prints

[INFO  ] 15-08-2024 17:54:09 - Building dataflow accelerator from onnx/model.onnx
[INFO  ] 15-08-2024 17:54:09 - Running step: step_tidy_up [1/3]
[INFO  ] 15-08-2024 17:54:10 - Running step: step_qonnx_to_finn [2/3]

Log file gets precise prints

[INFO  ] 15-08-2024 18:02:14 - main - Applying FINN steps on onnx/model.onnx [in /group/cdc_ir/members/azizb/workspace/sandbox_finn/finn-flow/sandbox-flow/gen_ip.py:41]
[INFO  ] 15-08-2024 18:02:14 - finn.builder.build_dataflow - Building dataflow accelerator from onnx/model.onnx [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/builder/build_dataflow.py:95]
[INFO  ] 15-08-2024 18:02:14 - finn.builder.build_dataflow - Running step: step_tidy_up [1/3] [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/builder/build_dataflow.py:115]
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Starting step_tidy_up [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:110]
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Finished step_tidy_up in 0.0419 seconds [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:115]
[INFO  ] 15-08-2024 18:02:14 - finn.builder.build_dataflow - Running step: step_qonnx_to_finn [2/3] [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/builder/build_dataflow.py:115]
[INFO  ] 15-08-2024 18:02:14 - finn.builder.build_dataflow - Running step: step_tidy_up [3/3] [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/builder/build_dataflow.py:115]
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Starting step_tidy_up [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:110]
[DEBUG ] 15-08-2024 18:02:14 - finn.builder.build_dataflow_steps - Finished step_tidy_up in 0.0363 seconds [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/util/logger.py:115]
[INFO  ] 15-08-2024 18:02:14 - finn.builder.build_dataflow - Completed successfully [in /group/cdc_ir/members/azizb/workspace/brainwave/finn/src/finn/builder/build_dataflow.py:142]


@azizb-xlnx azizb-xlnx marked this pull request as ready for review August 15, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant