def _getCallerLogger():
caller = inspect.currentframe().f_back.f_back
name = "{}-{}".format(caller.f_globals['__name__'], caller.f_code.co_name )
logger = logging.getLogger(name)
return logger
log = lambda msg : _getCallerLogger().debug(msg)
info = lambda msg: _getCallerLogger().info(msg)
warning = lambda msg: _getCallerLogger().warning(msg)
error = lambda msg: _getCallerLogger().error(msg)
critical = lambda msg: _getCallerLogger().critical(msg)
I have the above logging code in my application so I can just call log
from anywhere and it will print the file and where the log method was called from.
Would there be anything wrong with this in the long run?
log = _getCallerLogger().debug
? why dont' you set the logger in a variable instead of creating a new one 5 times? \$\endgroup\$