def printlog(message, logpath=False):
# I think the logging module is great, but this will be used for the time being
# Eventually, we will want to write out multiple output formats: xml,json, etc
if logpath:
# Next iteration of project will include a more secure logger,
# for now, we will just write results to a file directly.
# flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
# mode = stat.S_IRUSR | stat.S_IWUSR
# umask_original = os.umask(0)
# try:
# fdesc = os.open(logpath, flags, mode)
# # except(OSError):
# # print("[-] Log file exists. Remove it, or change log filename")
# # raise SystemExit
# finally:
# os.umask(umask_original)
# with os.fdopen(fdesc, 'w') as fout:
with open(logpath, 'a') as fout:
fout.write("{}\n".format(message))
print("{}".format(message))
评论列表
文章目录