Canonical URL:
https://alexstevovich.com/a/acidlog-nodejs
Software URL:
https://midnightcitylights.com/software/acidlog-nodejs
Acidlog is a lightweight persistent logger built using SQLite for efficient storage and management of logs. It provides features like automatic log retention, log pruning based on maximum entries, and support for custom loggers.
npm install acidlogimport AcidLog from 'acidlog';
// Create an instance with a custom retention period and max entries limit
const logger = new AcidLog('./logs/logs.db', {
retentionDays: 7,
maxEntries: 5000,
});
// Log entries at different levels
logger.info('System started');
logger.warn('Potential issue detected');
logger.error('Critical error occurred');
// Get the most recent 100 logs
const recentLogs = logger.getRecent(100);
console.log(recentLogs);
// Get logs by level
const errorLogs = logger.getByLevel('error', 50);
console.log(errorLogs);Creates an instance of the AcidLog logger.
filePath(string): Path to the SQLite database file where logs will be stored.options(object, optional):retentionDays(number): Number of days to retain logs. Default is5.maxEntries(number): Maximum number of log entries to store. Default is10000.logger(object): Custom logger to use internally. Default isconsole.
Records a log entry.
level(string): The log level (e.g.,"info","warn","error").message(string): The log message.system(string, optional): The subsystem or module name.
Returns the most recent limit logs.
limit(number): The number of logs to retrieve. Default is100.
Returns all logs, ordered by timestamp (most recent first).
Returns logs filtered by log level (info, warn, error).
level(string): The log level to filter by (e.g.,info).limit(number): The number of logs to retrieve. Default is100.
Logs an "info" level message.
Logs a "warn" level message.
Logs an "error" level message.
Creates a logger with a specific system or module name.
- Retention: Logs older than the
retentionDaysvalue are automatically deleted. - Max Entries: If the log entries exceed the
maxEntriesvalue, the oldest logs are deleted to keep the database within the set limit. - Custom Logger: You can pass a custom logger (like a file logger) if you prefer to log elsewhere, but the default is
console.
Licensed under the Apache License 2.0.