Better logging names
This commit is contained in:
parent
4bdb160f4d
commit
21d77562b4
2 changed files with 10 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ import logging
|
|||
from pathlib import Path
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from datetime import date
|
||||
from threading import Thread
|
||||
|
||||
import os
|
||||
|
|
@ -15,14 +16,20 @@ def __init_dirs(dest: str):
|
|||
if not os.path.exists("./logs"):
|
||||
os.mkdir("./logs")
|
||||
|
||||
def __get_log_version(today: date) -> int:
|
||||
existing = list(filter(lambda x: x.startswith(str(today)), os.listdir("./logs")))
|
||||
return len(existing)+1
|
||||
|
||||
|
||||
def main(source: str, destination: str) -> None:
|
||||
""""""
|
||||
__init_dirs(destination)
|
||||
|
||||
now = datetime.now()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel("DEBUG")
|
||||
logging.basicConfig(filename=f"./logs/{datetime.now()}.log")
|
||||
logging.basicConfig(filename=f"./logs/{now.date()}-{__get_log_version(now.date())}.log")
|
||||
|
||||
logger.info(f"Watching directory {source}")
|
||||
logger.info(f"Backing up to {destination}")
|
||||
|
|
|
|||
Loading…
Reference in a new issue