default logger is text again, remove colored logger

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@1505 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2004-08-25 20:08:53 +00:00
parent 228848e7c8
commit 324614ab18
8 changed files with 46 additions and 196 deletions

View file

@ -53,6 +53,15 @@ class Logger (object):
# only log given fields
self.logfields = kwargs['fields']
def init_fileoutput (self, args):
"""initialize self.fd file descriptor from args"""
if args.has_key('fileoutput'):
self.fd = file(args['filename'], "w")
elif args.has_key('fd'):
self.fd = args['fd']
else:
self.fd = sys.stdout
def has_field (self, name):
"""see if given field name will be logged"""
if self.logfields is None:

View file

@ -1,173 +0,0 @@
# -*- coding: iso-8859-1 -*-
"""a colored logger"""
# Copyright (C) 2000-2004 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import os
import linkcheck
import linkcheck.ansicolor
import linkcheck.logger.standard
from linkcheck.i18n import _
class ColoredLogger (linkcheck.logger.standard.StandardLogger):
"""ANSI colorized output"""
def __init__ (self, **args):
"""initialize standard colors"""
super(ColoredLogger, self).__init__(**args)
self.colorparent = linkcheck.ansicolor.esc_ansicolor(
args['colorparent'])
self.colorurl = linkcheck.ansicolor.esc_ansicolor(args['colorurl'])
self.colorname = linkcheck.ansicolor.esc_ansicolor(args['colorname'])
self.colorreal = linkcheck.ansicolor.esc_ansicolor(args['colorreal'])
self.colorbase = linkcheck.ansicolor.esc_ansicolor(args['colorbase'])
self.colorvalid = linkcheck.ansicolor.esc_ansicolor(
args['colorvalid'])
self.colorinvalid = linkcheck.ansicolor.esc_ansicolor(
args['colorinvalid'])
self.colorinfo = linkcheck.ansicolor.esc_ansicolor(args['colorinfo'])
self.colorwarning = linkcheck.ansicolor.esc_ansicolor(
args['colorwarning'])
self.colordltime = linkcheck.ansicolor.esc_ansicolor(
args['colordltime'])
self.colordlsize = linkcheck.ansicolor.esc_ansicolor(
args['colordlsize'])
self.colorreset = linkcheck.ansicolor.esc_ansicolor(
args['colorreset'])
self.currentPage = None
self.prefix = 0
def new_url (self, url_data):
"""print new url data in color"""
if self.fd is None:
return
if self.has_field("parenturl"):
if url_data.parent_url:
if self.currentPage != url_data.parent_url:
if self.prefix:
self.fd.write("o"+os.linesep)
self.fd.write(os.linesep+self.field("parenturl")+
self.spaces("parenturl")+
self.colorparent+url_data.parent_url+
self.colorreset+os.linesep)
self.currentPage = url_data.parent_url
self.prefix = 1
else:
if self.prefix:
self.fd.write("o"+os.linesep)
self.prefix = 0
self.currentPage = None
if self.has_field("url"):
if self.prefix:
self.fd.write("|"+os.linesep+"+- ")
else:
self.fd.write(os.linesep)
self.fd.write(self.field("url")+self.spaces("url")+self.colorurl+
repr(url_data.base_url)+self.colorreset)
if url_data.line:
self.fd.write(_(", line %d")%url_data.line)
if url_data.column:
self.fd.write(_(", col %d")%url_data.column)
if url_data.cached:
self.fd.write(_(" (cached)")+os.linesep)
else:
self.fd.write(os.linesep)
if url_data.name and self.has_field("name"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("name")+self.spaces("name")+
self.colorname+repr(url_data.name)+self.colorreset+
os.linesep)
if url_data.base_ref and self.has_field("base"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("base")+self.spaces("base")+
self.colorbase+url_data.base_ref+self.colorreset+
os.linesep)
if url_data.url and self.has_field("realurl"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("realurl")+self.spaces("realurl")+
self.colorreal+url_data.url+
self.colorreset+os.linesep)
if url_data.dltime >= 0 and self.has_field("dltime"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("dltime")+self.spaces("dltime")+
self.colordltime+
(_("%.3f seconds") % url_data.dltime)+
self.colorreset+os.linesep)
if url_data.dlsize >= 0 and self.has_field("dlsize"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("dlsize")+self.spaces("dlsize")+
self.colordlsize+
linkcheck.strformat.strsize(url_data.dlsize)+
self.colorreset+os.linesep)
if url_data.checktime and self.has_field("checktime"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("checktime")+self.spaces("checktime")+
self.colordltime+(_("%.3f seconds") % url_data.checktime)+
self.colorreset+os.linesep)
if url_data.info and self.has_field("info"):
if self.prefix:
text = os.linesep.join(url_data.info)
text = linkcheck.strformat.wrap(text, 65,
subsequent_indent="| "+self.spaces("info"))
self.fd.write("| "+self.field("info")+
self.spaces("info")+text)
else:
text = os.linesep.join(url_data.info)
text = linkcheck.strformat.wrap(text, 65,
subsequent_indent=" "+self.spaces("info"))
self.fd.write(self.field("info")+self.spaces("info")+text)
self.fd.write(self.colorreset+os.linesep)
if url_data.warning and self.has_field("warning"):
if self.prefix:
self.fd.write("| ")
text = os.linesep.join(url_data.warning)
self.fd.write(self.field("warning")+self.spaces("warning")+
self.colorwarning+text+self.colorreset+os.linesep)
if self.has_field("result"):
if self.prefix:
self.fd.write("| ")
self.fd.write(self.field("result")+self.spaces("result"))
if url_data.valid:
self.fd.write(self.colorvalid+url_data.result+
self.colorreset+os.linesep)
else:
self.errors += 1
self.fd.write(self.colorinvalid+url_data.result+
self.colorreset+os.linesep)
self.flush()
def end_output (self, linknumber=-1):
"""print end of checking message and flush output buffers"""
if self.fd is None:
return
if self.has_field("outro"):
if self.prefix:
self.fd.write("o"+os.linesep)
super(ColoredLogger, self).end_output(linknumber=linknumber)

