npm.io
4.0.2 • Published 1 month ago

@prairielearn/logger

Licence
—
Version
4.0.2
Deps
2
Size
56 kB
Vulns
0
Weekly
0
Stars
533

@prairielearn/logger

Provides a shared Pino logger with human-readable console output and JSON file output.

Usage

import { logger, addFileLogging, reopenFileLogging } from '@prairielearn/logger';

// Log all messages to a file.
addFileLogging({ filename: '/path/to/file.log' });

// Log all errors to another file.
addFileLogging({ filename: '/path/to/errors.log', level: 'error' });

// Reopen configured log files after an external tool rotates them.
process.on('SIGHUP', reopenFileLogging);

logger.debug('debug');
logger.verbose('verbose');
logger.info('info');
logger.warn('warn');

try {
  await mightError();
} catch (err) {
  logger.error('An error occurred', err);
}