diff --git a/ckanext/odsh/plugin.py b/ckanext/odsh/plugin.py index f4438e152cfe5c7446a9f5cf9944d6d8a319603f..32d10c8410c519e7f49c24604d47e6d42f9a3466 100644 --- a/ckanext/odsh/plugin.py +++ b/ckanext/odsh/plugin.py @@ -26,6 +26,56 @@ log = logging.getLogger(__name__) _ = toolkit._ +from multiline_formatter.formatter import MultilineMessagesFormatter +class OdshLogger(MultilineMessagesFormatter): + multiline_marker = '...' + multiline_fmt = multiline_marker + ' : %(message)s' + + def format(self, record): + """ + This is mostly the same as logging.Formatter.format except for the splitlines() thing. + This is done so (copied the code) to not make logging a bottleneck. It's not lots of code + after all, and it's pretty straightforward. + """ + endl_marker = '\n... : ";' + record.message = record.getMessage() + if self.usesTime(): + record.asctime = self.formatTime(record, self.datefmt) + if '\n' in record.message: + splitted = record.message.splitlines() + output = self._fmt % dict(record.__dict__, message=splitted.pop(0)) + output += ' ' + self.multiline_marker % record.__dict__ + '\n' + output += '\n'.join( + self.multiline_fmt % dict(record.__dict__, message=line) + for line in splitted + ) + output = output.replace('"','\\\\"') + output += endl_marker + else: + output = self._fmt % record.__dict__ + + if record.exc_info: + # Cache the traceback text to avoid converting it multiple times + # (it's constant anyway) + if not record.exc_text: + record.exc_text = self.formatException(record.exc_info) + if record.exc_text: + output += ' ' + self.multiline_marker % record.__dict__ + '\n' + try: + output += '\n'.join( + self.multiline_fmt % dict(record.__dict__, message=line) + for index, line in enumerate(record.exc_text.splitlines()) + ) + output = output.replace('"','\\\\"') + output += endl_marker + except UnicodeError: + output += '\n'.join( + self.multiline_fmt % dict(record.__dict__, message=line) + for index, line + in enumerate(record.exc_text.decode(sys.getfilesystemencoding(), 'replace').splitlines()) + ) + return output + def odsh_get_facet_items_dict(name, limit=None): ''' @@ -304,6 +354,10 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm # use several daterange queries agains temporal_start and temporal_end field # TODO: use field of type date_range in solr index instead def before_search(self, search_params): + try: + raise BaseException('boom') + except: + log.exception("got exception") extras = search_params.get('extras') if not extras: diff --git a/uls.conf b/uls.conf new file mode 100644 index 0000000000000000000000000000000000000000..0c9c4df7b288c895b1858a5c03df1c0caea6f8f7 --- /dev/null +++ b/uls.conf @@ -0,0 +1,23 @@ +inputfile = test.log +outputfile = ./out.uls + +# %F = YYYY-MM-DD +# %T = hh:mm:ss +# %W = der ganze Rest +#inputformat = {"asctime": "%F %T,%c%c%c", "levelname": "ERROR", "name": "%q", "message": "%W +iformat0 = %F %T,%c%c%c ERROR [%q] got exception ...%W +#nreadformat0 =... (7568:worker 2) : %W +nreadformat0 =... : %W + +# Alle Zeilen, die ERR enthalten +reg0 = got exception ... +nreadreg0 =^... : +#consolidate0 = 0/1s: 2 + +# Gebe die ganze Zeile auf stdout aus +#eaction = echo %F %T %q +#action0 = echo %F %T [%q,%p] %W +#nreadaction0 = echo %W +##write0 = V;%F %T;source;"section";"teststep";"detail";"Text"; [%q,%p] %W +write0 = V;%F %T;ckan274;"ULS";"Test";"detail";"Text";" +nreadwrite0 = %W \ No newline at end of file