@intuitionrobotics/ts-common
Version:
41 lines • 1.28 kB
JavaScript
import { LogClient } from "./LogClient.js";
import { LogLevel } from "./types.js";
import { _logger_convertLogParamsToStrings } from "./utils.js";
export class LogClient_BaseRotate extends LogClient {
name;
maxEntries;
maxSize;
bufferSize = 0;
rotationListener;
constructor(name, maxEntries = 10, maxSize = 1024 * 1024) {
super();
this.name = name;
this.maxSize = maxSize;
this.maxEntries = maxEntries;
}
logMessage(level, bold, prefix, toLog) {
const toLogAsString = _logger_convertLogParamsToStrings(toLog);
this.rotate();
for (const paramAsString of toLogAsString) {
const log = paramAsString + "\n";
this.printLogMessage(log);
this.bufferSize += log.length;
}
}
setRotationListener(rotationListener) {
this.rotationListener = rotationListener;
return this;
}
rotate() {
if (this.bufferSize < this.maxSize)
return;
this.cleanup();
for (let i = this.maxEntries - 1; i > 0; i--) {
this.rotateBuffer(i - 1, i);
}
this.rotationListener?.();
this.bufferSize = 0;
this.prepare();
}
}
//# sourceMappingURL=LogClient_BaseRotate.js.map