1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

feat(log): added parseErrorsAndWarnings utility

This commit is contained in:
Yury Shkoda
2023-04-10 15:45:54 +03:00
parent 15774eca34
commit 7c1c1e2410
4 changed files with 51 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ import { PermissionsContext } from '../../../../context/permissionsContext'
import {
findExistingPermission,
findUpdatingPermission
} from '../../../../utils/helper'
} from '../../../../utils'
const useAddPermission = () => {
const {

3
web/src/utils/index.ts Normal file
View File

@@ -0,0 +1,3 @@
export * from './log'
export * from './types'
export * from './helper'

41
web/src/utils/log.ts Normal file
View File

@@ -0,0 +1,41 @@
export const parseErrorsAndWarnings = (log: string) => {
const logLines = log.split('\n')
const errorLines: string[] = []
const warningLines: string[] = []
logLines.forEach((line: string, index: number) => {
// INFO: check if content in element starts with ERROR
if (/<.*>ERROR/gm.test(line)) {
const errorLine = line.substring(line.indexOf('E'), line.length - 1)
errorLines.push(errorLine)
}
// INFO: check if line starts with ERROR
else if (/^ERROR/gm.test(line)) {
errorLines.push(line)
logLines[index] =
`<font id="error_${errorLines.length - 1}">` +
logLines[index] +
'</font>'
}
// INFO: check if content in element starts with WARNING
else if (/<.*>WARNING/gm.test(line)) {
const warningLine = line.substring(line.indexOf('W'), line.length - 1)
warningLines.push(warningLine)
}
// INFO: check if line starts with WARNING
else if (/^WARNING/gm.test(line)) {
warningLines.push(line)
logLines[index] =
`<font id="warning_${warningLines.length - 1}">` +
logLines[index] +
'</font>'
}
})
return { errors: errorLines, warnings: warningLines, logLines }
}

View File

@@ -39,3 +39,9 @@ export interface TreeNode {
isFolder: boolean
children: Array<TreeNode>
}
export interface LogObject {
body: string
errors: string[]
warnings: string[]
}