Add ?build query param for logs

This commit is contained in:
Johannes Zellner
2015-04-14 12:52:43 +02:00
parent a49dbe6d90
commit 4544a86846
2 changed files with 41 additions and 2 deletions
+35
View File
@@ -19,6 +19,9 @@ exports = module.exports = {
getLogStream: getLogStream,
getLogs: getLogs,
getBuildLogStream: getBuildLogStream,
getBuildLogs: getBuildLogs,
start: start,
stop: stop,
@@ -484,6 +487,38 @@ function getLogs(appId, callback) {
});
}
function getBuildLogStream(appId, fromLine, callback) {
assert(typeof appId === 'string');
assert(typeof fromLine === 'number'); // behaves like tail -n
assert(typeof callback === 'function');
debug('Getting build logs for %s', appId);
appdb.get(appId, function (error, app) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND));
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
var logStream = fs.createReadStream(path.join(paths.APP_SOURCES_DIR, app.id + '.log'));
return callback(null, logStream);
});
}
function getBuildLogs(appId, callback) {
assert(typeof appId === 'string');
assert(typeof callback === 'function');
debug('Getting build logs for %s', appId);
appdb.get(appId, function (error, app) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new AppsError(AppsError.NOT_FOUND));
if (error) return callback(new AppsError(AppsError.INTERNAL_ERROR, error));
var logStream = fs.createReadStream(path.join(paths.APP_SOURCES_DIR, app.id + '.log'));
return callback(null, logStream);
});
}
function uninstall(appId, callback) {
assert(typeof appId === 'string');
assert(typeof callback === 'function');
+6 -2
View File
@@ -242,7 +242,9 @@ function getLogStream(req, res, next) {
if (req.headers.accept !== 'text/event-stream') return next(new HttpError(400, 'This API call requires EventStream'));
apps.getLogStream(req.params.id, fromLine, function (error, logStream) {
var func = req.params.build ? apps.getBuildLogStream : apps.getLogStream;
func(req.params.id, fromLine, function (error, logStream) {
if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app'));
if (error && error.reason === AppsError.BAD_STATE) return next(new HttpError(412, error.message));
if (error) return next(new HttpError(500, error));
@@ -271,7 +273,9 @@ function getLogs(req, res, next) {
debug('Getting logs of app id:%s', req.params.id);
apps.getLogs(req.params.id, function (error, logStream) {
var func = req.params.build ? apps.getBuildLogs : apps.getLogs;
func(req.params.id, function logHandler(error, logStream) {
if (error && error.reason === AppsError.NOT_FOUND) return next(new HttpError(404, 'No such app'));
if (error && error.reason === AppsError.BAD_STATE) return next(new HttpError(412, error.message));
if (error) return next(new HttpError(500, error));