getStats
Get statistics about the current log storage.
Syntax​
getStats(): Promise<{ totalLogs: number; activeLoggers: number; maxLogs: number }>
Returns​
A Promise<object> with the following properties:
totalLogs(number): Total number of log entries storedactiveLoggers(number): Number of unique logger instances that have loggedmaxLogs(number): Maximum number of logs allowed
Examples​
Basic Usage​
const logger = InteractiveLogger();
const stats = await logger.getStats();
console.log(`Total logs: ${stats.totalLogs}`);
console.log(`Active loggers: ${stats.activeLoggers}`);
console.log(`Max logs: ${stats.maxLogs}`);
Display Statistics​
const logger = InteractiveLogger();
const stats = await logger.getStats();
const usagePercent = (stats.totalLogs / stats.maxLogs) * 100;
console.log(`Storage: ${stats.totalLogs}/${stats.maxLogs} (${usagePercent.toFixed(1)}%)`);
console.log(`Active loggers: ${stats.activeLoggers}`);
Check Storage Usage​
const logger = InteractiveLogger();
const stats = await logger.getStats();
if (stats.totalLogs > stats.maxLogs * 0.9) {
console.warn('Storage is nearly full');
await logger.setMaxLogs(stats.maxLogs * 2);
}
See Also​
- setMaxLogs - Update maximum log limit
- clear - Clear all logs