Skip to content

Commit

Permalink
Persist/buffer function logs when switching between functions in the …
Browse files Browse the repository at this point in the history
…Functions UI. Fixes #377
  • Loading branch information
ahmelsayed committed May 21, 2016
1 parent 9d36c7a commit 2f92f46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ export class LogStreamingComponent implements OnDestroy, OnChanges {
this.xhReq.setRequestHeader('Authorization', `Bearer ${this.token}`);
this.xhReq.setRequestHeader('FunctionsPortal', '1');
this.xhReq.send(null);
var oldLogs = '';

this._functionsService.getOldLogs(this.functionInfo, 10000).subscribe(r => oldLogs = r);

var callBack = () => {
var diff = this.xhReq.responseText.length - this.oldLength;
if (!this.stopped && diff > 0) {
if (this.xhReq.responseText.length > maxCharactersInLog) {
this.log = this.xhReq.responseText.substring(this.xhReq.responseText.length - maxCharactersInLog);
} else {
this.log = this.hostErrors + this.xhReq.responseText;
this.log = oldLogs
? oldLogs + this.xhReq.responseText.substring(this.xhReq.responseText.indexOf('\n') + 1)
: this.xhReq.responseText;
}

this.oldLength = this.xhReq.responseText.length;
Expand Down
22 changes: 22 additions & 0 deletions AzureFunctions.Client/app/services/functions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,28 @@ export class FunctionsService {
this.isEasyAuthEnabled = !!config['siteAuthEnabled'];
}

getOldLogs(fi: FunctionInfo, range: number): Observable<string> {
return this._http.get(`${this.scmUrl}/api/vfs/logfiles/application/functions/function/${fi.name}/`, { headers: this.getHeaders()})
.flatMap<string>(r => {
var files: any[] = r.json();
if (files.length > 0) {
var headers = this.getHeaders();
headers.append('Range', `bytes=-${range}`);
files.map(e => {e.parsedTime = new Date(e.mtime); return e;}).sort((a, b) => a.parsedTime.getTime() - b.parsedTime.getTime())
return this._http.get(files.pop().href, { headers: headers })
.map<string>(r => {
var content = r.text();
let index = content.indexOf('\n');
return index !== -1
? content.substring(index + 1)
: content;
});
} else {
return Observable.of('');
}
});
}

private getHeaders(contentType?: string): Headers {
contentType = contentType || 'application/json';
var headers = new Headers();
Expand Down

0 comments on commit 2f92f46

Please sign in to comment.