Attempt at fixing up logging

This commit is contained in:
unknown 2021-12-01 18:29:17 +01:00
parent 23e652f17a
commit 2fced8122e
18 changed files with 148 additions and 107 deletions

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
from string import Template from string import Template
import re import re

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
from PyQt5 import QtCore, QtGui from PyQt5 import QtCore, QtGui
from datetime import * from datetime import *

4
irc.py
View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
from PyQt5 import QtCore, QtGui from PyQt5 import QtCore, QtGui
from oyoyo.client import IRCClient from oyoyo.client import IRCClient

View file

@ -2,7 +2,7 @@
keys=root,pchumLogger keys=root,pchumLogger
[handlers] [handlers]
keys=consoleHandler,FileHandler keys=consoleHandler
[formatters] [formatters]
keys=simpleFormatter keys=simpleFormatter
@ -13,7 +13,7 @@ handlers=consoleHandler
[logger_pchumLogger] [logger_pchumLogger]
level=WARNING level=WARNING
handlers=consoleHandler,FileHandler handlers=consoleHandler
qualname=pchumLogger qualname=pchumLogger
propagate=0 propagate=0
@ -23,12 +23,6 @@ level=WARNING
formatter=simpleFormatter formatter=simpleFormatter
args=(sys.stdout,) args=(sys.stdout,)
[handler_FileHandler]
class=FileHandler
level=WARNING
formatter=simpleFormatter
args=('pesterchum.log', 'a')
[formatter_simpleFormatter] [formatter_simpleFormatter]
format=%(asctime)s - %(levelname)s - %(module)s - %(threadName)s - %(message)s format=%(asctime)s - %(levelname)s - %(module)s - %(threadName)s - %(message)s
datefmt= datefmt=

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import os, sys, re, ostools import os, sys, re, ostools
try: try:

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
from string import Template from string import Template
import re import re

View file

@ -16,7 +16,9 @@
# THE SOFTWARE. # THE SOFTWARE.
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import logging import logging

View file

@ -15,7 +15,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import inspect import inspect

View file

@ -18,7 +18,9 @@
""" contains helper functions for common irc commands """ """ contains helper functions for common irc commands """
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import random import random

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import re import re
import random import random

View file

