Created
July 13, 2019 09:35
-
-
Save maxmckenzie/ea4b37760e2a97730ff19414b8deaf10 to your computer and use it in GitHub Desktop.
logger example with sentry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-console */ | |
import raven from 'raven'; | |
/* | |
To Use | |
import logger from './logger'; | |
logger.error('test error'); | |
logger.debug('test debug'); | |
logger.warning('test warning'); | |
logger.fatal('test fatal'); | |
> This example uses global environment configurations | |
*/ | |
// set up raven client | |
const client = new raven.Client(process.env.DSM); | |
// patch global node errors | |
client.patchGlobal(); | |
// fire an event when a call is successfully made | |
client.on('logged', () => { | |
console.log(`Successfully logged to: ${client.dsn.host}`); | |
}); | |
// fire an event when a call fails to be made | |
client.on('error', (e) => { | |
console.log(`Failed to log to: ${client.dsn.host} | |
reason: ${e.reason} | |
statusCode: ${e.statusCode} | |
responce: ${e.response} | |
`); | |
}); | |
// Set tags such as env (development/production) | |
client.setTagsContext({ | |
environment: process.env.NODE_ENV, | |
}); | |
// Hook all event level types and expose them as a node module export pattern | |
exports.info = (data) => { | |
client.captureMessage(data, { | |
level: 'info', | |
}); | |
console.log(data); | |
}; | |
exports.error = (data) => { | |
client.captureException(data, { | |
level: 'error', | |
}); | |
console.log(data); | |
}; | |
exports.warning = (data) => { | |
client.captureMessage(data, { | |
level: 'warning', | |
}); | |
console.log(data); | |
}; | |
exports.debug = (data) => { | |
client.captureMessage(data, { | |
level: 'debug', | |
}); | |
console.log(data); | |
}; | |
exports.fatal = (data) => { | |
client.captureMessage(data, { | |
level: 'fatal', | |
}); | |
console.log(data); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment