Better handling of multiline logs
I fixed a logic error related to the reversing of the list, and now display multi-line log messages as a single summary line with a "more info" link to expand them. Expanded log messages show without text wrap - this makes Python exception traces easier to read. For extra points, we could even do something cunning, like process the ^^^ markers into <u>
This commit is contained in:
parent
24060b6d2a
commit
4bf473fad7
1 changed files with 32 additions and 11 deletions
|
|
@ -50,8 +50,20 @@
|
||||||
'uk-alert-danger uk-alert': item.level == 'ERROR'
|
'uk-alert-danger uk-alert': item.level == 'ERROR'
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<b>{{ formatDateTime(item.timestamp) }}</b>
|
<b>{{ formatDateTime(item.timestamp) }}: {{ item.level }}</b>
|
||||||
<div class="logging-message">{{ formatMessage(item) }}</div>
|
<div class="logging-summary">
|
||||||
|
{{ item.summary }}
|
||||||
|
<a
|
||||||
|
v-if="(item.summary != item.message) & !item.expanded"
|
||||||
|
style="float: right"
|
||||||
|
@click="item.expanded = true"
|
||||||
|
>
|
||||||
|
More info...
|
||||||
|
</a>
|
||||||
|
<div v-if="item.expanded" class="logging-message">
|
||||||
|
{{ item.message }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Paginate
|
<Paginate
|
||||||
|
|
@ -135,38 +147,45 @@ export default {
|
||||||
},
|
},
|
||||||
async updateLogs() {
|
async updateLogs() {
|
||||||
let response = await axios.get(this.logFileURI);
|
let response = await axios.get(this.logFileURI);
|
||||||
let lines = response.data.split("\n").reverse();
|
let lines = response.data.split("\n");
|
||||||
this.logs = [];
|
let logs = [];
|
||||||
let regexp = /\[(.+)\] \[(.+)\] (.*)$/;
|
let regexp = /\[(.+)\] \[(.+)\] (.*)$/;
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
if (line.length > 0) {
|
if (line.length > 0) {
|
||||||
let m = line.match(regexp);
|
let m = line.match(regexp);
|
||||||
if (m) {
|
if (m) {
|
||||||
this.logs.push({
|
logs.push({
|
||||||
timestamp: m[1],
|
timestamp: m[1],
|
||||||
level: m[2],
|
level: m[2],
|
||||||
|
summary: m[3],
|
||||||
message: m[3],
|
message: m[3],
|
||||||
sequence: this.logs.length
|
sequence: logs.length,
|
||||||
|
expanded: false
|
||||||
});
|
});
|
||||||
} else if (this.logs) {
|
} else if (logs) {
|
||||||
// If a line does not look like a log entry, append it to the last
|
// If a line does not look like a log entry, append it to the last
|
||||||
// log entry (i.e. allow multi-line messages)
|
// log entry (i.e. allow multi-line messages)
|
||||||
this.logs[this.logs.length - 1].message += "\n" + line;
|
let entry = logs[logs.length - 1];
|
||||||
|
entry.message += "\n" + line;
|
||||||
|
if (entry.message.startsWith("Traceback")) {
|
||||||
|
entry.summary = line; // For tracebacks, the last line is the best summary
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if there's no existing log message to append to, discard lines
|
// if there's no existing log message to append to, discard lines
|
||||||
// until we find one.
|
// until we find one.
|
||||||
|
console.log(
|
||||||
|
"Ignored non-matching lines at the start of the log file."
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.logs = logs.reverse(); // Display in reverse chronological order
|
||||||
},
|
},
|
||||||
formatDateTime: function(isoDateTimeString) {
|
formatDateTime: function(isoDateTimeString) {
|
||||||
isoDateTimeString = isoDateTimeString.replace(",", ".");
|
isoDateTimeString = isoDateTimeString.replace(",", ".");
|
||||||
let date = new Date(isoDateTimeString);
|
let date = new Date(isoDateTimeString);
|
||||||
return date.toLocaleDateString() + " " + date.toLocaleTimeString();
|
return date.toLocaleDateString() + " " + date.toLocaleTimeString();
|
||||||
},
|
|
||||||
formatMessage: function(item) {
|
|
||||||
return item.level + ": " + item.message;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -185,5 +204,7 @@ export default {
|
||||||
}
|
}
|
||||||
.logging-message {
|
.logging-message {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
|
overflow-x: auto;
|
||||||
|
text-wrap: nowrap;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue