Fix all sources to comply with eslint rules introduced in 2.0.0 (no logic changes).
This commit is contained in:
+22
-22
@@ -1,32 +1,32 @@
|
||||
import { LogMessage, LogLevel, flattenMessage, FlattenedLogMessage } from './log-message';
|
||||
import { LogAppender } from './log-appender';
|
||||
import { LogMessage, LogLevel, flattenMessage, FlattenedLogMessage } from './log-message'
|
||||
import { LogAppender } from './log-appender'
|
||||
|
||||
export class ApiLogAppender implements LogAppender {
|
||||
public batchSize = 10;
|
||||
public minimumTimePassedInSec = 60;
|
||||
public maximumTimePassedInSec = 120;
|
||||
public threshold = LogLevel.ALL;
|
||||
public batchSize = 10
|
||||
public minimumTimePassedInSec = 60
|
||||
public maximumTimePassedInSec = 120
|
||||
public threshold = LogLevel.ALL
|
||||
|
||||
private msgBuffer: FlattenedLogMessage[] = [];
|
||||
private lastSent = 0;
|
||||
private msgBuffer: FlattenedLogMessage[] = []
|
||||
private lastSent = 0
|
||||
|
||||
constructor(
|
||||
public readonly apiEndpoint: string,
|
||||
public authToken?: string,
|
||||
threshold?: LogLevel
|
||||
) {
|
||||
setTimeout(this.checkPost, 1000);
|
||||
setTimeout(this.checkPost, 1000)
|
||||
if (threshold) {
|
||||
this.threshold = threshold;
|
||||
this.threshold = threshold
|
||||
}
|
||||
}
|
||||
|
||||
public appendMessage(msg: LogMessage): void {
|
||||
if (this.threshold && msg.level < this.threshold) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
this.msgBuffer.push(flattenMessage(msg));
|
||||
this.msgBuffer.push(flattenMessage(msg))
|
||||
}
|
||||
|
||||
private doPost() {
|
||||
@@ -39,29 +39,29 @@ export class ApiLogAppender implements LogAppender {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${this.authToken}`
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
this.lastSent = Date.now();
|
||||
this.msgBuffer = [];
|
||||
this.lastSent = Date.now()
|
||||
this.msgBuffer = []
|
||||
}
|
||||
}
|
||||
|
||||
private checkPost = () => {
|
||||
const now = Date.now();
|
||||
const min = this.lastSent + this.minimumTimePassedInSec * 1000;
|
||||
const max = this.lastSent + this.maximumTimePassedInSec * 1000;
|
||||
const now = Date.now()
|
||||
const min = this.lastSent + this.minimumTimePassedInSec * 1000
|
||||
const max = this.lastSent + this.maximumTimePassedInSec * 1000
|
||||
|
||||
if (
|
||||
(this.msgBuffer.length >= this.batchSize && min < now) ||
|
||||
(this.msgBuffer.length > 0 && max < now)
|
||||
) {
|
||||
this.doPost();
|
||||
this.doPost()
|
||||
}
|
||||
setTimeout(
|
||||
this.checkPost,
|
||||
Math.max(10000, this.minimumTimePassedInSec * 1000)
|
||||
);
|
||||
};
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default ApiLogAppender;
|
||||
export default ApiLogAppender
|
||||
|
||||
Reference in New Issue
Block a user