Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(diag-logger): introduce a new global level api.diag for internal diagnostic logging #1880

Merged
merged 6 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: correct the usage of default logger for level and update test
- fix issue where the global diag level affected trailing tests
  • Loading branch information
MSNev committed Feb 9, 2021
commit fc00e10f40da1766f6a21e9d0832a8ec4b603095
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/src/diag/logLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function createLogLevelDiagLogger(
}

if (!logger) {
logger = DiagAPI.instance().getLogger();
logger = DiagAPI.instance();
}

function _filterFunc(
Expand Down
58 changes: 44 additions & 14 deletions packages/opentelemetry-api/test/diag/logLevel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('LogLevelFilter DiagLogger', () => {
beforeEach(() => {
// set no logger
diag.setLogger(null as any);
diag.setLogLevel(DiagLogLevel.INFO);

// mock
dummyLogger = {} as DiagLogger;
Expand Down Expand Up @@ -213,6 +214,7 @@ describe('LogLevelFilter DiagLogger', () => {

it(`should use default logger for undefined and log ${fName} message with ${map.message} level`, () => {
diag.setLogger(dummyLogger);
diag.setLogLevel(DiagLogLevel.ALL);
const testLogger = createLogLevelDiagLogger(map.level, undefined);
testLogger[fName](`${fName} called %s`, 'param1');
diagLoggerFunctions.forEach(lName => {
Expand All @@ -229,6 +231,7 @@ describe('LogLevelFilter DiagLogger', () => {

it(`should use default logger for null and log ${fName} message with ${map.message} level`, () => {
diag.setLogger(dummyLogger);
diag.setLogLevel(DiagLogLevel.ALL);
const testLogger = createLogLevelDiagLogger(map.level, null);
testLogger[fName](`${fName} called %s`, 'param1');
diagLoggerFunctions.forEach(lName => {
Expand Down Expand Up @@ -260,21 +263,48 @@ describe('LogLevelFilter DiagLogger', () => {
});
});

it(`diag setLogLevel is ignored for specific logLevel logger and should log ${fName} message with ${map.message} level`, () => {
diag.setLogger(dummyLogger);
diag.setLogLevel(DiagLogLevel.NONE);
levelMap.forEach(masterLevelMap => {
it(`diag setLogLevel is not ignored when set to ${masterLevelMap.message} and using default logger to log ${fName} message with ${map.message} level`, () => {
diag.setLogger(dummyLogger);
diag.setLogLevel(masterLevelMap.level);

const testLogger = createLogLevelDiagLogger(map.level);
testLogger[fName](`${fName} called %s`, 'param1');
diagLoggerFunctions.forEach(lName => {
if (fName === lName && map.ignoreFuncs.indexOf(lName) === -1) {
assert.deepStrictEqual(calledArgs[lName], [
`${fName} called %s`,
'param1',
]);
} else {
assert.strictEqual(calledArgs[lName], null);
}
const testLogger = createLogLevelDiagLogger(map.level);
testLogger[fName](`${fName} called %s`, 'param1');
diagLoggerFunctions.forEach(lName => {
if (
fName === lName &&
map.ignoreFuncs.indexOf(lName) === -1 &&
masterLevelMap.ignoreFuncs.indexOf(lName) === -1
) {
assert.deepStrictEqual(calledArgs[lName], [
`${fName} called %s`,
'param1',
]);
} else {
assert.strictEqual(calledArgs[lName], null);
}
});
});

it(`diag setLogLevel is ignored when set to ${masterLevelMap.message} when using a specific logger to log ${fName} message with ${map.message} level`, () => {
diag.setLogger(dummyLogger);
diag.setLogLevel(masterLevelMap.level);

const testLogger = createLogLevelDiagLogger(
map.level,
diag.getLogger()
);
testLogger[fName](`${fName} called %s`, 'param1');
diagLoggerFunctions.forEach(lName => {
if (fName === lName && map.ignoreFuncs.indexOf(lName) === -1) {
assert.deepStrictEqual(calledArgs[lName], [
`${fName} called %s`,
'param1',
]);
} else {
assert.strictEqual(calledArgs[lName], null);
}
});
});
});

Expand Down