-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add wrapLogger API method for wrapping 3rd party loggers (#1054)
- Loading branch information
1 parent
ec5f2f8
commit 3713d73
Showing
7 changed files
with
209 additions
and
49 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
/** | ||
* @file Wraps native timeout and interval methods for instrumentation. | ||
* This module is used by: jserrors, spa. | ||
*/ | ||
|
||
import { ee as baseEE } from '../event-emitter/contextual-ee' | ||
import { createWrapperWithEmitter as wfn } from './wrap-function' | ||
|
||
/** | ||
* Wraps a supplied function and adds emitter events under the `-wrap-logger-` prefix | ||
* @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based. | ||
* @param {Object} parent - The parent object housing the logger function | ||
* @param {string} loggerFn - The name of the function in the parent object to wrap | ||
* @returns {Object} Scoped event emitter with a debug ID of `logger`. | ||
*/ | ||
// eslint-disable-next-line | ||
export function wrapLogger(sharedEE, parent, loggerFn) { | ||
const ee = scopedEE(sharedEE) | ||
var wrapFn = wfn(ee) | ||
|
||
wrapFn.inPlace(parent, [loggerFn], `${loggerFn}-wrap-logger-`) | ||
return ee | ||
} | ||
|
||
/** | ||
* Returns an event emitter scoped specifically for the `logger` context. This scoping is a remnant from when all the | ||
* features shared the same group in the event, to isolate events between features. It will likely be revisited. | ||
* @param {Object} sharedEE - Optional event emitter on which to base the scoped emitter. | ||
* Uses `ee` on the global scope if undefined). | ||
* @returns {Object} Scoped event emitter with a debug ID of 'logger'. | ||
*/ | ||
export function scopedEE (sharedEE) { | ||
return (sharedEE || baseEE).get('logger') | ||
} |
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
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
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
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
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
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