-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsonLogScript
36 lines (36 loc) · 1.37 KB
/
jsonLogScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Function called to extract date, level, app name and message
//
// @param preJSONString: string - optional non-JSON string proceeding JSON object
// @param jsonObject: {} - JSON log data
// @returns {date: Date, level: string, category: string, appName: string, message: string, rawLine: string, additionalJSON: {} }
//
// category is the availability zone
// appName is the pod name
//
const extractDateLevelCategoryAppNameMessage = function (preJSONString, jsonObject) {
let level = 'info';
let date = new Date();
let category = '';
let kind = 'Kind_is_not_set';
let message = 'Message is not set - edit or replace client/public/parsejson/plugin.js';
let additionalJSON = {};
const ignoreFields = [];
// Kube object?
if (jsonObject.kind && jsonObject.metadata) {
kind = jsonObject.kind;
message = jsonObject.metadata.name;
if (jsonObject.metadata.creationTimestamp) {
date = new Date(jsonObject.metadata.creationTimestamp);
}
level = '';
additionalJSON['level'] = undefined;
// Errors detected by the parseJson plugin?
if (jsonObject['errors']) {
level = 'error';
additionalJSON['level'] = level;
}
}
else { // Check for other log formats
}
return { date, level, category, kind, message, rawLine: undefined, additionalJSON, ignoreFields };
}