A lightweight, efficient logging system designed for both server environments and command-line interface (CLI) applications. Persistent Logger outputs logs to the console and stores them in a SQLite database for easy retrieval and management. Ideal for developers who value long-term data persistence and the flexibility of SQL for data manipulation.
- Console & SQLite Logging: Seamlessly logs messages to both the console and a SQLite database.
- Searchable Logs: Leverage SQL to easily search and filter log data.
- Data Persistence: Designed for long-term data storage, making it easier to track historical log data.
- Configurable Data Retention: (Soon) Includes a mechanism to periodically clean up old data, with customizable settings to manage data retention according to your needs.
Generally node.js applications. Not meant for use in the browser since browsers are client side.
Install persisted-logs via npm:
npm install persisted-logs
import BetterLog from "persisted-logs";
(async function() {
const bl = new BetterLog({ dbName:"unit-test-2.db",silent: false });
const {debug, info, warn, error, hush, unhush, hushNext} = bl; // Destructure the methods for easier access.
try {
await bl.info(['demo', 'test', 'alina'], `This is an info message. ${Date.now()}`);
await bl.debug(['demo', 'debug','test', 'Alina'], 'This is a debug message');
await bl.error(['demo', 'test', 'error', ' ALL_TAGS_ARE_NORMALIZED_TO_lowercase'], `This is an error message. it gets ${Date.now()} highlighted as an error`);
await bl.warn(['demo', 'test', 'warn', 'spaces are ok'], `This is a warning message. it gets highlighted as a warning ${Date.now()}`);
} catch (er) {
const _null = "[null]";
console.error(er?.toString() || _null);
await bl.error([], er?.toString() || _null);
}
try {
bl.hush();
await bl.info(['demo', 'hush test', 'hush-test'], `This is the hush demo. When you hush, it silences all output to the console. If you call hushNext(), it will only silence the next log message.`);
await bl.debug(['demo', 'hush test', 'hush-test'], 'The hush method will continue across all log levels until you call unhush().');
await bl.error(['demo', 'hush test', 'hush-test'], 'This includes error messages. Again, all of these still go to the persistent log.');
bl.unhush();
await bl.info(['demo', 'hush test', 'hush-test', 'unhush'], `Since Unhush has been called, this will go to the console.`);
bl.hushNext();
await bl.warn(['demo', 'hush test', 'hush-test', 'hushNext'], `This will be hushed since hushNext() was called.`);
await bl.info(['demo', 'hush test', 'hush-test', 'hushNext'], `This will not be hushed though. It will go to the console.`);
} catch (er) {
const _null = "[null]";
console.error(er?.toString() || _null);
await bl.error([], er?.toString() || _null);
}
})();
Consider the power of SQL in searching and filtering logs. For example, to search for logs with the tag "demo". Consider the benefit of using filters to chase down production bugs and such. Use tags to associate session Ids, user ids or methods to logs.
select t.tag, al.log_message, al.created_on, t.id, al.id
from app_log al
join log_tags lt on lt.log_id=al.id
join tags t on lt.tag_id=t.id
where t.tag='demo'
order by t.created_on desc, al.id desc;
https://github.com/TheOpenSourceU/persisted-logs/wiki
This project is open source and available under the MIT License.
Made with ❤️ by Frank Villasenor (https://www.theOpenSourceU.org) for the heck of it. Check out our other projects,
like AI Poems at https://poems.theOpenSourceU.org/.
Support
For support, please open an issue in the GitHub repository or contact the maintainers directly through https://www.theOpenSourceU.org.