Skip to content

Commit

Permalink
feat: add custom attributes to logInfo (openedx#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Butterworth authored Jul 19, 2019
1 parent 43fea04 commit b4b2340
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/NewRelicLoggingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ function fixErrorLength(error) {

class NewRelicLoggingService {
static logInfo(message, customAttributes = {}) {
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development') {
console.log(message); // eslint-disable-line
console.log(message, customAttributes); // eslint-disable-line
}
/* istanbul ignore else */
if (window && typeof window.newrelic !== 'undefined') {
window.newrelic.addPageAction('INFO', Object.assign({}, { message }, customAttributes));
}
}

static logError(error, customAttributes) {
/* istanbul ignore next */
if (process.env.NODE_ENV === 'development') {
console.error(error, customAttributes); // eslint-disable-line
}
/* istanbul ignore else */
if (window && typeof window.newrelic !== 'undefined') {
// Note: customProperties are not sent. Presumably High-Security Mode is being used.
window.newrelic.noticeError(fixErrorLength(error), customAttributes);
Expand Down
4 changes: 2 additions & 2 deletions src/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function getLoggingService() {
return loggingService;
}

function logInfo(message) {
return getLoggingService().logInfo(message);
function logInfo(message, customAttributes) {
return getLoggingService().logInfo(message, customAttributes);
}

function logError(error, customAttributes) {
Expand Down
4 changes: 2 additions & 2 deletions src/logging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('configured logging service', () => {
const mockStatic = jest.fn();
NewRelicLoggingService.logInfo = mockStatic.bind(NewRelicLoggingService);

logInfo(arg1);
expect(mockStatic).toHaveBeenCalledWith(arg1);
logInfo(arg1, arg2);
expect(mockStatic).toHaveBeenCalledWith(arg1, arg2);
});
});

Expand Down

0 comments on commit b4b2340

Please sign in to comment.