Beispiel #1
0
    def get_handlers(self, log_name):
        logger_dir = LOGGER_CONF["path"]
        logger_fmt = LOGGER_CONF["format"]
        # logger_size = int(LOGGER_CONF["size"])
        logger_level = LOGGER_CONF["level"].upper()

        if not os.path.exists(logger_dir):
            os.makedirs(logger_dir)

        def log_type(record, handler):
            log = logger_fmt.format(
                date = record.time,                              # 日志时间
                level = record.level_name,                       # 日志等级
                filename = os.path.split(record.filename)[-1],   # 文件名
                func_name = record.func_name,                    # 函数名
                lineno = record.lineno,                          # 行号
                msg = record.message,                            # 日志内容
                channel = record.channel,                        # 通道
                pid = self._pid,
                ppid = self._ppid
            )

            return log

        # 日志打印到屏幕
        log_std = ColorizedStderrHandler(bubble=True, level=logger_level)
        log_std.formatter = log_type

        # 日志打印到文件
        log_file = TimedRotatingFileHandler(os.path.join(logger_dir, '{}.log'.format(log_name)), date_format='%Y-%m-%d', rollover_format='{basename}_{timestamp}{ext}', bubble=True, level=logger_level, encoding='utf-8')
        log_file.formatter = log_type

        logbook.set_datetime_format("local")

        return [log_std, log_file]
Beispiel #2
0
def print_handler():
    # 日志路径,在主工程下生成log目录

    Log_Dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'log')
    if not os.path.exists(Log_Dir):
        os.makedirs(Log_Dir)
    # 打印到屏幕句柄
    user_std_handler = ColorizedStderrHandler(bubble=True)
    user_std_handler.formatter = log_formatter
    # 打印到文件句柄
    file_handler = TimedRotatingFileHandler(os.path.join(Log_Dir, "%s.log" % "test_log"), date_format="%Y%m%d", bubble=True)
    file_handler.formatter = log_formatter
    return user_std_handler, file_handler
Beispiel #3
0
def logger(file_name=LogName.DEFAULT):
    # 日志打印到文件
    log_file = TimedRotatingFileHandler(
        os.path.join(LOG_DIR, '%s.log' % file_name),
        date_format='%Y-%m-%d',
        bubble=True,
        rollover_format='{basename}_{timestamp}{ext}',
        encoding='utf-8',
    )
    log_file.formatter = log_type

    logbook.set_datetime_format('local')
    run_log = Logger('script_log')
    run_log.handlers = []
    run_log.handlers.append(log_file)
    return run_log
Beispiel #4
0
def generate_logger():

    # 日志名称
    logger = Logger(PROJECT_NAME_EN, level=LOG_LEVEL)
    logbook.set_datetime_format("local")
    logger.handlers = []
    # 日志打印到文件
    log_file = TimedRotatingFileHandler(os.path.join(
        LOG_DIR, '%s.log' % PROJECT_NAME_EN),
                                        date_format=DAY_FORMAT,
                                        bubble=True,
                                        encoding='utf-8')
    log_file.formatter = log_type
    logger.handlers.append(log_file)
    if DEBUG:
        # 日志打印到屏幕
        log_std = ColorizedStderrHandler(bubble=True)
        log_std.formatter = log_type
        logger.handlers.append(log_std)
    return logger
Beispiel #5
0
def get_logger(logname):
    user_log = logbook.Logger('log')

    logbook.set_datetime_format("local")  # 格式化时间

    # 日志打印到屏幕
    log_std = ColorizedStderrHandler(bubble=True)
    log_std.formatter = log_type

    # 日志打印到文件
    log_file = TimedRotatingFileHandler(os.path.join(full_path,
                                                     '%s.log' % logname),
                                        date_format='%Y-%m-%d',
                                        bubble=True,
                                        encoding='utf-8')  # 日期分割显示文件(带日期的)
    log_file.formatter = log_type

    user_log.handlers = []
    user_log.handlers.append(log_file)
    user_log.handlers.append(log_std)

    return user_log
Beispiel #6
0
    def __init__(self, log_dir=BASE_DIR, log_name='log.log', backup_count=10, log_type=log_type, stdOutFlag=False):
        if not os.path.exists(log_dir):
            os.mkdir(log_dir)
            
        self.log_dir = log_dir
        self.backup_count = backup_count
        
        handler = TimedRotatingFileHandler(filename= os.path.join(self.log_dir, log_name),
                                        date_format='%Y-%m-%d',
                                        backup_count=self.backup_count)
        self.handler = handler
        if log_type is not None:
            handler.formatter = log_type
        handler.push_application()

        if not stdOutFlag:
            return
        
        handler_std = ColorizedStderrHandler(bubble=True)
        if log_type is not None:
            handler_std.formatter = log_type
        handler_std.push_application()
Beispiel #7
0
    )


log_dir = os.getcwd()
print('123')
if os.path.exists(log_dir):
    print('文件存在')
else:
    print('文件不存在')
# print(path)


#日志打印到屏幕
log_led = ColorizedStderrHandler(bubble=True) #获取打印在屏幕上的句柄
log_led.formatter = log_type #log打印的格式设置

# 日志打印到文件
log_file = TimedRotatingFileHandler(os.path.join(log_dir,'%s.log' % 'log'),date_format='%Y-%m-%d',bubble=True,encoding='utf-8')
log_file.formatter = log_type

