<commit_before>import {Component, OnInit, OnDestroy, OnChanges, Input} from 'angular2/core';
import {FunctionInfo} from '../models/function-info';
import {UserService} from '../services/user.service';
import {FunctionContainer} from '../models/function-container';
import {FunctionsService} from '../services/functions.service';

@Component({
    selector: 'log-streaming',
    templateUrl: 'templates/log-streaming.component.html',
    styleUrls: ['styles/function-dev.style.css']
})
export class LogStreamingComponent implements OnDestroy, OnInit, OnChanges {
    public log: string;
    public stopped: boolean;
    private hostErrors: string;
    private xhReq: XMLHttpRequest;
    private timerId: number;
    @Input() functionInfo: FunctionInfo;

    constructor(private _userService: UserService, private _functionsService: FunctionsService) {
        this.hostErrors = '';
    }

    ngOnInit() {
        this.initLogs();
        this.startLogs()
    }

    ngOnChanges() {
        this.initLogs();
        this.startLogs()
    }

    ngOnDestroy() {
        if (this.xhReq){
            window.clearInterval(this.timerId);
            this.xhReq.abort();
        }
    }

    startLogs(){
        this.stopped = false;
    }

    stopLogs(){
        this.stopped = true;
    }

    clearLogs(){
        this.initLogs();
    }

    private initLogs() {
        if (this.xhReq) {
            window.clearInterval(this.timerId);
            this.log = '';
            this.xhReq.abort();
        }

        this._functionsService.getFunctionErrors(this.functionInfo)
            .subscribe((r: string[]) => this.hostErrors = r.reduce((a, b) => a + '\n' + b, ''));

        var scmUrl = this.functionInfo.href.substring(0, this.functionInfo.href.indexOf('/api/'));

        this.xhReq = new XMLHttpRequest();
        this.xhReq.open('GET', `${scmUrl}/api/logstream/application/functions/function/${this.functionInfo.name}`, true);
        this.xhReq.setRequestHeader('Authorization', `Bearer ${this._userService.getCurrentToken()}`);
        this.xhReq.setRequestHeader('FunctionsPortal', '1');
        this.xhReq.send(null);

        this.timerId = window.setInterval(() => {
            if (!this.stopped) {
                this.log = this.hostErrors + this.xhReq.responseText;
                window.setTimeout(() => {
                    var el = document.getElementById('log-stream');<commit_msg>Change \\n order in error messages<commit_after>import {Component, OnInit, OnDestroy, OnChanges, Input} from 'angular2/core';
import {FunctionInfo} from '../models/function-info';
import {UserService} from '../services/user.service';
import {FunctionContainer} from '../models/function-container';
import {FunctionsService} from '../services/functions.service';

@Component({
    selector: 'log-streaming',
    templateUrl: 'templates/log-streaming.component.html',
    styleUrls: ['styles/function-dev.style.css']
})
export class LogStreamingComponent implements OnDestroy, OnInit, OnChanges {
    public log: string;
    public stopped: boolean;
    private hostErrors: string;
    private xhReq: XMLHttpRequest;
    private timerId: number;
    @Input() functionInfo: FunctionInfo;

    constructor(private _userService: UserService, private _functionsService: FunctionsService) {
        this.hostErrors = '';
    }

    ngOnInit() {
        this.initLogs();
        this.startLogs()
    }

    ngOnChanges() {
        this.initLogs();
        this.startLogs()
    }

    ngOnDestroy() {
        if (this.xhReq){
            window.clearInterval(this.timerId);
            this.xhReq.abort();
        }
    }

    startLogs(){
        this.stopped = false;
    }

    stopLogs(){
        this.stopped = true;
    }

    clearLogs(){
        this.initLogs();
    }

    private initLogs() {
        if (this.xhReq) {
            window.clearInterval(this.timerId);
            this.log = '';
            this.xhReq.abort();
        }

        this._functionsService.getFunctionErrors(this.functionInfo)
            .subscribe((r: string[]) => this.hostErrors = r.reduce((a, b) => a + b + '\n', ''));

        var scmUrl = this.functionInfo.href.substring(0, this.functionInfo.href.indexOf('/api/'));

        this.xhReq = new XMLHttpRequest();
        this.xhReq.open('GET', `${scmUrl}/api/logstream/application/functions/function/${this.functionInfo.name}`, true);
        this.xhReq.setRequestHeader('Authorization', `Bearer ${this._userService.getCurrentToken()}`);
        this.xhReq.setRequestHeader('FunctionsPortal', '1');
        this.xhReq.send(null);

        this.timerId = window.setInterval(() => {
            if (!this.stopped) {
                this.log = this.hostErrors + this.xhReq.responseText;
                window.setTimeout(() => {
                    var el = document.getElementById('log-stream');
{'fraction_non_alphanumeric': 0.14318228843368508, 'fraction_numerical': 0.0012414649286157666, 'mean_word_length': 2.629129129129129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7486627', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1409, 'n_words': 254}