improved debugging messages

This commit is contained in:
David
2023-12-04 21:45:52 -08:00
parent f815a2a818
commit edea3f4be1
+58 -13
View File
@@ -1,4 +1,7 @@
import logging
import torch
import numpy as np
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@@ -6,25 +9,51 @@ logger = logging.getLogger(__name__)
CATEGORY="keyframed/debug"
# i could probably use icecream or something like that for this
def _inspect(item, depth=0):
pad="\t"*depth
if depth > 0:
pad +="- "
# NB: Linter says using f-strings in log statements can hinder performance
logger.info(f"{pad}type: {type(item)}")
log_item=True
if hasattr(item, "shape"):
logger.info(f"{pad}item.shape: {item.shape}")
log_item=False
elif hasattr(item, "size"):
logger.info(f"{pad}item.shape: {item.size}")
#logger.info(f"{pad}item.shape: {item.size()}")
log_item=False
# to do: be fancy and change to a match statement
#if isinstance(item, dict):
if hasattr(item, 'keys'):
logger.info(f"{pad}item.keys(): {item.keys()}")
if hasattr(item, 'items'):
for k,v in item.items():
logger.info(f"{pad}key: {k}")
logger.info(f"{pad}value: {_inspect(v, depth=depth+1)}")
log_item=False
if isinstance(item, list):
logger.info(f"{pad}len(item): {len(item)}")
for entry in item:
_inspect(entry, depth=depth+1)
log_item=False
if log_item:
logger.info(f"{pad}item: {item}")
class KfDebug_Passthrough:
CATEGORY=CATEGORY
FUNCTION = 'main'
# RETURN_TYPES = ("FLOAT","INT")
# @classmethod
# def INPUT_TYPES(s):
# return {
# "required": {
# "curve": ("KEYFRAMED_CURVE",{"forceInput": True,}),
# "t": ("INT",{"default":0})
# },
# }
def main(self, item):
logger.info(f"type: {type(item)}")
logger.info(f"item: {item}")
_inspect(item)
return (item,) # pretty sure it's gotta be a tuple?
class KfDebug_Float(KfDebug_Passthrough):
CATEGORY=CATEGORY
FUNCTION = 'main'
@@ -38,9 +67,25 @@ class KfDebug_Float(KfDebug_Passthrough):
},
}
class KfDebug_Cond(KfDebug_Passthrough):
CATEGORY=CATEGORY
FUNCTION = 'main'
RETURN_TYPES = ("CONDITIONING",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"item": ("CONDITIONING",{"forceInput": True,}),
},
}
NODE_CLASS_MAPPINGS = {
#"KfDebug_Passthrough": KfDebug_Passthrough,
"KfDebug_Float": KfDebug_Float,
"KfDebug_Cond": KfDebug_Cond,
}
# A dictionary that contains the friendly/humanly readable titles for the nodes