@ -4,6 +4,7 @@ import sys
import os import os
import shutil import shutil
import getopt import getopt
import configparser
try: try:
QString = unicode QString = unicode
except NameError: except NameError:
@ -17,32 +18,18 @@ print("Use -h/--help to see the available options.\nLogging is configured in log
# Help # Help
if ('--help' in sys.argv[1:]) or ('-h' in sys.argv[1:]): if ('--help' in sys.argv[1:]) or ('-h' in sys.argv[1:]):
print("Possible arguments:") print("Possible arguments:")
#help_arguments = " -l, --logging\n Specify level of logging, possible values are:\n" + \ help_arguments = " -l, --logging\n Specify level of logging, possible values are:\n" + \
# " CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.\n" + \ " CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.\n" + \
# " The default value is WARNING.\n" + \ " The default value is WARNING.\n" + \
# " (See https://docs.python.org/3/library/logging.html)\n\n" + \ " (See https://docs.python.org/3/library/logging.html)\n\n" + \
help_arguments = " -s, --server\n Specify server override. (legacy)\n\n" + \ help_arguments = " -s, --server\n Specify server override. (legacy)\n\n" + \
" -p, --port\n Specify port override. (legacy)\n\n" + \ " -p, --port\n Specify port override. (legacy)\n\n" + \
" --advanced\n Enable advanced.\n\n" + \ " --advanced\n Enable advanced.\n\n" + \
" --no-honk\n Disable honking.\n" " --no-honk\n Disable honking.\n"
print(help_arguments) print(help_arguments)
sys.exit() sys.exit()
import logging, logging.config
logging.config.fileConfig('logging.conf')
PchumLog = logging.getLogger('pchumLogger')
#PchumLog = logging.getLogger(__name__)
#Logfile = logging.FileHandler("pesterchum.log") import logging
#fileformat = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#Logfile.setFormatter(fileformat)
#PchumLog.addHandler(Logfile)
#stream = logging.StreamHandler()
#streamformat = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
#stream.setFormatter(streamformat)
#PchumLog.addHandler(stream)
#logging.basicConfig(filename="pesterchum.log")
from datetime import * from datetime import *
import random import random
import re import re
@ -58,17 +45,6 @@ except ImportError:
# Fall back on the old location - just in case # Fall back on the old location - just in case
#PchumLog.warning("Couldn't load attrdict from new loc; falling back") #PchumLog.warning("Couldn't load attrdict from new loc; falling back")
from pnc.dep.attrdict import AttrDict from pnc.dep.attrdict import AttrDict
try:
import console
except ImportError:
_CONSOLE = False
PchumLog.warning("Console file not shipped; skipping.")
except Exception as err:
_CONSOLE = False
# Consider erroring?
PchumLog.error("Failed to load console!", exc_info=err)
else:
_CONSOLE = True
reqmissing = [] reqmissing = []
optmissing = [] optmissing = []
@ -79,7 +55,7 @@ except ImportError as e:
if module.startswith("No module named ") or \ if module.startswith("No module named ") or \
module.startswith("cannot import name "): module.startswith("cannot import name "):
reqmissing.append(module[module.rfind(" ")+1:]) reqmissing.append(module[module.rfind(" ")+1:])
else: PchumLog.critical(e) else: logging.critical(e)
del module del module
# Because pygame intro msg :3c # Because pygame intro msg :3c
@ -94,11 +70,11 @@ except ImportError as e:
pygame = None pygame = None
module = str(e) module = str(e)
if module[:16] == "No module named ": optmissing.append(module[16:]) if module[:16] == "No module named ": optmissing.append(module[16:])
else: PchumLog.critical(e) else: logging.critical(e)
del module del module
if reqmissing: if reqmissing:
PchumLog.critical("ERROR: The following modules are required for Pesterchum to run and are missing on your system:") logging.critical("ERROR: The following modules are required for Pesterchum to run and are missing on your system:")
for m in reqmissing: PchumLog.critical("* "+m) for m in reqmissing: logging.critical("* "+m)
# False flag for some reason. # False flag for some reason.
#exit() #exit()
vnum = QtCore.qVersion() vnum = QtCore.qVersion()
@ -108,8 +84,8 @@ if vnum.find(".", vnum.find(".")+1) != -1:
else: else:
minor = int(vnum[vnum.find(".")+1:]) minor = int(vnum[vnum.find(".")+1:])
if not ((major > 5) or (major == 5 and minor >= 0)): if not ((major > 5) or (major == 5 and minor >= 0)):
PchumLog.critical("ERROR: Pesterchum requires at least Qt version >= 5.0") logging.critical("ERROR: Pesterchum requires at least Qt version >= 5.0")
PchumLog.critical("You currently have version " + vnum + ". Please upgrade Qt.") logging.critical("You currently have version " + vnum + ". Please upgrade Qt.")
exit() exit()
from version import _pcVersion from version import _pcVersion
@ -127,53 +103,96 @@ _datadir = ostools.getDataDir()
# (on Linux, same as using xdg). To stay safe with older versions, copy any # (on Linux, same as using xdg). To stay safe with older versions, copy any
# data (profiles, logs, etc) from old location to new data directory. # data (profiles, logs, etc) from old location to new data directory.
#loglevel = 30# Warning (Default) config = configparser.ConfigParser()
#if ('--logging' in sys.argv[1:]) or ('-l' in sys.argv[1:]) & (False == ('--logging' in sys.argv[1:]) and ('-l' in sys.argv[1:])): # Create logging.conf
# try: if os.path.exists(_datadir + "logging.ini") == False:
# # If both are specified, this does not run. config.read('logging.ini.example')
# if ('-l' in sys.argv[1:]):
# loglevel = sys.argv[sys.argv.index('-l') + 1] # Enable file logging
# if ('--logging' in sys.argv[1:]): config['handlers']['keys'] = 'consoleHandler,FileHandler'
# loglevel = sys.argv[sys.argv.index('--logging') + 1] config['logger_pchumLogger']['handlers'] = 'consoleHandler,FileHandler'
#
# loglevel = loglevel.upper() #(r'C:\Users\X\AppData\Local\pesterchum\pesterchum.log', 'a')
# config['handler_FileHandler'] = {'class': 'FileHandler',
# if loglevel == "CRITICAL": 'level': 'WARNING',
# loglevel = 50 'formatter': 'simpleFormatter',
# print("Logging Level is CRITICAL") 'args': (_datadir + 'pesterchum.log', 'a')}
# elif loglevel == "ERROR":
# print("Logging Level is ERROR") print(config.sections())
# elif loglevel == "WARNING": else:
# loglevel = 30 config.read(_datadir + 'logging.ini')
# print("Logging Level is WARNING")
# elif loglevel == "INFO": loglevel = "30"# Warning (Default)
# loglevel = 20 if ('--logging' in sys.argv[1:]) or ('-l' in sys.argv[1:]) & (False == ('--logging' in sys.argv[1:]) and ('-l' in sys.argv[1:])):
# print("Logging Level is INFO") try:
# elif loglevel == "DEBUG": # If both are specified, this does not run.
# loglevel = 10 if ('-l' in sys.argv[1:]):
# print("Logging Level is DEBUG") loglevel = sys.argv[sys.argv.index('-l') + 1]
# elif loglevel == "NOTSET": if ('--logging' in sys.argv[1:]):
# loglevel = 0 loglevel = sys.argv[sys.argv.index('--logging') + 1]
# print("Logging Level is NOTSET")
# else: loglevel = loglevel.upper().strip()
# raise Exception
# stream.setLevel(loglevel) config.read(_datadir + 'logging.ini')
# Logfile.setLevel(loglevel)
# print("loglevel = " + loglevel)
# # Remove from argv because the rest of the code can't handle it :/
# if ('-l' in sys.argv[1:]): if loglevel == "50" or loglevel == "CRITICAL":
# sys.argv.pop(sys.argv.index('-l') + 1) loglevel = "CRITICAL"
# sys.argv.pop(sys.argv.index('-l')) print("Logging Level is CRITICAL")
# if ('--logging' in sys.argv[1:]): elif loglevel == "40" or loglevel == "ERROR":
# sys.argv.pop(sys.argv.index('--logging') + 1) loglevel = "ERROR"
# sys.argv.pop(sys.argv.index('--logging')) print("Logging Level is ERROR")
# except: elif loglevel == "30" or loglevel == "WARNING":
# print("Invalid syntax.") loglevel = "WARNING"
# stream.setLevel(loglevel) print("Logging Level is WARNING")
# Logfile.setLevel(loglevel) elif loglevel == "20" or loglevel == "INFO":
#else: loglevel = "INFO"
# stream.setLevel(loglevel) print("Logging Level is INFO")
# Logfile.setLevel(loglevel) elif loglevel == "10" or loglevel == "DEBUG":
loglevel = "DEBUG"
print("Logging Level is DEBUG")
elif loglevel == "0" or loglevel == "NOTSET":
loglevel = "NOTSET"
print("Logging Level is NOTSET")
else:
loglevel = "WARNING"
print("Logging Level is WARNING")
config['logger_root']['level'] = loglevel
config['logger_pchumLogger']['level'] = loglevel
config['handler_consoleHandler']['level'] = loglevel
# Remove from argv because the rest of the code can't handle it :/
if ('-l' in sys.argv[1:]):
sys.argv.pop(sys.argv.index('-l') + 1)
sys.argv.pop(sys.argv.index('-l'))
if ('--logging' in sys.argv[1:]):
sys.argv.pop(sys.argv.index('--logging') + 1)
sys.argv.pop(sys.argv.index('--logging'))
except:
logging.exception("Invalid syntax?")
# Update logging.conf
with open(_datadir + "logging.ini", 'w') as configfile:
config.write(configfile)
# Load logging.conf
import logging.config
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
try:
import console
except ImportError:
_CONSOLE = False
logging.warning("Console file not shipped; skipping.")
except Exception as err:
_CONSOLE = False
# Consider erroring?
logging.error("Failed to load console!", exc_info=err)
else:
_CONSOLE = True
if _datadir: if _datadir:
if not os.path.exists(_datadir): if not os.path.exists(_datadir):

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import os import os
from string import Template from string import Template

View file

@ -93,7 +93,7 @@ add_data = ['quirks;quirks',
'CHANGELOG.md;.', 'CHANGELOG.md;.',
'PCskins.png;.', 'PCskins.png;.',
'Pesterchum.png;.', 'Pesterchum.png;.',
'logging.conf;.'] 'logging.ini.example;.']
upx_exclude = ["qwindows.dll", upx_exclude = ["qwindows.dll",
"Qt5Core.dll", "Qt5Core.dll",

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import os, sys, imp, re, ostools import os, sys, imp, re, ostools
from quirks import ScriptQuirks from quirks import ScriptQuirks

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import os, sys, re, ostools import os, sys, re, ostools
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets

View file

@ -31,7 +31,7 @@ includefiles = ["quirks",
"CHANGELOG.md", "CHANGELOG.md",
"PCskins.png", "PCskins.png",
"Pesterchum.png", "Pesterchum.png",
"logging.conf"] "logging.ini.example"]
build_exe_options = { build_exe_options = {
## "includes": ["PyQt5.QtCore", ## "includes": ["PyQt5.QtCore",
## "PyQt5.QtGui", ## "PyQt5.QtGui",

View file

@ -1,5 +1,7 @@
import logging, logging.config import logging, logging.config
logging.config.fileConfig('logging.conf') import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger') PchumLog = logging.getLogger('pchumLogger')
import inspect import inspect
#import threading #import threading