Better logging names
This commit is contained in:
parent
4bdb160f4d
commit
21d77562b4
2 changed files with 10 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,8 +1,9 @@
|
||||||
|
__pycache__
|
||||||
/bin
|
/bin
|
||||||
/include
|
/include
|
||||||
/lib
|
/lib
|
||||||
/lib64
|
/lib64
|
||||||
/logs
|
/logs
|
||||||
/out
|
/out
|
||||||
|
/Scripts
|
||||||
/share
|
/share
|
||||||
__pycache__
|
|
||||||
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from datetime import date
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
@ -15,14 +16,20 @@ def __init_dirs(dest: str):
|
||||||
if not os.path.exists("./logs"):
|
if not os.path.exists("./logs"):
|
||||||
os.mkdir("./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:
|
def main(source: str, destination: str) -> None:
|
||||||
""""""
|
""""""
|
||||||
__init_dirs(destination)
|
__init_dirs(destination)
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel("DEBUG")
|
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"Watching directory {source}")
|
||||||
logger.info(f"Backing up to {destination}")
|
logger.info(f"Backing up to {destination}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue