- Installation
- Usage
- examples (To get you going)
- LoggerConfig (Customization for the entire logger)
- MethodConfig (Customization on a per-method basis)
- Shimming console.log
Using npm
:
npm install @lvksh/logger
or if you prefer to use the yarn
package manager:
yarn add @lvksh/logger
Get started by creating your logger
import { createLogger } from '@lvksh/logger';
import chalk from 'chalk';
const log = createLogger(
{
ok: {
label: chalk.greenBright`[OK]`,
newLine: '| ',
newLineEnd: '\\-',
},
debug: chalk.magentaBright`[DEBUG]`,
info: {
label: chalk.cyan`[INFO]`,
newLine: chalk.cyan`⮡`,
newLineEnd: chalk.cyan`⮡`,
},
veryBigNetworkError: chalk.bgRed.white.bold`[NETWORK]`,
},
{ padding: 'PREPEND' },
console.log
);
And now log to your hearts content
log.ok('This is the best logging', 'library', 'you');
log.info('will probably');
log.debug('ever use');
log.veryBigNetworkError`Never Gonna Give You Up!`;
log.debug('in', 'your', 'life', "you're", 'welcome');
log.info('item 1', 'item 2', 'item 3', 'item 4', 'item 5');
Which produces the following result
Other Themes:
This section is still work in progress.
This section is still work in progress.
Do you still type console.log
out of habit? Not a problem, simply run shimLog
with your logger, and your log function of choice and voila.
Now every stray console.log
will be on steroids from now on!
import { createLogger, shimLog } from '@lvksh/logger';
import chalk from 'chalk';
const log = createLogger({
debug: chalk.magentaBright`[DEBUG]`,
});
// Replaces `console.log` with `log.debug` !
shimLog(log, 'debug');
import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger } from '@lvksh/logger/lib/file-log';
const log = createLogger(
{
OK: 'OK',
INFO: 'INFO',
},
{ divider: ' | ' },
FileLogger({
mode: 'NEW_FILE',
path: join(__dirname, 'logs'),
namePattern: 'test.txt',
})
);
log.OK('Hello World');
import { join } from 'path';
import { createLogger } from '@lvksh/logger';
import { FileLogger, FileLoggerConfig } from '@lvksh/logger/lib/file-log';
const fileConfig: FileLoggerConfig = {
mode: 'NEW_FILE',
path: join(__dirname, '../logs'),
namePattern: 'test.txt'
}
const methodConfig = {
OK: 'OK',
INFO: 'INFO'
}
const log = createLogger(
methodConfig,
{ divider: ' | ' },
[FileLogger(fileConfig), console.log]
);
export default log;
log.OK('Hello World');
This package is licensed under the GNU Lesser General Public License.
Regex matching within this package is sourced from ansi-regex, which is licensed under the MIT license.