12345678910111213141516171819202122232425262728 |
- def log(message):
- DirLogs = settings.BASE_DIR + "/log"
- if not os.path.exists(DirLogs):
- try:
- os.mkdir(DirLogs)
- except OSError:
- return
- DirLogs = settings.BASE_DIR + "/log/log"
- if not os.path.exists(DirLogs):
- try:
- os.mkdir(DirLogs)
- except OSError:
- return
- date = datetime.now()
- month = "0" if date.month < 10 else ""
- month += str(date.month)
- day = "0" if date.day < 10 else ""
- day += str(date.day)
- StrDate = "%s%s%s" % (str(date.year), month, day)
- file = open(DirLogs + '/message_' + StrDate + '.log', 'a')
- my_file = File(file)
- my_file.write("[%s]: %s\n" % (
- str(datetime.now().strftime("%d-%m-%Y %H:%M:%S")),
- str(message)))
- my_file.closed
- file.closed
|