mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -07:00
Uniform logger
This commit is contained in:
parent
7d3711bf5a
commit
258ec197d7
1 changed files with 22 additions and 22 deletions
|
@ -103,7 +103,7 @@ def initialize(config_file):
|
||||||
|
|
||||||
if CONFIG.HTTP_PORT < 21 or CONFIG.HTTP_PORT > 65535:
|
if CONFIG.HTTP_PORT < 21 or CONFIG.HTTP_PORT > 65535:
|
||||||
plexpy.logger.warn(
|
plexpy.logger.warn(
|
||||||
'HTTP_PORT out of bounds: 21 < %s < 65535', CONFIG.HTTP_PORT)
|
u"HTTP_PORT out of bounds: 21 < %s < 65535", CONFIG.HTTP_PORT)
|
||||||
CONFIG.HTTP_PORT = 8181
|
CONFIG.HTTP_PORT = 8181
|
||||||
|
|
||||||
if not CONFIG.HTTPS_CERT:
|
if not CONFIG.HTTPS_CERT:
|
||||||
|
@ -134,7 +134,7 @@ def initialize(config_file):
|
||||||
try:
|
try:
|
||||||
os.makedirs(CONFIG.BACKUP_DIR)
|
os.makedirs(CONFIG.BACKUP_DIR)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error("Could not create backup dir '%s': %s" % (CONFIG.BACKUP_DIR, e))
|
logger.error(u"Could not create backup dir '%s': %s" % (CONFIG.BACKUP_DIR, e))
|
||||||
|
|
||||||
if not CONFIG.CACHE_DIR:
|
if not CONFIG.CACHE_DIR:
|
||||||
CONFIG.CACHE_DIR = os.path.join(DATA_DIR, 'cache')
|
CONFIG.CACHE_DIR = os.path.join(DATA_DIR, 'cache')
|
||||||
|
@ -142,10 +142,10 @@ def initialize(config_file):
|
||||||
try:
|
try:
|
||||||
os.makedirs(CONFIG.CACHE_DIR)
|
os.makedirs(CONFIG.CACHE_DIR)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error("Could not create cache dir '%s': %s" % (CONFIG.CACHE_DIR, e))
|
logger.error(u"Could not create cache dir '%s': %s" % (CONFIG.CACHE_DIR, e))
|
||||||
|
|
||||||
# Initialize the database
|
# Initialize the database
|
||||||
logger.info('Checking to see if the database has all tables....')
|
logger.info(u"Checking if the database upgrades are required...")
|
||||||
try:
|
try:
|
||||||
dbcheck()
|
dbcheck()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -171,7 +171,7 @@ def initialize(config_file):
|
||||||
with open(version_lock_file, "w") as fp:
|
with open(version_lock_file, "w") as fp:
|
||||||
fp.write(CURRENT_VERSION)
|
fp.write(CURRENT_VERSION)
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
logger.error("Unable to write current version to file '%s': %s" %
|
logger.error(u"Unable to write current version to file '%s': %s" %
|
||||||
(version_lock_file, e))
|
(version_lock_file, e))
|
||||||
|
|
||||||
# Check for new versions
|
# Check for new versions
|
||||||
|
@ -179,7 +179,7 @@ def initialize(config_file):
|
||||||
try:
|
try:
|
||||||
LATEST_VERSION = versioncheck.checkGithub()
|
LATEST_VERSION = versioncheck.checkGithub()
|
||||||
except:
|
except:
|
||||||
logger.exception("Unhandled exception")
|
logger.exception(u"Unhandled exception")
|
||||||
LATEST_VERSION = CURRENT_VERSION
|
LATEST_VERSION = CURRENT_VERSION
|
||||||
else:
|
else:
|
||||||
LATEST_VERSION = CURRENT_VERSION
|
LATEST_VERSION = CURRENT_VERSION
|
||||||
|
@ -207,8 +207,8 @@ def initialize(config_file):
|
||||||
def daemonize():
|
def daemonize():
|
||||||
if threading.activeCount() != 1:
|
if threading.activeCount() != 1:
|
||||||
logger.warn(
|
logger.warn(
|
||||||
'There are %r active threads. Daemonizing may cause'
|
u"There are %r active threads. Daemonizing may cause"
|
||||||
' strange behavior.',
|
" strange behavior.",
|
||||||
threading.enumerate())
|
threading.enumerate())
|
||||||
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
@ -248,10 +248,10 @@ def daemonize():
|
||||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||||
|
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
logger.info('Daemonized to PID: %d', pid)
|
logger.info(u"Daemonized to PID: %d", pid)
|
||||||
|
|
||||||
if CREATEPID:
|
if CREATEPID:
|
||||||
logger.info("Writing PID %d to %s", pid, PIDFILE)
|
logger.info(u"Writing PID %d to %s", pid, PIDFILE)
|
||||||
with file(PIDFILE, 'w') as fp:
|
with file(PIDFILE, 'w') as fp:
|
||||||
fp.write("%s\n" % pid)
|
fp.write("%s\n" % pid)
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ def launch_browser(host, port, root):
|
||||||
try:
|
try:
|
||||||
webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root))
|
webbrowser.open('%s://%s:%i%s' % (protocol, host, port, root))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Could not launch browser: %s' % e)
|
logger.error(u"Could not launch browser: %s" % e)
|
||||||
|
|
||||||
|
|
||||||
def initialize_scheduler():
|
def initialize_scheduler():
|
||||||
|
@ -351,15 +351,15 @@ def schedule_job(function, name, hours=0, minutes=0, seconds=0, args=None):
|
||||||
if job:
|
if job:
|
||||||
if hours == 0 and minutes == 0 and seconds == 0:
|
if hours == 0 and minutes == 0 and seconds == 0:
|
||||||
SCHED.remove_job(name)
|
SCHED.remove_job(name)
|
||||||
logger.info("Removed background task: %s", name)
|
logger.info(u"Removed background task: %s", name)
|
||||||
elif job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes):
|
elif job.trigger.interval != datetime.timedelta(hours=hours, minutes=minutes):
|
||||||
SCHED.reschedule_job(name, trigger=IntervalTrigger(
|
SCHED.reschedule_job(name, trigger=IntervalTrigger(
|
||||||
hours=hours, minutes=minutes, seconds=seconds), args=args)
|
hours=hours, minutes=minutes, seconds=seconds), args=args)
|
||||||
logger.info("Re-scheduled background task: %s", name)
|
logger.info(u"Re-scheduled background task: %s", name)
|
||||||
elif hours > 0 or minutes > 0 or seconds > 0:
|
elif hours > 0 or minutes > 0 or seconds > 0:
|
||||||
SCHED.add_job(function, id=name, trigger=IntervalTrigger(
|
SCHED.add_job(function, id=name, trigger=IntervalTrigger(
|
||||||
hours=hours, minutes=minutes, seconds=seconds), args=args)
|
hours=hours, minutes=minutes, seconds=seconds), args=args)
|
||||||
logger.info("Scheduled background task: %s", name)
|
logger.info(u"Scheduled background task: %s", name)
|
||||||
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
@ -372,7 +372,7 @@ def start():
|
||||||
|
|
||||||
def sig_handler(signum=None, frame=None):
|
def sig_handler(signum=None, frame=None):
|
||||||
if signum is not None:
|
if signum is not None:
|
||||||
logger.info("Signal %i caught, saving and exiting...", signum)
|
logger.info(u"Signal %i caught, saving and exiting...", signum)
|
||||||
shutdown()
|
shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
@ -955,7 +955,7 @@ def dbcheck():
|
||||||
# Add "Local" user to database as default unauthenticated user.
|
# Add "Local" user to database as default unauthenticated user.
|
||||||
result = c_db.execute('SELECT id FROM users WHERE username = "Local"')
|
result = c_db.execute('SELECT id FROM users WHERE username = "Local"')
|
||||||
if not result.fetchone():
|
if not result.fetchone():
|
||||||
logger.debug(u'User "Local" does not exist. Adding user.')
|
logger.debug(u"User 'Local' does not exist. Adding user.")
|
||||||
c_db.execute('INSERT INTO users (user_id, username) VALUES (0, "Local")')
|
c_db.execute('INSERT INTO users (user_id, username) VALUES (0, "Local")')
|
||||||
|
|
||||||
conn_db.commit()
|
conn_db.commit()
|
||||||
|
@ -969,27 +969,27 @@ def shutdown(restart=False, update=False):
|
||||||
CONFIG.write()
|
CONFIG.write()
|
||||||
|
|
||||||
if not restart and not update:
|
if not restart and not update:
|
||||||
logger.info('PlexPy is shutting down...')
|
logger.info(u"PlexPy is shutting down...")
|
||||||
|
|
||||||
if update:
|
if update:
|
||||||
logger.info('PlexPy is updating...')
|
logger.info(u"PlexPy is updating...")
|
||||||
try:
|
try:
|
||||||
versioncheck.update()
|
versioncheck.update()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn('PlexPy failed to update: %s. Restarting.' % e)
|
logger.warn(u"PlexPy failed to update: %s. Restarting." % e)
|
||||||
|
|
||||||
if CREATEPID:
|
if CREATEPID:
|
||||||
logger.info('Removing pidfile %s', PIDFILE)
|
logger.info(u"Removing pidfile %s", PIDFILE)
|
||||||
os.remove(PIDFILE)
|
os.remove(PIDFILE)
|
||||||
|
|
||||||
if restart:
|
if restart:
|
||||||
logger.info('PlexPy is restarting...')
|
logger.info(u"PlexPy is restarting...")
|
||||||
exe = sys.executable
|
exe = sys.executable
|
||||||
args = [exe, FULL_PATH]
|
args = [exe, FULL_PATH]
|
||||||
args += ARGS
|
args += ARGS
|
||||||
if '--nolaunch' not in args:
|
if '--nolaunch' not in args:
|
||||||
args += ['--nolaunch']
|
args += ['--nolaunch']
|
||||||
logger.info('Restarting PlexPy with %s', args)
|
logger.info(u"Restarting PlexPy with %s", args)
|
||||||
|
|
||||||
# os.execv fails with spaced names on Windows
|
# os.execv fails with spaced names on Windows
|
||||||
# https://bugs.python.org/issue19066
|
# https://bugs.python.org/issue19066
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue