Logger.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:ws-cli 作者: hack4sec 项目源码 文件源码
def ex(self, _exception):
        """ Log func for exceptions """

        # Very ugly hack, will be fixed
        tmp_file_name = "/tmp/{0}{1}.txt".format("wsexc", random.randint(1, 9999))
        fh = open(tmp_file_name, "w")
        traceback.print_stack(file=fh)
        fh.close()
        trace_text = file_get_contents(tmp_file_name)
        os.remove(tmp_file_name)

        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]

        log_str = "Exception {1}:\n{2} ({3}): {4}\n{0}\n{5}{0}\n".format(
            "{0:=^20}".format(""),
            exc_type,
            fname,
            exc_tb.tb_lineno,
            str(_exception),
            trace_text,
        )

        self.log(log_str, _print=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号