Very simple and cool logger for your Node.js projects. Supports JavaScript and TypeScript.
Feature |
---|
âś… Fully customizable |
âś… Basic logging |
âś… Chalk support |
âś… RGB, ANSI, Decimal, Hexadecimal support |
âś… JavaScript & TypeScript support |
âś… Advanced logging |
âś… Log level support |
âś… Custom colors |
âś… Custom loggers |
âś… Randomized logging |
âś… Rainbow logging |
âś… Config file support |
âś… Built-in colors |
âś… Custom logger logic support |
âś… Log file support |
âś… Log event support |
npm install @tolga1452/logchu
const { logger, ColorPreset, fromChalk, LogType } = require('@tolga1452/logchu');
// Basic usage
logger.info('Hello, world!');
logger.success('Hello, world!');
logger.warning('Hello, world!');
logger.error('Hello, world!');
logger.debug('Hello, world!');
// With styles and color presets
logger.info('Hello, world!', { bold: true });
logger.custom('Hello, world!', { color: ColorPreset.Magenta, italic: true, type: LogType.Debug });
logger.custom('Hello, world!', ColorPreset.Cyan);
// With chalk
const chalk = require('chalk');
logger.custom('Hello, world!', fromChalk(chalk.dim.red(' '))); // You have to use a single space character as text for chalk
const { logger } = require('@tolga1452/logchu');
logger.random('Hello, world!', { bold: true }); // Log with random color
logger.fullRandom('Hello, world!', { inverse: true }); // Fully random log with overwrites
const { write, ColorPreset } = require('@tolga1452/logchu');
write(
{
color: ColorPreset.LightGray,
italic: true
},
{
text: 'First one was default config ',
color: ColorPreset.LightGreen
},
{
text: 'this is ',
useDefault: true
},
{
text: 'awesome!',
color: ColorPreset.LightCyan,
bold: true
}
);
const { CustomLogger } = require('@tolga1452/logchu');
const myCustomLogger = new CustomLogger({
_logic: log => {
console.log('Put your custom logic here.');
console.log('This will be runned along with the default logic.');
},
info: { color: ColorPreset.BackgroundBlue, italic: true }
}, true); // true for overwrite default logic
Supports Hexadecimal, RGB, decimal and ANSI colors.
const { logger } = require('@tolga1452/logchu');
logger.custom('Hello, world!', { color: '#f44747' });
- Create a file named
logchu.config.js
in your project root. - Add the following code to the file:
module.exports = {
customColorPresets: {
myCustomColor: '#639dff'
}
};
- Use it in your code:
const { logger, userColor } = require('@tolga1452/logchu');
logger.custom('Hello, world!', userColor('myCustomColor'));
const { CustomLogger, ColorPreset } = require('@tolga1452/logchu');
const myCustomLogger = new CustomLogger({
info: { color: ColorPreset.BackgroundBlue, italic: true },
success: { color: ColorPreset.LightGreen, bold: true },
trolley: { color: '#9b4eea', bold: true }
});
myCustomLogger.info('Hello, world!');
myCustomLogger.success('Hello, world!', { bold: false });
myCustomLogger.trolley('Hello, world!', ColorPreset.BackgroundRed);
- Create a file named
logchu.config.js
in your project root. - Add the following code to the file:
const { ColorPreset } = require('@tolga1452/logchu');
module.exports = {
customLoggers: {
myCustomLogger: {
info: { color: ColorPreset.BackgroundBlue, italic: true },
success: { color: '#80b918', bold: true },
trolley: { color: '$custom:myCustomColor', bold: true }
}
},
customColorPresets: {
myCustomColor: '#e84118'
}
};
- Use it in your code:
const { useLogger } = require('@tolga1452/logchu');
const myCustomLogger = useLogger('myCustomLogger');
myCustomLogger.info('Hello, world!');
- Create a file named
logchu.config.js
in your project root. - Add the following code to the file:
module.exports = {
logFile: './logs.txt'
};
- Create a file named
logchu.config.js
in your project root. - Add the following code to the file:
const { Watcher } = require('@tolga1452/logchu');
module.exports = {
watcher: new Watcher()
};
- Use it in your code:
const { logger, LogEvent } = require('@tolga1452/logchu');
const { watcher } = require('./logchu.config');
watcher.on(LogEvent.Info, log => {
console.log('Info log event triggered:', log);
});
logger.info('Hello, world!');