# Path: py12306/log/base.py
# class BaseLog:
#     logs = []
#     thread_logs = {}
#     quick_log = []
# 
#     @classmethod
#     def add_log(cls, content=''):
#         self = cls()
#         # print('添加 Log 主进程{} 进程ID{}'.format(is_main_thread(), current_thread_id()))
#         if is_main_thread():
#             self.logs.append(content)
#         else:
#             tmp_log = self.thread_logs.get(current_thread_id(), [])
#             tmp_log.append(content)
#             self.thread_logs[current_thread_id()] = tmp_log
#         return self
# 
#     @classmethod
#     def flush(cls, sep='\n', end='\n', file=None, exit=False, publish=True):
#         from py12306.cluster.cluster import Cluster
#         self = cls()
#         logs = self.get_logs()
#         # 输出到文件
#         if file == None and Config().OUT_PUT_LOG_TO_FILE_ENABLED and not Const.IS_TEST:  # TODO 文件无法写入友好提示
#             file = open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'a', encoding='utf-8')
#         if not file: file = None
#         # 输出日志到各个节点
#         if publish and self.quick_log and Config().is_cluster_enabled() and Cluster().is_ready:  #
#             f = io.StringIO()
#             with redirect_stdout(f):
#                 print(*logs, sep=sep, end='' if end == '\n' else end)
#             out = f.getvalue()
#             Cluster().publish_log_message(out)
#         else:
#             print(*logs, sep=sep, end=end, file=file)
#         self.empty_logs(logs)
#         if exit: sys.exit()
# 
#     def get_logs(self):
#         if self.quick_log:
#             logs = self.quick_log
#         else:
#             if is_main_thread():
#                 logs = self.logs
#             else:
#                 logs = self.thread_logs.get(current_thread_id())
#         return logs
# 
#     def empty_logs(self, logs=None):
#         if self.quick_log:
#             self.quick_log = []
#         else:
#             if is_main_thread():
#                 self.logs = []
#             else:
#                 if logs and self.thread_logs.get(current_thread_id()): del self.thread_logs[current_thread_id()]
# 
#     @classmethod
#     def add_quick_log(cls, content=''):
#         self = cls()
#         self.quick_log.append(content)
#         return self
# 
#     def notification(self, title, content=''):
#         # if sys.platform == 'darwin': # 不太友好 先关闭，之前没考虑到 mac 下会请求权限
#         #     os.system( 'osascript -e \'tell app "System Events" to display notification "{content}" with title "{title}"\''.format(
#         #             title=title, content=content))
#         pass


from py12306.log.base import BaseLog
from py12306.config import *
from py12306.helpers.func import *
            from py12306.cluster.cluster import Cluster
            self.add_quick_log('邮件通知: {}'.format(get_true_false_text(Config().EMAIL_ENABLED, enable, disable)))
        if Config().DINGTALK_ENABLED:
            self.add_quick_log('钉钉通知: {}'.format(get_true_false_text(Config().DINGTALK_ENABLED, enable, disable)))
        if Config().TELEGRAM_ENABLED:
            self.add_quick_log('Telegram通知: {}'.format(get_true_false_text(Config().TELEGRAM_ENABLED, enable, disable)))
        if Config().SERVERCHAN_ENABLED:
            self.add_quick_log(
                'ServerChan通知: {}'.format(get_true_false_text(Config().SERVERCHAN_ENABLED, enable, disable)))
        if Config().BARK_ENABLED:
            self.add_quick_log('Bark通知: {}'.format(get_true_false_text(Config().BARK_ENABLED, enable, disable)))
        if Config().PUSHBEAR_ENABLED:
            self.add_quick_log(
                'PushBear通知: {}'.format(get_true_false_text(Config().PUSHBEAR_ENABLED, enable, disable)))
        self.add_quick_log().flush(sep='\t\t')
        self.add_quick_log('查询间隔: {} 秒'.format(Config().QUERY_INTERVAL))
        self.add_quick_log('用户心跳检测间隔: {} 秒'.format(Config().USER_HEARTBEAT_INTERVAL))
        self.add_quick_log('WEB 管理页面: {}'.format(get_true_false_text(Config().WEB_ENABLE, enable, disable)))
        if Config().is_cluster_enabled():
            self.add_quick_log('分布式查询: {}'.format(get_true_false_text(Config().is_cluster_enabled(), enable, enable)))
            self.add_quick_log('节点名称: {}'.format(Cluster().node_name))
            self.add_quick_log('节点是否主节点: {}'.format(get_true_false_text(Config().is_master(), '是', '否')))
            self.add_quick_log(
                '子节点提升为主节点: {}'.format(get_true_false_text(Config().NODE_SLAVE_CAN_BE_MASTER, enable, disable)))
        self.add_quick_log()
        self.flush()
        return self

    @classmethod
    def print_test_complete(cls):
        self = cls()

