-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogs-parser.ts
More file actions
24 lines (22 loc) · 889 Bytes
/
logs-parser.ts
File metadata and controls
24 lines (22 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { informationSourceTypeToString } from "./enums/enum-functions";
import { InformationSourceType } from "./enums/enums";
export function parseContainerLogsData(logs: string[], isType: InformationSourceType = null) {
if (!logs) {
if (isType) return [`Running ${informationSourceTypeToString(isType, false)}...`];
else return null;
}
if (!Array.isArray(logs)) return null;
if (logs.length == 0) return [];
const neededIDLength = String(logs.length)?.length;
return logs.map((wrapper, index) => {
const d: Date = new Date(wrapper.substr(0, wrapper.indexOf(' ')));
if (isNaN(d.getTime())) return wrapper;
return (
String(index + 1).padStart(neededIDLength, '0') +
': ' +
d.toLocaleString() +
' - ' +
wrapper.substr(wrapper.indexOf(' ') + 1)
);
});
}