<commit_before>#!/usr/bin/python
import logging
from logging.handlers import TimedRotatingFileHandler

logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s')

logger = logging.getLogger(__name__)
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
handler = TimedRotatingFileHandler(filename='/Users/tu/testlog.log', when='D')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.debug('log content')<commit_msg>Update timed_rotate_log_example.py<commit_after># -*- coding: utf-8 -*-
import logging
import sys
from logging.handlers import TimedRotatingFileHandler
FORMATTER = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
LOG_FILE = "my-app.log"


def get_console_handler():
    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.setFormatter(FORMATTER)
    return console_handler


def get_file_handler(file_path=None):
    if not file_path:
       file_path = LOG_FILE
    file_handler = TimedRotatingFileHandler(file_path, when='midnight')
    file_handler.setFormatter(FORMATTER)
    return file_handler


def get_logger(logger_name):
    logger = logging.getLogger(logger_name)
    # better to have too much log than not enough
    logger.setLevel(logging.DEBUG)
    logger.addHandler(get_console_handler())
    logger.addHandler(get_file_handler())
    # it's rarely necessary to propagate the error up to parent
    logger.propagate = False
    return logger


if __name__ == '__main__':
    logger = get_logger('zqxt')
    logger.info('just a test')
    logger.debug('ok')
{'fraction_non_alphanumeric': 0.11695544554455446, 'fraction_numerical': 0.0006188118811881188, 'mean_word_length': 5.416666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3499227', 'n_tokens_mistral': 520, 'n_tokens_neox': 506, 'n_words': 102}