Properly set default thresholds on log appenders.
This commit was merged in pull request #1.
This commit is contained in:
@@ -5,7 +5,7 @@ export class ApiLogAppender implements LogAppender {
|
|||||||
public batchSize = 10
|
public batchSize = 10
|
||||||
public minimumTimePassedInSec = 60
|
public minimumTimePassedInSec = 60
|
||||||
public maximumTimePassedInSec = 120
|
public maximumTimePassedInSec = 120
|
||||||
public threshold = LogLevel.ALL
|
public threshold: LogLevel
|
||||||
|
|
||||||
private msgBuffer: FlattenedLogMessage[] = []
|
private msgBuffer: FlattenedLogMessage[] = []
|
||||||
private lastSent = 0
|
private lastSent = 0
|
||||||
@@ -16,9 +16,7 @@ export class ApiLogAppender implements LogAppender {
|
|||||||
threshold?: LogLevel
|
threshold?: LogLevel
|
||||||
) {
|
) {
|
||||||
setTimeout(this.checkPost, 1000)
|
setTimeout(this.checkPost, 1000)
|
||||||
if (threshold) {
|
this.threshold = threshold ?? LogLevel.ALL
|
||||||
this.threshold = threshold
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public appendMessage(msg: LogMessage): void {
|
public appendMessage(msg: LogMessage): void {
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
import type {
|
import type { LogAppender } from './log-appender'
|
||||||
LogLevel,
|
import { LogLevel, type LogMessage } from './log-message'
|
||||||
LogMessage
|
|
||||||
} from './log-message'
|
|
||||||
|
|
||||||
export class BufferLogAppender implements LogAppender {
|
export class BufferLogAppender implements LogAppender {
|
||||||
public threshold = LogLevel.ALL
|
public threshold: LogLevel
|
||||||
public buffer: LogMessage[]
|
public buffer: LogMessage[]
|
||||||
|
|
||||||
constructor(buffer: LogMessage[], threshold?: LogLevel) {
|
constructor(buffer?: LogMessage[], threshold?: LogLevel) {
|
||||||
this.buffer = buffer
|
this.buffer = buffer ?? []
|
||||||
|
this.threshold = threshold ?? LogLevel.ALL
|
||||||
if (threshold) {
|
|
||||||
this.threshold = threshold
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public appendMessage(msg: LogMessage): void {
|
public appendMessage(msg: LogMessage): void {
|
||||||
if (this.threshold && msg.level < this.threshold) return
|
if (this.threshold && msg.level < this.threshold) return
|
||||||
else buffer.push(msg)
|
else this.buffer.push(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearBuffer(): void {
|
public clearBuffer(): void {
|
||||||
|
|||||||
@@ -18,16 +18,12 @@ import { LogAppender } from './log-appender'
|
|||||||
* data for inspection in the browser's developer tools.
|
* data for inspection in the browser's developer tools.
|
||||||
*/
|
*/
|
||||||
export class ConsoleLogAppender implements LogAppender {
|
export class ConsoleLogAppender implements LogAppender {
|
||||||
public threshold = LogLevel.ALL
|
public threshold: LogLevel
|
||||||
public formatter: LogMessageFormatter = flattenMessage
|
public formatter: LogMessageFormatter
|
||||||
|
|
||||||
constructor(threshold?: LogLevel, formatter?: LogMessageFormatter) {
|
constructor(threshold?: LogLevel, formatter?: LogMessageFormatter) {
|
||||||
if (threshold) {
|
this.threshold = threshold ?? LogLevel.ALL
|
||||||
this.threshold = threshold
|
this.formatter = formatter ?? flattenMessage
|
||||||
}
|
|
||||||
if (formatter) {
|
|
||||||
this.formatter = formatter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public appendMessage(msg: LogMessage): void {
|
public appendMessage(msg: LogMessage): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user