X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fsfalogging.py;h=006250c3213d5482e5654d2e336bd1ae237d0eda;hb=04ee37a509b179c89d2584458bbe0d69db5b7c9c;hp=0e17ccbaff46ef61e1b5fc3a9dc07d7f315c4732;hpb=952322d76247f8991f3c2688ed7e1f5a22ca4572;p=sfa.git diff --git a/sfa/util/sfalogging.py b/sfa/util/sfalogging.py index 0e17ccba..006250c3 100644 --- a/sfa/util/sfalogging.py +++ b/sfa/util/sfalogging.py @@ -1,12 +1,14 @@ import logging import os +import traceback #SFA access log initialization TMPDIR = os.getenv("TMPDIR", "/tmp") SFA_HTTPD_ACCESS_LOGFILE = TMPDIR + "/" + 'sfa_httpd_access.log' SFA_ACCESS_LOGFILE='/var/log/sfa_access.log' logger=logging.getLogger() -logger.setLevel(logging.INFO) +#logger.setLevel(logging.INFO) +logger.setLevel(logging.DEBUG) try: logfile=logging.FileHandler(SFA_ACCESS_LOGFILE) @@ -15,8 +17,22 @@ except IOError: # owned by root, but httpd is trying to access it. logfile=logging.FileHandler(SFA_HTTPD_ACCESS_LOGFILE) -formatter = logging.Formatter("%(asctime)s - %(message)s") +formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") logfile.setFormatter(formatter) logger.addHandler(logfile) def get_sfa_logger(): return logger + +# logs an exception - use in an except statement +def log_exc(message): + logger.error("%s BEG TRACEBACK"%message+"\n"+traceback.format_exc().strip("\n")) + logger.error("%s END TRACEBACK"%message) + + +# for investigation purposes, can be placed anywhere +def log_stack(message): + to_log="".join(traceback.format_stack()) + logger.debug("%s BEG STACK"%message+"\n"+to_log) + logger.debug("%s END STACK"%message) + +