Added logging to files

logs are located in the logs folder inside deemix config folder
This commit is contained in:
RemixDev 2020-07-01 16:33:47 +02:00
parent e5dd2bb4f0
commit 565b205262
5 changed files with 30 additions and 5 deletions

View File

@ -1,2 +1,3 @@
#!/usr/bin/env python3
# Empty File
__version__ = "1.1.2"

View File

@ -844,7 +844,7 @@ def downloadTrackObj_wrap(dz, track, settings, bitrate, queueItem, interface):
try:
result = downloadTrackObj(dz, track, settings, bitrate, queueItem, interface=interface)
except Exception as e:
traceback.print_exc()
logger.exception(str(e))
result = {'error': {
'message': str(e),
'data': {
@ -872,7 +872,7 @@ def download(dz, queueItem, interface=None):
try:
result = downloadTrackObj(dz, queueItem['single'], settings, bitrate, queueItem, interface=interface)
except Exception as e:
traceback.print_exc()
logger.exception(str(e))
result = {'error': {
'message': str(e),
'data': {

View File

@ -1,10 +1,13 @@
#!/usr/bin/env python3
import json
import os.path as path
from os import makedirs
from os import makedirs, listdir, remove
from deemix import __version__ as deemixVersion
import random
import string
import logging
import datetime
import platform
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('deemix')
@ -41,6 +44,26 @@ def initSettings(localFolder = False, configFolder = None):
settings['downloadLocation'] = path.join(localpaths.getHomeFolder(), 'deemix Music')
saveSettings(settings)
makedirs(settings['downloadLocation'], exist_ok=True)
# logfiles
# logfile name
logspath = path.join(configFolder, 'logs')
now = datetime.datetime.now()
logfile = now.strftime("%Y-%m-%d_%H%M%S")+".log"
makedirs(logspath, exist_ok=True)
# add handler for logfile
fh = logging.FileHandler(path.join(logspath, logfile))
fh.setLevel(logging.DEBUG)
fh.setFormatter(logging.Formatter('%(asctime)s - [%(levelname)s] %(message)s'))
logger.addHandler(fh)
logger.info(f"{platform.platform(True, True)} - Python {platform.python_version()}, deemix {deemixVersion}")
#delete old logfiles
logslist = listdir(logspath)
logslist.sort()
if len(logslist)>5:
for i in range(len(logslist)-5):
remove(path.join(logspath, logslist[i]))
return settings

View File

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup(
name="deemix",
version="1.1.1",
version="1.1.2",
description="A barebone deezer downloader library",
long_description=README,
long_description_content_type="text/markdown",

View File

@ -2,5 +2,6 @@
rm -rd build
rm -rd dist
bump
bump deemix/__init__.py
python3 setup.py sdist bdist_wheel
python3 -m twine upload dist/*