Simple Wei Xin mini program log library
First, import the MLog
class from the mlog.js
file:
const { MLog } = require('./mlog');
Create an instance of MLog with an optional module name:
const logger = new MLog('MyModule');
Set the log level to control the verbosity of the logs. Available levels are TRACE, DEBUG, INFO, WARN, and ERROR:
logger.setLevel('DEBUG');
Use the following methods to log messages at different levels:
trace: For detailed trace information. debug: For debugging information. info: For informational messages. warn: For warnings. error: For error messages.
Here is a complete example:
const { MLog } = require('./mlog');
const logger = new MLog('MyModule');
logger.setLevel('DEBUG');
logger.trace('This is a trace message');
logger.debug('This is a debug message');
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');