View file

@ -20,26 +20,26 @@ import time
import csv
import os
import linkcheck.logger.standard
import linkcheck.logger
import linkcheck.configuration
from linkcheck.i18n import _
class CSVLogger (linkcheck.logger.standard.StandardLogger):
class CSVLogger (linkcheck.logger.Logger):
""" CSV output. CSV consists of one line per entry. Entries are
separated by a semicolon.
"""
def __init__ (self, **args):
"""store default separator and (os dependent) line terminator"""
super(CSVLogger, self).__init__(**args)
self.init_fileoutput(args)
self.separator = args['separator']
self.lineterminator = os.linesep
def start_output (self):
"""print checking start info as csv comment"""
linkcheck.logger.Logger.start_output(self)
super(CSVLogger, self).start_output()
if self.fd is None:
return
self.starttime = time.time()

View file

@ -19,13 +19,12 @@
import time
import os
import linkcheck.logger.standard
import linkcheck.configuration
from linkcheck.i18n import _
class GMLLogger (linkcheck.logger.standard.StandardLogger):
class GMLLogger (linkcheck.logger.Logger):
"""GML means Graph Modeling Language. Use a GML tool to see
your sitemap graph.
"""
@ -33,12 +32,13 @@ class GMLLogger (linkcheck.logger.standard.StandardLogger):
def __init__ (self, **args):
"""initialize graph node list and internal id counter"""
super(GMLLogger, self).__init__(**args)
self.init_fileoutput(args)
self.nodes = {}
self.nodeid = 0
def start_output (self):
"""print start of checking info as gml comment"""
linkcheck.logger.Logger.init(self)
super(GMLLogger, self).start_output()
if self.fd is None:
return
self.starttime = time.time()

View file

