mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-21 02:01:35 +00:00
Add logging endpoint to supervisor
Change-type: minor Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
parent
6e2801380b
commit
6156825293
@ -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);
|
||||
});
|
||||
}
|
||||
|
@ -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),
|
||||
|
Loading…
x
Reference in New Issue
Block a user