# Path: py12306/log/base.py
# class BaseLog:
#     logs = []
#     thread_logs = {}
#     quick_log = []
# 
#     @classmethod
#     def add_log(cls, content=''):
#         self = cls()
#         # print('添加 Log 主进程{} 进程ID{}'.format(is_main_thread(), current_thread_id()))
#         if is_main_thread():
#             self.logs.append(content)
#         else:
#             tmp_log = self.thread_logs.get(current_thread_id(), [])
#             tmp_log.append(content)
#             self.thread_logs[current_thread_id()] = tmp_log
#         return self
# 
#     @classmethod
#     def flush(cls, sep='\n', end='\n', file=None, exit=False, publish=True):
#         from py12306.cluster.cluster import Cluster
#         self = cls()
#         logs = self.get_logs()
#         # 输出到文件
#         if file == None and Config().OUT_PUT_LOG_TO_FILE_ENABLED and not Const.IS_TEST:  # TODO 文件无法写入友好提示
#             file = open(Config().OUT_PUT_LOG_TO_FILE_PATH, 'a', encoding='utf-8')
#         if not file: file = None
#         # 输出日志到各个节点
#         if publish and self.quick_log and Config().is_cluster_enabled() and Cluster().is_ready:  #
#             f = io.StringIO()
#             with redirect_stdout(f):
#                 print(*logs, sep=sep, end='' if end == '\n' else end)
#             out = f.getvalue()
#             Cluster().publish_log_message(out)
#         else:
#             print(*logs, sep=sep, end=end, file=file)
#         self.empty_logs(logs)
#         if exit: sys.exit()
# 
#     def get_logs(self):
#         if self.quick_log:
#             logs = self.quick_log
#         else:
#             if is_main_thread():
#                 logs = self.logs
#             else:
#                 logs = self.thread_logs.get(current_thread_id())
#         return logs
# 
#     def empty_logs(self, logs=None):
#         if self.quick_log:
#             self.quick_log = []
#         else:
#             if is_main_thread():
#                 self.logs = []
#             else:
#                 if logs and self.thread_logs.get(current_thread_id()): del self.thread_logs[current_thread_id()]
# 
#     @classmethod
#     def add_quick_log(cls, content=''):
#         self = cls()
#         self.quick_log.append(content)
#         return self
# 
#     def notification(self, title, content=''):
#         # if sys.platform == 'darwin': # 不太友好 先关闭，之前没考虑到 mac 下会请求权限
#         #     os.system( 'osascript -e \'tell app "System Events" to display notification "{content}" with title "{title}"\''.format(
#         #             title=title, content=content))
#         pass


# Path: py12306/log/common_log.py
from py12306.log.base import BaseLog
from py12306.config import *
from py12306.helpers.func import *
            from py12306.cluster.cluster import Cluster

            self.add_quick_log('邮件通知: {}'.format(get_true_false_text(Config().EMAIL_ENABLED, enable, disable)))
        if Config().DINGTALK_ENABLED:
            self.add_quick_log('钉钉通知: {}'.format(get_true_false_text(Config().DINGTALK_ENABLED, enable, disable)))
        if Config().TELEGRAM_ENABLED:
            self.add_quick_log('Telegram通知: {}'.format(get_true_false_text(Config().TELEGRAM_ENABLED, enable, disable)))
        if Config().SERVERCHAN_ENABLED:
            self.add_quick_log(
                'ServerChan通知: {}'.format(get_true_false_text(Config().SERVERCHAN_ENABLED, enable, disable)))
        if Config().BARK_ENABLED:
            self.add_quick_log('Bark通知: {}'.format(get_true_false_text(Config().BARK_ENABLED, enable, disable)))
        if Config().PUSHBEAR_ENABLED:
            self.add_quick_log(
                'PushBear通知: {}'.format(get_true_false_text(Config().PUSHBEAR_ENABLED, enable, disable)))
        self.add_quick_log().flush(sep='\t\t')
        self.add_quick_log('查询间隔: {} 秒'.format(Config().QUERY_INTERVAL))
        self.add_quick_log('用户心跳检测间隔: {} 秒'.format(Config().USER_HEARTBEAT_INTERVAL))
        self.add_quick_log('WEB 管理页面: {}'.format(get_true_false_text(Config().WEB_ENABLE, enable, disable)))
        if Config().is_cluster_enabled():
            self.add_quick_log('分布式查询: {}'.format(get_true_false_text(Config().is_cluster_enabled(), enable, enable)))
            self.add_quick_log('节点名称: {}'.format(Cluster().node_name))
            self.add_quick_log('节点是否主节点: {}'.format(get_true_false_text(Config().is_master(), '是', '否')))
            self.add_quick_log(
                '子节点提升为主节点: {}'.format(get_true_false_text(Config().NODE_SLAVE_CAN_BE_MASTER, enable, disable)))
        self.add_quick_log()
        self.flush()
        return self

    @classmethod
    def print_test_complete(cls):
        self = cls()

        self.add_quick_log('# 测试完成，请检查输出是否正确 #')