@ -21,7 +21,6 @@ import cgi
import os
import linkcheck.logger
import linkcheck.logger.standard
import linkcheck.strformat
import linkcheck.configuration
@ -46,12 +45,13 @@ HTML_HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<body bgcolor="%s" link="%s" vlink="%s" alink="%s">
"""
class HtmlLogger (linkcheck.logger.standard.StandardLogger):
class HtmlLogger (linkcheck.logger.Logger):
"""Logger with HTML output"""
def __init__ (self, **args):
"""initialize default HTML color values"""
super(HtmlLogger, self).__init__(**args)
self.init_fileoutput(args)
self.colorbackground = args['colorbackground']
self.colorurl = args['colorurl']
self.colorborder = args['colorborder']
@ -62,7 +62,7 @@ class HtmlLogger (linkcheck.logger.standard.StandardLogger):
def start_output (self):
"""print start of checking info"""
linkcheck.logger.Logger.start_output(self)
super(HtmlLogger, self).start_output()
if self.fd is None:
return
self.starttime = time.time()

View file

@ -20,7 +20,6 @@ import time
import os
import linkcheck
import linkcheck.logger.standard
import linkcheck.logger
from linkcheck.i18n import _
@ -33,12 +32,13 @@ def sqlify (s):
return "'%s'" % s.replace("'", "''")
class SQLLogger (linkcheck.logger.standard.StandardLogger):
class SQLLogger (linkcheck.logger.Logger):
"""SQL output for PostgreSQL, not tested"""
def __init__ (self, **args):
"""initialize database access data"""
super(SQLLogger, self).__init__(**args)
self.init_fileoutput(args)
self.dbname = args['dbname']
self.separator = args['separator']

View file

@ -28,8 +28,8 @@ import linkcheck.configuration
from linkcheck.i18n import _
class StandardLogger (linkcheck.logger.Logger):
"""Standard text logger.
class TextLogger (linkcheck.logger.Logger):
"""A text logger, colorizing the output if possible.
Every Logger has to implement the following functions:
start_output (self)
@ -64,18 +64,32 @@ class StandardLogger (linkcheck.logger.Logger):
def __init__ (self, **args):
"""initialize error counter and optional file output"""
super(StandardLogger, self).__init__(**args)
super(TextLogger, self).__init__(**args)
self.init_fileoutput(args)
self.colorparent = linkcheck.ansicolor.esc_ansicolor(
args['colorparent'])
self.colorurl = linkcheck.ansicolor.esc_ansicolor(args['colorurl'])
self.colorname = linkcheck.ansicolor.esc_ansicolor(args['colorname'])
self.colorreal = linkcheck.ansicolor.esc_ansicolor(args['colorreal'])
self.colorbase = linkcheck.ansicolor.esc_ansicolor(args['colorbase'])
self.colorvalid = linkcheck.ansicolor.esc_ansicolor(
args['colorvalid'])
self.colorinvalid = linkcheck.ansicolor.esc_ansicolor(
args['colorinvalid'])
self.colorinfo = linkcheck.ansicolor.esc_ansicolor(args['colorinfo'])
self.colorwarning = linkcheck.ansicolor.esc_ansicolor(
args['colorwarning'])
self.colordltime = linkcheck.ansicolor.esc_ansicolor(
args['colordltime'])
self.colordlsize = linkcheck.ansicolor.esc_ansicolor(
args['colordlsize'])
self.colorreset = linkcheck.ansicolor.esc_ansicolor(
args['colorreset'])
self.errors = 0
if args.has_key('fileoutput'):
self.fd = file(args['filename'], "w")
elif args.has_key('fd'):
self.fd = args['fd']
else:
self.fd = sys.stdout
def start_output (self):
"""print generic start checking info"""
super(StandardLogger, self).start_output()
super(TextLogger, self).start_output()
if self.fd is None:
return
self.starttime = time.time()

View file

@ -20,7 +20,6 @@ import os
import time
import xml.sax.saxutils
import linkcheck.logger.standard
import linkcheck.logger
import linkcheck.configuration
@ -55,13 +54,14 @@ def xmlunquoteattr (s):
return xml.sax.saxutils.unescape(s, xmlattr_entities)
class XMLLogger (linkcheck.logger.standard.StandardLogger):
class XMLLogger (linkcheck.logger.Logger):
"""XML output mirroring the GML structure. Easy to parse with any XML
tool."""
def __init__ (self, **args):
"""initialize graph node list and internal id counter"""
super(XMLLogger, self).__init__(**args)
self.init_fileoutput(args)
self.nodes = {}
self.nodeid = 0