Fix the -l, --logfile option
This commit is contained in:
parent
f990fd1a9a
commit
f16ff06083
|
@ -27,12 +27,32 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Setup the logger
|
levels = {
|
||||||
logging.basicConfig(
|
"info": logging.INFO,
|
||||||
level=logging.ERROR,
|
"warning": logging.WARNING,
|
||||||
format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s",
|
"error": logging.ERROR,
|
||||||
datefmt="%H:%M:%S"
|
"none": logging.CRITICAL,
|
||||||
)
|
"debug": logging.DEBUG
|
||||||
|
}
|
||||||
|
def setupLogger(level="error", filename=None):
|
||||||
|
"""
|
||||||
|
Sets up the basic logger and if `:param:filename` is set, then it will log
|
||||||
|
to that file instead of stdout.
|
||||||
|
|
||||||
|
:param level: str, the level to log
|
||||||
|
:param filename: str, the file to log to
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not level:
|
||||||
|
level = "error"
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=levels[level],
|
||||||
|
format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s",
|
||||||
|
datefmt="%H:%M:%S",
|
||||||
|
filename=filename,
|
||||||
|
filemode="w"
|
||||||
|
)
|
||||||
|
|
||||||
def setLoggerLevel(level):
|
def setLoggerLevel(level):
|
||||||
"""
|
"""
|
||||||
|
@ -41,14 +61,6 @@ def setLoggerLevel(level):
|
||||||
:param level: str, a string representing the desired level
|
:param level: str, a string representing the desired level
|
||||||
|
|
||||||
"""
|
"""
|
||||||
levels = {
|
|
||||||
"info": logging.INFO,
|
|
||||||
"warning": logging.WARNING,
|
|
||||||
"error": logging.ERROR,
|
|
||||||
"none": logging.CRITICAL,
|
|
||||||
"debug": logging.DEBUG
|
|
||||||
}
|
|
||||||
|
|
||||||
if level not in levels:
|
if level not in levels:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import os.path
|
||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import deluge.log
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
|
|
||||||
|
@ -91,28 +92,24 @@ def start_ui():
|
||||||
|
|
||||||
# Always log to a file in Windows
|
# Always log to a file in Windows
|
||||||
if deluge.common.windows_check() and not options.logfile:
|
if deluge.common.windows_check() and not options.logfile:
|
||||||
options.logfile = "deluge.log"
|
|
||||||
|
|
||||||
if options.logfile:
|
|
||||||
if options.config:
|
if options.config:
|
||||||
logfile = os.path.join(options.config, options.logfile)
|
options.logfile = os.path.join(options.config, "deluge.log")
|
||||||
else:
|
else:
|
||||||
config_dir = deluge.common.get_default_config_dir()
|
config_dir = deluge.common.get_default_config_dir()
|
||||||
logfile = os.path.join(config_dir, options.logfile)
|
options.logfile = os.path.join(config_dir, "deluge.log")
|
||||||
sys.stdout = open(logfile, "wb")
|
|
||||||
sys.stderr = sys.stdout
|
|
||||||
sys.stdin = None
|
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
# Setup the logger
|
||||||
# Set the log level if necessary
|
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
||||||
if options.loglevel:
|
if options.logfile:
|
||||||
import deluge.log
|
sys.stdout = None
|
||||||
deluge.log.setLoggerLevel(options.loglevel)
|
sys.stderr = None
|
||||||
|
sys.stdin = None
|
||||||
|
|
||||||
version = deluge.common.get_version()
|
version = deluge.common.get_version()
|
||||||
if deluge.common.get_revision() != "":
|
if deluge.common.get_revision() != "":
|
||||||
version = version + "r" + deluge.common.get_revision()
|
version = version + "r" + deluge.common.get_revision()
|
||||||
|
|
||||||
|
from deluge.log import LOG as log
|
||||||
log.info("Deluge ui %s", version)
|
log.info("Deluge ui %s", version)
|
||||||
log.debug("options: %s", options)
|
log.debug("options: %s", options)
|
||||||
log.debug("args: %s", args)
|
log.debug("args: %s", args)
|
||||||
|
@ -161,23 +158,14 @@ def start_daemon():
|
||||||
if not os.path.exists(deluge.common.get_default_config_dir()):
|
if not os.path.exists(deluge.common.get_default_config_dir()):
|
||||||
os.makedirs(deluge.common.get_default_config_dir())
|
os.makedirs(deluge.common.get_default_config_dir())
|
||||||
|
|
||||||
# Opens a log file and redirects stdout to it
|
# Sets the options.logfile to point to the default location
|
||||||
def open_logfile():
|
def open_logfile():
|
||||||
path = None
|
if not options.logfile:
|
||||||
if options.logfile:
|
|
||||||
path = options.logfile
|
|
||||||
else:
|
|
||||||
if options.config:
|
if options.config:
|
||||||
path = os.path.join(options.config, "deluged.log")
|
options.logfile = os.path.join(options.config, "deluged.log")
|
||||||
else:
|
else:
|
||||||
config_dir = deluge.common.get_default_config_dir()
|
config_dir = deluge.common.get_default_config_dir()
|
||||||
path = os.path.join(config_dir, "deluged.log")
|
options.logfile = os.path.join(config_dir, "deluged.log")
|
||||||
|
|
||||||
# Open a logfile
|
|
||||||
if path:
|
|
||||||
sys.stdout = open(path, "wb")
|
|
||||||
sys.stderr = sys.stdout
|
|
||||||
sys.stdin = None
|
|
||||||
|
|
||||||
# Writes out a pidfile if necessary
|
# Writes out a pidfile if necessary
|
||||||
def write_pidfile():
|
def write_pidfile():
|
||||||
|
@ -204,10 +192,12 @@ def start_daemon():
|
||||||
# Do not daemonize
|
# Do not daemonize
|
||||||
write_pidfile()
|
write_pidfile()
|
||||||
|
|
||||||
# Set the log level if necessary
|
# Setup the logger
|
||||||
if options.loglevel:
|
deluge.log.setupLogger(level=options.loglevel, filename=options.logfile)
|
||||||
import deluge.log
|
if options.logfile:
|
||||||
deluge.log.setLoggerLevel(options.loglevel)
|
sys.stdout = None
|
||||||
|
sys.stderr = None
|
||||||
|
sys.stdin = None
|
||||||
|
|
||||||
from deluge.core.daemon import Daemon
|
from deluge.core.daemon import Daemon
|
||||||
Daemon(options, args)
|
Daemon(options, args)
|
||||||
|
|
Loading…
Reference in New Issue