mini-logger a debug based logger with preset colors, running on both browsers and Node.
npm install @gloxy/mini-logger
or
yarn add @gloxy/mini-logger
or
pnpm add @gloxy/mini-logger
For all logger methods, the first parameter is a title for it. The second paramter is a formatter, and the rest are any strings one by one for the formatter.
Activate logger
- Browser: localStorage.debug = 'myapp:*'
- Node: add the env variable DEBUG = myapp:*
Deactivate by remove them respectively.
// Create the logger instance in the very beginning of your app.
// The namespace is for the logs being distingushiable from other prints, i.e. myapp
const logger = createLogger('myapp');
// Print info
logger('play ball', 'ball player: %s', 'Mary');
logger.info('play ball', 'ball player: %s', 'Mary');
// Print warn
logger.warn('play ball', 'ball player: %s', 'Mary');
// Print success
logger.success('play ball', 'ball player: %s', 'Mary');
// Print error
logger.error('play ball', 'ball player: %s', 'Mary');
// Print debug
logger.debug('play ball', 'ball player: %s', 'Mary');
👤 GloryWong
- Website: https://zhaozhao.today
- GitHub: @GloryWong
Give a ⭐️ if this project helped you!