@logshq.io/node
v1.1.11
Published
Official LogsHQ.io logger for Node.js
Downloads
12
Maintainers
Readme
Official LogsHQ.io logger for Node.js
The official LogsHQ.io notifier for capturing Nodejs errors in Node.js and reporting them to LogsHQ.
Installation
Using npm:
npm install @logshq.io/node --save
Using yarn:
yarn add @logshq.io/node
Usage
Create a Stream and get your Stream API KEY, and use it like this:
// myLogger.js
const LogshqLogger = require('@logshq.io/node');
const logger = new LogshqLogger({
project_id: 'SOME-PROJECT-ID',
api_key: 'SOME-STREAM-KEY',
environment: 'production', // optional
hostname: 'auth-service', // optional
});
module.exports = logger
Examples
// auth.js
const { correlationId } = require('SomeModule')
const logger = require('./myLogger')
function signUp (user) {
try {
await authService.create(user);
logger.debug('Signup success sending email now', {
step: 'Step 1',
next: 'Preparing Email',
method: 'signUp',
module: 'auth.js',
correlationId
});
// Send Welcome Email
logger.debug('Email sent', {
step: 'Step 2',
next: 'Returning OK',
method: 'signUp',
module: 'auth.js',
correlationId
});
// Return something
logger.info('Signup success', {
step: 'Step 3',
method: 'signUp',
module: 'auth.js',
correlationId
});
} catch (error) {
logger.error('Signup failed', error, {
method: 'signUp',
module: 'auth.js',
correlationId
});
}
}