@jameslnewell/logger
v3.0.1
Published
A logging library.
Downloads
55
Readme
@jameslnewell/logger
A logging library.
Installation
yarn add @jameslnewell/logger
Usage
Using a logger
import logger from '@jameslnewell/logger';
logger.info('Server is listening on http://localhost:3000');
Using an extended logger
import logger from '@jameslnewell/logger';
const log = logger.extend('my-server');
log.info('Server is listening on http://localhost:3000');
Adding the time to the logs
import logger, {time} from '@jameslnewell/logger';
logger.use(time());
Adding the version to the logs
import logger, {version} from '@jameslnewell/logger';
logger.use(version());
Adding a custom field to the logs
import logger from '@jameslnewell/logger';
logger.use(log => ({...log, foo: 'bar'}));
Filtering the logs
import logger, {Level, filter} from '@jameslnewell/logger';
logger.use(filter(log => log.level === Level.error));
Writing logs to the console
import logger, {ConsoleOutputStream} from '@jameslnewell/logger';
logger.pipe(new ConsoleOutputStream());
Writing logs to a file
import logger, {FileOutputStream} from '@jameslnewell/logger';
logger.pipe(new FileOutputStream());
Writing logs to a file on error
import logger, {MemoryOutputStream} from '@jameslnewell/logger';
const logs = logger.pipe(new MemoryOutputStream());
try {
// do stuff here
} catch (error) {
logger.error(error);
fs.WritingFileSync('app.log', logs);
}
Writing logs to CloudWatch
import logger, {CloudwatchOutputStream} from '@jameslnewell/logger';
logger.pipe(new CloudwatchOutputStream({
group: 'my-group',
stream: 'my-stream',
}));