#脚本日志
run_log = Logger("script_log")
def init_logger():
    logbook.set_datetime_format("local")
    run_log.handlers = []
    run_log.handlers.append(log_file)
    run_log.handlers.append(log_led)

logger = init_logger()

Beispiel #8
0
    return log

std_handler = ColorizedStderrHandler(bubble=True)
std_handler.formatter = log_formatter


# 日志存放路径
LOG_DIR = env.log_dir
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)


# 日志打印到文件
log_file_debug = TimedRotatingFileHandler(os.path.join(LOG_DIR, '{}.log'.format('debug')), date_format='%Y-%m-%d', level=logbook.DEBUG, bubble=True, encoding='utf-8')
log_file_debug.formatter = log_formatter

log_file_info = TimedRotatingFileHandler(os.path.join(LOG_DIR, '{}.log'.format('info')), date_format='%Y-%m-%d', level=logbook.INFO, bubble=True, encoding='utf-8')
log_file_info.formatter = log_formatter

log_file_err = TimedRotatingFileHandler(os.path.join(LOG_DIR, '{}.log'.format('err')), date_format='%Y-%m-%d', level=logbook.WARNING, bubble=True, encoding='utf-8')
log_file_err.formatter = log_formatter

def init_logger(level=logbook.INFO):
    logbook.set_datetime_format("local")

    system_log = Logger("system_log")
    system_log.handlers = []
    system_log.handlers.append(log_file_debug)
    system_log.handlers.append(log_file_info)
    system_log.handlers.append(log_file_err)
Beispiel #9
0
        filename=os.path.split(record.filename)[-1],  # 文件名
        func_name=record.func_name,  # 函数名
        lineno=record.lineno,  # 行号
        msg=record.message  # 日志内容
    )
    return log


LOG_DIR = os.path.join("Log")
logbook.set_datetime_format("local")
#handler = FileHandler('app.log')
handler = TimedRotatingFileHandler(os.path.join(LOG_DIR, '%s.log' % 'log'),
                                   date_format='%Y-%m-%d',
                                   bubble=True,
                                   encoding='utf-8')
handler.formatter = log_type
handler.push_application()
log = Logger('taobao')
'''配置好selenium 链接上Chrome'''
options = webdriver.ChromeOptions()
options.add_argument('--headless')
browser = webdriver.Chrome(
    executable_path=r'C:\Temp\jdk1.8.0\bin\chromedriver.exe',
    chrome_options=options)
wait = WebDriverWait(browser, 10)


class redisDB():
    '''
    waiting集合中是待读取的个人user-token
    pools列表是免费IP代理池
Beispiel #10
0
    )
    return log


std_handler = ColorizedStderrHandler(bubble=True)
std_handler.formatter = handler_log_formatter

LOG_DIR = os.path.join('log')
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

file_handler = TimedRotatingFileHandler(
    os.path.join(LOG_DIR, '%s.log' % 'runtime'),
    date_format='%Y%m%d',
    bubble=True,
    backup_count=31,
    rollover_format='{basename}.{timestamp}{ext}')
file_handler.formatter = handler_log_formatter

logger = Logger()


def init_logger():
    logbook.set_datetime_format("local")
    logger.handlers = []
    logger.handlers.append(std_handler)
    logger.handlers.append(file_handler)


init_logger()
Beispiel #11
0
        func_name=record.func_name,  # 函数名
        lineno=record.lineno,  # 行号
        msg=record.message,  # 日志内容
    )
    return log


# 打印到屏幕句柄
log_pout_handle = ColorizedStderrHandler(bubble=True)
log_pout_handle.formatter = user_handler_log_formatter

# 打印到文件句柄
log_pfile_handle = TimedRotatingFileHandler(os.path.join(
    LOG_DIR, '%s.log' % 'monkey_log'),
                                            bubble=True)
log_pfile_handle.formatter = user_handler_log_formatter

# 用户代码logger日志
user_log = Logger("user_log")


def init_logger():
    logbook.set_datetime_format("local")
    user_log.handlers = []
    user_log.handlers.append(log_pout_handle)
    user_log.handlers.append(log_pfile_handle)


init_logger()

Beispiel #12
0
# 日志存放路径
LOG_DIR = os.path.join('Log')
if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

# 日志打印到屏幕
log_std = ColorizedStderrHandler(bubble=True)
log_std.formatter = __log_type

# 日志打印到文件
log_file = TimedRotatingFileHandler(os.path.join(LOG_DIR, '%s.log' % 'log'),
                                    date_format='%Y-%m-%d',
                                    bubble=True,
                                    encoding='utf-8')
log_file.formatter = __log_type

# 脚本日志
run_log = Logger('script_log')


def init_logger():
    logbook.set_datetime_format("local")
    run_log.handlers = []
    run_log.handlers.append(log_file)
    run_log.handlers.append(log_std)


# 实例化,默认调用
init_logger()
Beispiel #13
0
# 日志路径,在主工程下生成log目录

LOG_DIR = os.path.join('log')

if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

# 打印到文件句柄

user_file_handler = TimedRotatingFileHandler(os.path.join(
    LOG_DIR, '%s.log' % 'test_log'),
                                             date_format='%Y%m%d',
                                             bubble=True)

user_file_handler.formatter = user_handler_log_formatter

# 用户代码logger日志

user_log = Logger("user_log")


def init_logger():
    logbook.set_datetime_format("local")

    user_log.handlers = []

    user_log.handlers.append(user_std_handler)

    user_log.handlers.append(user_file_handler)