@basd/logger v0.0.5
@basd/logger
the more you know — never forget
@basd/logger is a versatile and robust logging module for Node.js and the browser. It is part of the basd ecosystem of libraries and uses @basd/base for some of its core utilities. It supports logging directly to the console, to files, and to a specified database.
Installation
npm install @basd/loggerUsage
The logger library supports different logging levels (debug, info, warn, error, log) and can print to the console or write to a database.
const Logger = require('@basd/logger')
const myLogger = new Logger()
myLogger.debug('This is a debug message')
myLogger.info('This is an info message')
myLogger.warn('This is a warning message')
myLogger.error('This is an error message')
myLogger.log('This is a generic log message')Logger Options
You can instantiate the logger with certain options:
const myLogger = new Logger({
db: myDatabaseInstance, // provide a database instance
winston: true, // enable winston logging
})Database Logging
When provided a database instance during instantiation, the logger will write logs to the database:
myLogger.print('debug', 'This is a debug message stored in the DB')Reading Logs
With the NodeLogger you can read the logs from the filesystem.
const NodeLogger = require('@basd/logger')
const nodeLogger = new NodeLogger()
nodeLogger.list().then(console.log) // list all log files
nodeLogger.read().then(console.log) // read the latest log file
nodeLogger.read('2023-07-24').then(console.log) // read a specific log file by date
nodeLogger.read([new Date('2023-01-01'), new Date()]).then(console.log) // read all logs between two datesDocumentation
Tests
In order to run the test suite, simply clone the repository and install its dependencies:
git clone https://gitlab.com/frenware/core/basd/logger.git
cd basd
npm installTo run the tests:
npm testContributing
Thank you! Please see our contributing guidelines for details.
Donations
If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!
Bitcoin (BTC):
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdFMonero (XMR):
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQLicense
Logger is MIT licensed.