mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-16 18:41:07 +00:00
Added extra status logger class
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3811 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
f7a8b16096
commit
8085045ae9
5 changed files with 36 additions and 16 deletions
|
|
@ -151,7 +151,7 @@ class Configuration (dict):
|
|||
self["scanvirus"] = False
|
||||
self["clamavconf"] = clamav.canonical_clamav_conf()
|
||||
|
||||
def init_logging (self, debug=None):
|
||||
def init_logging (self, status_logger, debug=None):
|
||||
"""
|
||||
Load logging.conf file settings to set up the
|
||||
application logging (not to be confused with check loggers).
|
||||
|
|
@ -167,6 +167,7 @@ class Configuration (dict):
|
|||
handler.setFormatter(logging.Formatter("%(levelname)s %(message)s"))
|
||||
logging.getLogger(LOG).addHandler(handler)
|
||||
self.set_debug(debug)
|
||||
self.status_logger = status_logger
|
||||
|
||||
def set_debug (self, debug):
|
||||
"""Set debugging levels for configured loggers. The argument
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Aggregate (object):
|
|||
def start_threads (self):
|
||||
"""Spawn threads for URL checking and status printing."""
|
||||
if self.config["status"]:
|
||||
t = status.Status(self.urlqueue)
|
||||
t = status.Status(self.urlqueue, self.config.status_logger)
|
||||
t.start()
|
||||
self.threads.append(t)
|
||||
t = cleanup.Cleanup(self.connections)
|
||||
|
|
@ -51,7 +51,7 @@ class Aggregate (object):
|
|||
self.threads.append(t)
|
||||
num = self.config["threads"]
|
||||
if num >= 1:
|
||||
for dummy in xrange(num):
|
||||
for dummy in range(num):
|
||||
t = checker.Checker(self.urlqueue, self.logger)
|
||||
t.start()
|
||||
self.threads.append(t)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,22 @@ from .. import i18n, configuration
|
|||
_encoding = i18n.default_encoding
|
||||
stderr = codecs.getwriter(_encoding)(sys.stderr, errors="ignore")
|
||||
|
||||
|
||||
class StatusLogger (object):
|
||||
|
||||
def __init__ (self, fd=stderr):
|
||||
self.fd = fd
|
||||
|
||||
def write (self, msg):
|
||||
self.fd.write(msg)
|
||||
|
||||
def writeln (self, msg):
|
||||
self.fd.write(u"%s%s" % (msg, unicode(os.linesep)))
|
||||
|
||||
def flush (self):
|
||||
self.fd.flush()
|
||||
|
||||
|
||||
def internal_error ():
|
||||
"""
|
||||
Print internal error message to stderr.
|
||||
|
|
|
|||
|
|
@ -18,23 +18,24 @@
|
|||
import time
|
||||
from .. import strformat
|
||||
from . import task
|
||||
from .console import stderr
|
||||
|
||||
|
||||
class Status (task.CheckedTask):
|
||||
"""Status thread."""
|
||||
|
||||
def __init__ (self, urlqueue):
|
||||
def __init__ (self, urlqueue, logger):
|
||||
"""Store urlqueue object."""
|
||||
super(Status, self).__init__()
|
||||
self.urlqueue = urlqueue
|
||||
self.logger = logger
|
||||
|
||||
def run_checked (self):
|
||||
"""Print periodic status messages."""
|
||||
self.start_time = time.time()
|
||||
self.setName("Status")
|
||||
waitfor = range(5)
|
||||
while True:
|
||||
for dummy in xrange(5):
|
||||
for dummy in waitfor:
|
||||
time.sleep(1)
|
||||
if self.stopped():
|
||||
return
|
||||
|
|
@ -44,12 +45,13 @@ class Status (task.CheckedTask):
|
|||
"""Print a status message."""
|
||||
duration = time.time() - self.start_time
|
||||
checked, in_progress, queue = self.urlqueue.status()
|
||||
msg = _n("%2d URL active,", "%2d URLs active,", in_progress) % \
|
||||
msg = _n("%2d URL active", "%2d URLs active", in_progress) % \
|
||||
in_progress
|
||||
print >> stderr, msg,
|
||||
msg = _n("%5d URL queued,", "%5d URLs queued,", queue) % queue
|
||||
print >> stderr, msg,
|
||||
msg = _n("%4d URL checked,", "%4d URLs checked,", checked) % checked
|
||||
print >> stderr, msg,
|
||||
self.logger.write(u"%s, " % msg)
|
||||
msg = _n("%5d URL queued", "%5d URLs queued", queue) % queue
|
||||
self.logger.write(u"%s, " % msg)
|
||||
msg = _n("%4d URL checked", "%4d URLs checked", checked) % checked
|
||||
self.logger.write(u"%s, " % msg)
|
||||
msg = _("runtime %s") % strformat.strduration_long(duration)
|
||||
print >> stderr, msg
|
||||
self.logger.writeln(msg)
|
||||
self.logger.flush()
|
||||
|
|
|
|||
|
|
@ -255,10 +255,10 @@ class LCHelpFormatter (optparse.IndentedHelpFormatter):
|
|||
# eg. ("-x", or "-fFILENAME, --file=FILENAME")
|
||||
# * the user-supplied help string
|
||||
# eg. ("turn on expert mode", "read data from FILENAME")
|
||||
#
|
||||
|
||||
# If possible, we write both of these on the same line:
|
||||
# -x turn on expert mode
|
||||
#
|
||||
|
||||
# But if the opt string list is too long, we put the help
|
||||
# string on a second line, indented to the same column it would
|
||||
# start in if it fit on the first line.
|
||||
|
|
@ -532,7 +532,8 @@ if options.debug:
|
|||
for _name in options.debug:
|
||||
if _name not in allowed_debugs:
|
||||
print_usage(_("Invalid debug level %(level)r") % {'level': _name})
|
||||
config.init_logging(debug=options.debug)
|
||||
from linkcheck.director.console import StatusLogger
|
||||
config.init_logging(StatusLogger(), debug=options.debug)
|
||||
log.debug(LOG_CMDLINE, _("Python %(version)s on %(platform)s") % \
|
||||
{"version": sys.version, "platform": sys.platform})
|
||||
# read configuration files
|
||||
|
|
|
|||
Loading…
Reference in a new issue