mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 16:17:29 +00:00
Don't crash if log line isn't understood
This commit is contained in:
parent
5c5339e34e
commit
d98618a934
@ -89,14 +89,20 @@ const regex = /^([^ ]+) - - \[([^\]]+)\] "([A-Z]+) ([^"]+) HTTP\/(?:1.0|1.1|2.0)
|
|||||||
|
|
||||||
function parseLine(line) {
|
function parseLine(line) {
|
||||||
const result = line.match(regex)
|
const result = line.match(regex)
|
||||||
return {
|
if (!result) {
|
||||||
ip: result[1],
|
console.log("Line didn't match regular expression:")
|
||||||
date: result[2],
|
console.log(line)
|
||||||
method: result[3],
|
return null
|
||||||
path: result[4],
|
} else {
|
||||||
status: result[5],
|
return {
|
||||||
bytes: +result[6],
|
ip: result[1],
|
||||||
userAgent: result[7]
|
date: result[2],
|
||||||
|
method: result[3],
|
||||||
|
path: result[4],
|
||||||
|
status: result[5],
|
||||||
|
bytes: +result[6],
|
||||||
|
userAgent: result[7]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +130,7 @@ let dateCollection = null
|
|||||||
|
|
||||||
reader.on("line", line => {
|
reader.on("line", line => {
|
||||||
const parsed = parseLine(line)
|
const parsed = parseLine(line)
|
||||||
|
if (!parsed) return
|
||||||
const dateObject = new Date(parsed.date.replace(":", " "))
|
const dateObject = new Date(parsed.date.replace(":", " "))
|
||||||
|
|
||||||
//console.log(parsed)
|
//console.log(parsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user