Thursday 15 August 2013

python - Lazy Evaluation of Django QuerySet in log message -


If I have my log level set to INFO, then both queries from the following rows will still be evaluated, even if The data is not printed:

  logger.debug ("calculation is% s"% Widget.objects.count ()) logger.debug ("calculation is% s", Widget. Objects. Count ())   

Is there any way to avoid this?

  class lazy (object): def __init __ (self , Function): self.func = func def __str __ (self):  

return self.config () logger. Debug (lazy: lambda: "count% s"% widget population.) () )

No comments:

Post a Comment