@surajs02/logdash v1.0.10
logdash
Simple and customizable log functions that can integrate with lodash.
Features
- 5 pre-defined log functions:
logn: Prints uncolored[NONE]tag viaconsole.loglogi: Prints blue[INFO]tag viaconsole.infologs: Prints green[SUCCESS]tag viaconsole.loglogw: Prints orange[WARN]tag viaconsole.warnloge: Prints red[ERROR]tag viaconsole.error
- Add and customize logs by color, console, tag, and more
- Use log functions directly or easily integrate for lodash chain logging
- Toggle log functions on/off
- Helper functions for easily mapping over and customizing log type objects
Install
npm install @surajs02/logdashBasic Usage
All log functions can be used directly (i.e., without lodash integration)
import { loadLogdash } from '@surajs02/logdash'; // TypeScript
// const { loadLogdash } = require('logdash'); // JavaScript.
const { logn, logi, logs, logw, loge } = loadLogdash().logFuncs;
logn('A standard log');
logi('This might be useful');
logs('That went well');
logw('There may be a problem...');
loge('There was an error');The above logs would be styled and displayed with a colored tag:

All log functions support multiple arguments:
logn('String1', 1, true, [1], { a: 1 }, null, undefined);Integrating with lodash
Pass a lodash instance as a lodashForMixin option to make log functions available via lodash:
const _ = require('lodash');
loadLogdash({ lodashForMixin: _, });
_.logn('Logging directly via logdash');Log functions can be used indirectly in lodash chains:
const doubled = _.chain([1, 2, 3])
.logi() // Prints [1, 2, 3].
.map(n => n * 2)
.logi() // Prints [2, 4, 8].
.value();
_.logi(doubled.length); // Prints 3.Customization
All log functions are enabled by default but can be disabled via the disableAllLogs option:
const { logi } = loadLogdash({ disableAllLogs: true, }).logFuncs;
_.logi("This won't be printed");Log types are customized via the customizeLogTypes option, which is a function that
accepts a ILogTypeMap to return a new ILogTypeMap:
interface ILogTypeMap {
[key: string]: ILogType;
}ILogTypeMap maps log type names to ILogType values:
interface ILogType {
color?: Function;
consoleType?: Function;
tag?: String;
func?: ILogFunc;
enabled?: boolean;
}New log types can be added and accessed via log<initial-letter-of-log-type>:
const { loga } = loadLogdash({
customizeLogTypes: (logTypes: ILogTypeMap) => ({
...logTypes,
added: { color: chalk.cyan }, // `added` will become `loga`.
}),
}).logFuncs;
loga('This will print in cyan!');Existing log types can be customized easily via the mapObjValues helper:
import { loadLogdash, mapObjValues, ILogType } from '@surajs02/logdash';
const { logi } = loadLogdash({
customizeLogTypes: (logTypes: ILogTypeMap) => mapObjValues(
logTypes, (t: ILogType) => ({...logTypes, color: chalk.magenta }),
}),
}).logFuncs;
logi('This and other log functions will now print in magenta!');Testing
Setup
git clone https://github.com/surajs02/logdash.git && cd logdash && npm installRun all tests
npm run testTest only log functions
npm run testLogFuncsTest only logdash options (e.g., lodash integration)
npm run testOptions