Closed benmgreene closed 10 years ago
I personally do it in a generic logger file in a lib directory, so it gets executed once on startup for server side logging, and every time in the client for browser logging. The raven credentials in settings.json and only the public dsn is sent to the browser. Here's a snippet for you.
/**
* Logger
*
* System wide logger for errors and debug messages.
* Errors are logged to console & sent to Sentry.
*/
/* global RavenLogger */
(function(App) {
'use strict';
/**
* Setup Raven integration on server/browser start.
*/
if (Meteor.isClient
&& typeof Meteor.settings.public.sentry !== 'undefined'
&& typeof Meteor.settings.public.sentry.dsn !== 'undefined'
) {
RavenLogger.initialize({
client: Meteor.settings.public.sentry.dsn
}, {
trackUser: true
});
}
if (Meteor.isServer && typeof Meteor.settings.sentry !== 'undefined') {
RavenLogger.initialize({
server: Meteor.settings.sentry.dsn
});
}
/**
* Log an error message.
*
* @param String|Error message Message to log
* @param Object tags Optionally add a tag name & value eg: { component: 'charts' }
*/
function error(message, tags) {
tags = tags === undefined ? '' : tags;
if (message instanceof Error)
console.log(message.message + '\n', message.stack, tags);
else
console.log(message, tags);
try {
RavenLogger.log(message, tags);
} catch (e) {
console.log('Raven failed to log a message: ' + e.message);
}
}
...
I'm finding the documentation a little unclear as to where this initialization belongs. I read the previous thread on initialization, and tried okgrow's solution, but to no avail.