gcloud-logger
v0.1.21
Published
simple logger for gcp
Downloads
40
Maintainers
Readme
gcloud-logger
A simple lightweight logger for GCP Stackdriver.
Contents
Usage requirements
Requires Node version 10 or higher.
To use Stackdriver logging your application must have access to the GCP project and permission to write logs.
Installation
npm install gcloud-logger
Quick start
To initialize the logger pass the options object to the method createLogger
.
Configuration is simple and consists of next params:
console
- writing logs to stdoutstackdriver
- sending logs to Stackdriver
You can omit any of these properties or set the value to falsy if it's not needed.
const gcloudLogger = require('gcloud-logger');
const logger = gcloudLogger.createLogger({
console: true,
stackdriver: { projectId: 'gcloud-project-ID', logName: 'log-name' },
});
logger.debug('Debug');
logger.error(new Error('Something went wrong'));
Levels
Available logging levels (RFC 5424) and corresponding Stackdriver severity:
logger.debug('Debug');
logger.info('Info');
logger.notice('Info');
logger.warning('Warning');
logger.error('Error');
logger.crit('Fatal');
logger.alert('Fatal');
logger.emerg('Fatal');
uncaughtException and unhandledRejection handlers
You can add the following properties to your options object to log uncaughtException
and unhandledRejection
errors:
const gcloudLogger = require('gcloud-logger');
const logger = gcloudLogger.createLogger({
console: true,
logExceptionLevel: 'alert',
logRejectionLevel: 'crit',
});
Note: the logger will exit with process.exit(1)
after logging uncaughtException
or unhandledRejection
.