️ 一个为浏览器提供的多彩记录器
️ A colorful logger for the browser
Demo - https://sidhantpanda.github.io/logt/dist/
$ npm i logt -SYou can use this logger for your frontend projects. You can choose as an ES6 module or directly include the script in HTML.
Create a file in your project called logger.js or logger.ts
import LogT from 'logt';
const LOG_TAG = 'sample tag';
let logger;
if (process.env.NODE_ENV === 'production') {
logger = new LogT('error'); // or logger = new LogT("none");
} else {
logger = new LogT('silly');
}
// See documentation for `readConsole()` for usage
// uncomment following line if you want to override default console methods
// logger.readConsole();
logger.error(LOG_TAG, new Error('example error'));
export default logger;…If any other value is supplied to the constructor, a default value of none is used.
error(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The error log message...rest - Any additional arguments to be passed onto console.errorwarn(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The warning log message...rest - Any additional arguments to be passed onto console.warninfo(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The info log message...rest - Any additional arguments to be passed onto console.infoverbose(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The verbose log message...rest - Any additional arguments to be passed onto console.logdebug(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The debug log message...rest - Any additional arguments to be passed onto console.logsilly(logTag: string, message: any, ...rest: any[])logTag - A log tag to identify the message and point to source of the message.message - The silly log message...rest - Any additional arguments to be passed onto console.loggetLogLevel(): numberReturns the logger instance's log level in numeric form;
setLogLevel(logLevel: string | number)Update a logger instance's logLevel dynamically later.
logLevel - New logLevel for the instance. Values: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 'none' | 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly'showHidden(logLevel: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 'none' | 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly')Show log messages hidden by the logger. Only logs equal or above logLevel will be shown.
logLevel - Log level for which logs are to be shownconst logger = new LogT(0);
logger.warn('TAG', 'warning message'); // Will not print anything to console
logger.info('TAG', 'info message'); // Will not print anything to console
logger.debug('TAG', 'debug message'); // Will not print anything to console
logger.silly('TAG', 'silly message'); // Will not print anything to console
logger.showHidden(1); // Will print the warning message
logger.showHidden(2); // Will print the info message
logger.showHidden(5); // Will print the debug as well as silly messagereadConsole()Replace default console.error, console.warn, console.info, console.log implementation with logt logger.
const logger = new LogT(0);
logger.readConsole();
console.error(new Error('test error')); // will be same as logger.error('console', new Error('test error'));
console.warn('warn message'); // will be same as logger.warn('console', 'warn message');
console.log('info message'); // will be same as logger.info('console', 'info message');
console.log('log message'); // will be same as logger.debug('console', 'log message');image() method. Will be removed in next major release. Logging images is no longer supported by Chromme.image() methodCheckout the project page for details about future development.
暂无开放 Issues,或尚未同步最近议题。