Add logging endpoint to supervisor

Change-type: minor
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-10-09 12:04:50 +01:00
parent 6e2801380b
commit 6156825293
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
2 changed files with 14 additions and 0 deletions

View File

@ -284,4 +284,14 @@ export function createV2Api(router: Router, applications: ApplicationManager) {
});
}
});
router.get('/v2/local/logs', async (_req, res) => {
const backend = applications.logger.getLocalBackend();
backend.assignServiceNameResolver(applications.serviceNameFromId.bind(applications));
// Get the stream, and stream it into res
const listenStream = backend.attachListener();
listenStream.pipe(res);
});
}

View File

@ -298,6 +298,10 @@ export class Logger {
const logLine = msgBuf.toString();
const space = logLine.indexOf(' ');
if (space > 0) {
let timestamp = (new Date(logLine.substr(0, space))).getTime();
if (_.isNaN(timestamp)) {
timestamp = Date.now();
}
return {
timestamp: (new Date(logLine.substr(0, space))).getTime(),
message: logLine.substr(space + 1),