overleaf/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee

29 lines
998 B
CoffeeScript
Raw Normal View History

define [
"libs/latex-log-parser"
2016-06-16 10:29:00 -04:00
"ide/human-readable-logs/HumanReadableLogsRules"
], (LogParser, ruleset) ->
parse : (rawLog, options) ->
if typeof rawLog is 'string'
parsedLogEntries = LogParser.parse(rawLog, options)
else
parsedLogEntries = rawLog
2016-06-16 10:29:00 -04:00
_getRule = (logMessage) ->
return rule for rule in ruleset when rule.regexToMatch.test logMessage
for entry in parsedLogEntries.all
ruleDetails = _getRule entry.message
2016-06-16 10:29:00 -04:00
if (ruleDetails?)
if ruleDetails.ruleId?
entry.ruleId = ruleDetails.ruleId
else if ruleDetails.regexToMatch?
entry.ruleId = 'hint_' + ruleDetails.regexToMatch.toString().replace(/\s/g, '_').slice(1, -1)
if ruleDetails.newMessage?
entry.message = entry.message.replace ruleDetails.regexToMatch, ruleDetails.newMessage
2016-06-30 06:30:43 -04:00
entry.humanReadableHint = ruleDetails.humanReadableHint if ruleDetails.humanReadableHint?
entry.extraInfoURL = ruleDetails.extraInfoURL if ruleDetails.extraInfoURL?
return parsedLogEntries