1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const os = require("os");
|
4 | const logger_1 = require("./logger");
|
5 | let logger = new logger_1.Logger('testLogger');
|
6 | class TaskLogger {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | constructor(task, pid) {
|
16 | this.task = task;
|
17 | this.pid = pid;
|
18 | this.buffer = '';
|
19 | this.insertTag = true;
|
20 | this.logHeader_();
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | logHeader_() {
|
29 | let output = 'PID: ' + this.pid + os.EOL;
|
30 | if (this.task.specs.length === 1) {
|
31 | output += 'Specs: ' + this.task.specs.toString() + os.EOL + os.EOL;
|
32 | }
|
33 | this.log(output);
|
34 | }
|
35 | |
36 |
|
37 |
|
38 | peek() {
|
39 | if (this.buffer) {
|
40 |
|
41 | logger.info(os.EOL + '------------------------------------' + os.EOL);
|
42 | logger.info(this.buffer);
|
43 | logger.info(os.EOL);
|
44 | }
|
45 | }
|
46 | |
47 |
|
48 |
|
49 | flush() {
|
50 | if (this.buffer) {
|
51 | this.peek();
|
52 | this.buffer = '';
|
53 | }
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | log(data) {
|
62 | let tag = '[';
|
63 | let capabilities = this.task.capabilities;
|
64 | tag += (capabilities.logName) ? capabilities.logName :
|
65 | (capabilities.browserName) ? capabilities.browserName : '';
|
66 | tag += (capabilities.version) ? (' ' + capabilities.version) : '';
|
67 | tag += (capabilities.platform) ? (' ' + capabilities.platform) : '';
|
68 | tag += (capabilities.logName && capabilities.count < 2) ? '' : ' #' + this.task.taskId;
|
69 | tag += '] ';
|
70 | data = data.toString();
|
71 | for (let i = 0; i < data.length; i++) {
|
72 | if (this.insertTag) {
|
73 | this.insertTag = false;
|
74 |
|
75 |
|
76 |
|
77 | if (data[i] === '\x1B' && data.substring(i, i + 4) === '\x1B[0m') {
|
78 | this.buffer += ('\x1B[0m' + tag);
|
79 | i += 3;
|
80 | continue;
|
81 | }
|
82 | this.buffer += tag;
|
83 | }
|
84 | if (data[i] === '\n') {
|
85 | this.insertTag = true;
|
86 | }
|
87 | this.buffer += data[i];
|
88 | }
|
89 | }
|
90 | }
|
91 | exports.TaskLogger = TaskLogger;
|
92 |
|
\ | No newline at end of file |