# Buggy code
def __init__(
    self,
    log_dir: Optional[str] = None,
    level=logbook.DEBUG,
    filter=None,
    bubble=True,
) -> None:
    self.disabled = False
    self._msg_buffer: Optional[List[logbook.LogRecord]] = []
    # if we get 1k messages without a logfile being set, something is wrong
    self._bufmax = 1000
    self._log_path = None
    # we need the base handler class' __init__ to run so handling works
    logbook.Handler.__init__(self, level, filter, bubble)
    if log_dir is not None:
        self.set_path(log_dir)
    self._text_format_string = None


# Traceback (FileExistsError)
2019-10-25 03:10:31,150080 (MainThread): Running with dbt=0.15.0-b2
2019-10-25 03:10:31,478080 (MainThread): running dbt with arguments Namespace(cls=<class 'dbt.task.test.TestTask'>, data=False, debug=True, exclude=None, log_cache_events=False, log_format='default', models=['dim_agency_assert_agency_id'], partial_parse=None, profile=None, profiles_dir='C:\\Users\\dbt_fan\\.dbt', project_dir=None, record_timing_info=None, rpc_method='test', schema=False, single_threaded=False, strict=False, target=None, test_new_parser=False, threads=None, use_cache=True, vars='{}', version_check=True, warn_error=False, which='test', write_json=True)
2019-10-25 03:10:31,480087 (MainThread): Encountered an error:
2019-10-25 03:10:31,480087 (MainThread): [WinError 183] Cannot create a file when that file already exists: 'logs\\dbt.log' -> 'C:\\source\\my_dbt\\logs\\dbt-2019-10-24.log'
2019-10-25 03:10:31,482083 (MainThread): Traceback (most recent call last):
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\main.py", line 80, in main
results, succeeded = handle_and_check(args)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\main.py", line 158, in handle_and_check
task, res = run_from_args(parsed)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\main.py", line 204, in run_from_args
log_manager.set_path(log_path)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\logger.py", line 483, in set_path
self._file_handler.set_path(path)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\logger.py", line 383, in set_path
self._replay_buffered()
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\dbt\logger.py", line 402, in _replay_buffered
super().emit(record)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\logbook\handlers.py", line 980, in emit
self.perform_rollover(new_timestamp)
File "c:\users\dbt_fan\appdata\local\programs\python\python37\lib\site-packages\logbook\handlers.py", line 962, in perform_rollover
os.rename(self._filename, filename)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'logs\\dbt.log' -> 'C:\\source\\my_dbt\\logs\\dbt-2019-10-24.log'

# Fixed code
def __init__(
    self,
    log_dir: Optional[str] = None,
    level=logbook.DEBUG,
    filter=None,
    bubble=True,
    max_size=10 * 1024 * 1024,  # 10 mb
    backup_count=5,
) -> None:
    self.disabled = False
    self._msg_buffer: Optional[List[logbook.LogRecord]] = []
    # if we get 1k messages without a logfile being set, something is wrong
    self._bufmax = 1000
    self._log_path = None
    # we need the base handler class' __init__ to run so handling works
    logbook.Handler.__init__(self, level, filter, bubble)
    if log_dir is not None:
        self.set_path(log_dir)
    self._text_format_string = None
    self._max_size = max_size
    self._backup_count = backup_count