2021-09-28 05:32:52 -04:00
|
|
|
import LatexLogParser from '../log-parser/latex-log-parser'
|
2020-05-19 05:02:56 -04:00
|
|
|
import ruleset from './HumanReadableLogsRules'
|
|
|
|
|
|
|
|
export default {
|
2018-11-05 05:06:39 -05:00
|
|
|
parse(rawLog, options) {
|
|
|
|
let parsedLogEntries
|
|
|
|
if (typeof rawLog === 'string') {
|
2021-09-28 05:32:52 -04:00
|
|
|
const latexLogParser = new LatexLogParser(rawLog, options)
|
|
|
|
parsedLogEntries = latexLogParser.parse()
|
2018-11-05 05:06:39 -05:00
|
|
|
} else {
|
|
|
|
parsedLogEntries = rawLog
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const _getRule = function (logMessage) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const rule of ruleset) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (rule.regexToMatch.test(logMessage)) {
|
|
|
|
return rule
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const seenErrorTypes = {} // keep track of types of errors seen
|
|
|
|
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const entry of parsedLogEntries.all) {
|
2018-11-05 05:06:39 -05:00
|
|
|
const ruleDetails = _getRule(entry.message)
|
|
|
|
|
|
|
|
if (ruleDetails != null) {
|
2021-10-26 04:08:56 -04:00
|
|
|
let type
|
2018-11-05 05:06:39 -05:00
|
|
|
if (ruleDetails.ruleId != null) {
|
|
|
|
entry.ruleId = ruleDetails.ruleId
|
|
|
|
}
|
|
|
|
if (ruleDetails.newMessage != null) {
|
|
|
|
entry.message = entry.message.replace(
|
|
|
|
ruleDetails.regexToMatch,
|
|
|
|
ruleDetails.newMessage
|
|
|
|
)
|
|
|
|
}
|
2023-02-20 08:45:22 -05:00
|
|
|
if (ruleDetails.contentRegex) {
|
|
|
|
const match = entry.content.match(ruleDetails.contentRegex)
|
|
|
|
if (match) {
|
|
|
|
entry.contentDetails = match.slice(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (entry.contentDetails && ruleDetails.improvedTitle) {
|
2023-09-11 05:56:43 -04:00
|
|
|
const message = ruleDetails.improvedTitle(
|
2023-02-20 08:45:22 -05:00
|
|
|
entry.message,
|
|
|
|
entry.contentDetails
|
|
|
|
)
|
2023-09-11 05:56:43 -04:00
|
|
|
if (Array.isArray(message)) {
|
|
|
|
entry.message = message[0]
|
|
|
|
entry.messageComponent = message[1]
|
|
|
|
} else {
|
|
|
|
entry.message = message
|
|
|
|
}
|
2023-02-20 08:45:22 -05:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
// suppress any entries that are known to cascade from previous error types
|
|
|
|
if (ruleDetails.cascadesFrom != null) {
|
2020-10-29 06:24:07 -04:00
|
|
|
for (type of ruleDetails.cascadesFrom) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (seenErrorTypes[type]) {
|
|
|
|
entry.suppressed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// record the types of errors seen
|
|
|
|
if (ruleDetails.types != null) {
|
2020-10-29 06:24:07 -04:00
|
|
|
for (type of ruleDetails.types) {
|
2018-11-05 05:06:39 -05:00
|
|
|
seenErrorTypes[type] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// filter out the suppressed errors (from the array entries in parsedLogEntries)
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const key in parsedLogEntries) {
|
2018-11-05 05:06:39 -05:00
|
|
|
const errors = parsedLogEntries[key]
|
|
|
|
if (typeof errors === 'object' && errors.length > 0) {
|
|
|
|
parsedLogEntries[key] = Array.from(errors).filter(
|
|
|
|
err => !err.suppressed
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedLogEntries
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|