Created
July 13, 2011 14:43
-
-
Save sbz/1080425 to your computer and use it in GitHub Desktop.
generic logit method in order to log functions calling with arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
import logging | |
logger = logging.getLogger('application') | |
def logit(order, *largs, **kwargs): | |
return True | |
__line__ = int(inspect.stack()[1][2]) | |
__function__ = inspect.stack()[1][3] | |
with_color=False | |
format = "" | |
fmt2 = "" | |
for k in kwargs: | |
if with_color: | |
format += "%s=^[[33m%s^[[0m, " % (k, kwargs[k]) | |
else: | |
format += "%s=%s, " % (k, kwargs[k]) | |
if with_color: | |
format += "^[[0m" | |
if with_color: | |
fmt2="%d - ^[[31m%s^[[0m: %s %s +%d" | |
else: | |
fmt2="%d - %s: %s %s +%d" | |
logger.info( | |
fmt2 % ( | |
order, __function__, format, __file__, __line__ | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage: