cal-adapt / climakitae

A Python toolkit for retrieving, visualizing, and performing scientific analyses with data from the Cal-Adapt Analytics Engine.
https://climakitae.readthedocs.io
BSD 3-Clause "New" or "Revised" License
21 stars 2 forks source link

Creating Library Logger #341

Closed claalmve closed 7 months ago

claalmve commented 7 months ago

Description of PR

Creating a comprehensive logger for developers to view what is going on in the AE library. This PR allows developers to wrap functions within modules with a log function, which prints the runtime of the function and all the sub-functions of the function that exist within the same module. It additionally will log any other sub-modules reference within the current module (i.e. if you try to log DataInterface, it will also log functions within the DataParameters class).

Summary of changes and related issue Addition of a library-facing logger in climakitae.util.logging to increase visibility of function execution and runtimes in the codebase.

Relevant motivation and context This has been developed because it increases the visibility of what functions run at execution (good for tracking logic of the codebase, esp. useful for new developers), and demonstrates the run-time of all sub-functions being run within that module.

Example of its usage is below:

image

(similar to showing the call stack of a function, but also shows the runtimes).

Type of change

How Has This Been Tested?

# If you're interested in what's going on in the back-end for a specific module, you can `enable_lib_logging` and `disable_lib_logging` as you'd like!
from climakitae.explore import agnostic
from climakitae.util.logging import enable_lib_logging, disable_lib_logging
enable_app_logging(agnostic)
disable_app_logging(agnostic)

Checklist:

Tianchi-Liu commented 7 months ago

Since this is only for developers for now, please consider using hidden functions, and even moving the code to a separate place.

The description and intended use of the tool would be more helpful if they are documented in a place the developers can access more easily. Limitations would be helpful to note as well.

claalmve commented 6 months ago

Logger for function execution visibility