1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2025-02-13 09:44:40 +00:00

FIX: Fix for log_dir error on startup when log_dir is not set in the config.ini - either due to new startup or was set to None

This commit is contained in:
evilhero 2018-05-11 12:34:41 -04:00
parent 58b59d49bf
commit 4314b8b98c
2 changed files with 35 additions and 23 deletions

View file

@ -500,6 +500,17 @@ class Config(object):
self.provider_sequence()
if startup is True:
if self.LOG_DIR is None:
self.LOG_DIR = os.path.join(mylar.DATA_DIR, 'logs')
if not os.path.exists(self.LOG_DIR):
try:
os.makedirs(self.LOG_DIR)
except OSError:
if not mylar.QUIET:
self.LOG_DIR = None
print('Unable to create the log directory. Logging to screen only.')
# Start the logger, silence console logging if we need to
if logger.LOG_LANG.startswith('en'):
logger.initLogger(console=not mylar.QUIET, log_dir=self.LOG_DIR, max_logsize=self.MAX_LOGSIZE, max_logfiles=self.MAX_LOGFILES, loglevel=mylar.LOG_LEVEL)

View file

@ -77,37 +77,38 @@ if not LOG_LANG.startswith('en'):
lg = logging.getLogger('mylar')
lg.setLevel(logging.DEBUG)
self.filename = os.path.join(log_dir, self.filename)
if log_dir is not None:
self.filename = os.path.join(log_dir, self.filename)
#concurrentLogHandler/0.8.7 (to deal with windows locks)
#since this only happens on windows boxes, if it's nix/mac use the default logger.
if mylar.OS_DETECT == 'Windows':
#set the path to the lib here - just to make sure it can detect cloghandler & portalocker.
import sys
sys.path.append(os.path.join(mylar.PROG_DIR, 'lib'))
#concurrentLogHandler/0.8.7 (to deal with windows locks)
#since this only happens on windows boxes, if it's nix/mac use the default logger.
if mylar.OS_DETECT == 'Windows':
#set the path to the lib here - just to make sure it can detect cloghandler & portalocker.
import sys
sys.path.append(os.path.join(mylar.PROG_DIR, 'lib'))
try:
from ConcurrentLogHandler.cloghandler import ConcurrentRotatingFileHandler as RFHandler
mylar.LOGTYPE = 'clog'
except ImportError:
try:
from ConcurrentLogHandler.cloghandler import ConcurrentRotatingFileHandler as RFHandler
mylar.LOGTYPE = 'clog'
except ImportError:
mylar.LOGTYPE = 'log'
from logging.handlers import RotatingFileHandler as RFHandler
else:
mylar.LOGTYPE = 'log'
from logging.handlers import RotatingFileHandler as RFHandler
else:
mylar.LOGTYPE = 'log'
from logging.handlers import RotatingFileHandler as RFHandler
filehandler = RFHandler(
self.filename,
maxBytes=max_logsize,
backupCount=max_logfiles)
filehandler = RFHandler(
self.filename,
maxBytes=max_logsize,
backupCount=max_logfiles)
filehandler.setLevel(logging.DEBUG)
filehandler.setLevel(logging.DEBUG)
fileformatter = logging.Formatter('%(asctime)s - %(levelname)-7s :: %(message)s', '%d-%b-%Y %H:%M:%S')
fileformatter = logging.Formatter('%(asctime)s - %(levelname)-7s :: %(message)s', '%d-%b-%Y %H:%M:%S')
filehandler.setFormatter(fileformatter)
lg.addHandler(filehandler)
self.filehandler = filehandler
filehandler.setFormatter(fileformatter)
lg.addHandler(filehandler)
self.filehandler = filehandler
if loglevel:
consolehandler = logging.StreamHandler()