def __init__(self, **kwargs): """Creates a new instance of MarkupError.""" self._thrown = Logger.getFormattedStackTrace(2, 3) self._definition = ArgsUtils.get('errorDef', None, kwargs) self._tag = ArgsUtils.get('tag', None, kwargs) self._block = ArgsUtils.get('block', self._tag.block if self._tag else None, kwargs) self._processor = ArgsUtils.get('processor', self._tag.processor if self._tag else None, kwargs) self._code = ArgsUtils.get('code', self._definition.code, kwargs, allowNone=False) self.label = ArgsUtils.get('label', self._definition.label, kwargs, allowNone=False) self.message = ArgsUtils.get('message', self._definition.message, kwargs, allowNone=False) self._critical = ArgsUtils.get('critical', False, kwargs) replacements = ArgsUtils.getAsList('replacements', kwargs) replacements.append([u'#TAG#', unicode(self._tag.tagName if self._tag else u'???')]) for r in replacements: if self.message: self.message = self.message.replace(unicode(r[0]), unicode(r[1])) if self.label: self.label = self.label.replace(unicode(r[0]), unicode(r[1])) self._verbose = ArgsUtils.get('verbose', False, kwargs) self._line = None self._character = None self._source = None self._logSource = None self._populateData()
def writeLog( self, header, message, extras =None, headerColor =None, headerBackColor =None, color =None, backColor =None, fontSize =None, error =None, prefix =None, suffix =None ): """ Formats the specified header and message according to the various formatting arguments and writes resulting message the log """ if not headerColor: headerColor = u'#000000' if not headerBackColor: headerBackColor = u'#FFFFFF' if not color: color = u'#333333' if not backColor: backColor = u'#FFFFFF' if not fontSize: fontSize = 11 # Out is formatted on separate lines because Qt text edit widget requires newlines to # change styles out = [ u'<div style="font-size:%spx;color:%s;background-color:%s;">' % ( fontSize, color, backColor), u'<span style="font-weight:bold;color:%s;background-color:%s;font-size:%spx;">' % ( headerColor, headerBackColor, fontSize + 2), unicode(header) + u': ', u'</span>', unicode(message), u'</div>'] if prefix: out.insert(0, prefix) #--- EXTRAS # If an extras argument (dict, list, or basestring) was included, format it for # friendly display if extras: out.append(u'<div>\n<ul style="font-size:%spx;color:%s;background-color:%s">' % ( fontSize, color, backColor)) if isinstance(extras, list): for item in extras: out.append(u'<li>%s</li>' % item) elif isinstance(extras, dict): for n,v in extras.iteritems(): out.append(u'<li><span style="font-weight:bold">%s:</span> %s</li>' % (n, v)) else: out.append(u'<li>%s</li>' % extras) out.append(u'</ul>\n<div>') #--- ERROR # Format the error and stack trace for friendly display if present if error: out.append(u'<div style="font-size:14px;color:%s">%s</div>' % (headerColor, error)) stack = Logger.getFormattedStackTrace(0, 3) out.extend([ u'<br />', u'<div style="font-size:10px;color:#AAAAAA">', u'<span style="font-weight:bold">Thrown At:</span> %s' % stack.replace( '\n', u'<br />').replace( ' ', ' ').replace( '\t', ' '), u'</div>\n<br />']) if suffix: out.append(suffix) # Create final combined string and shorten known paths for compact display out = u'\n'.join(out).replace( self.sourceWebRootPath, u'/').replace( self.containerPath, u'//') self.logger.write(out)