有时在制作中,人们可能会遇到一些错误,例如Flask会引发异常。其中一个解决方案是使用$(document).ready(function () {
getNumSlots(settings.minTime, settings.maxTime, settings.timeSlotGap);
for(var i = 1; i<=settings.numSlots; i++){
//I have no idea what I'm doing here
$('#calendar').append("<p>Timeslot:" + i +"</p>");
}
});
var WeekNo = moment().week();
var CurrentDate = getCurrentDate();
var WeekDay = moment().weekday();
var settings = {
startOfWeek:0, //0 = Sunday, 1 = Monday
timeSlotGap: 60,
minTime: "09:00:00",
maxTime: "17:30:00",
numSlots: 0
};
if(settings.startOfWeek == 0){
WeekDay = WeekDay - 1;
}
function getNumSlots(minTime, maxTime, timeSlotGap){
var minTimeSplit = minTime.split(":");
var hourStart = new Date("01/01/1900 " + minTime).getHours();
var hourEnd = new Date("01/01/1900 " + maxTime).getHours();
var minStart = new Date("01/01/1900 " + minTime).getMinutes();
var minEnd = new Date("01/01/1900 " + maxTime).getMinutes();
var diffHour = hourEnd - hourStart;
var diffMins = minEnd - minStart;
var slots = ((diffHour * 60) + diffMins) / timeSlotGap;
settings.numSlots = slots;
}
记录异常。但重现这个问题还不够。
如果我们可以将异常转储到文件中以便以后调试,探索对象,那将是很好的。 python能做到吗?像核心转储?
答案 0 :(得分:0)
如果发生异常,您可以将完整的堆栈跟踪保存到文件中。 您可以为应用程序实例创建一个记录异常的函数。在此示例中,app或sqllachemy包中的所有异常都将记录在“sample.log”文件中。
def log(app):
import logging
from logging.handlers import RotatingFileHandler
from logging import getLogger
logging._defaultFormatter = logging.Formatter(u"%(message)s")
file_handler.setLevel(logging.ERROR)
file_handler = RotatingFileHandler("sample.log", maxBytes=1024*1024*10, backupCount=100)
loggers = [app.logger, getLogger('sqlalchemy')]
for logger in loggers:
logger.addHandler(file_handler)
在创建应用实例后,在应用程序的init脚本中 调用创建的函数
log(app)