This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reduce diag API surface exposed to user
- Loading branch information
Showing
12 changed files
with
223 additions
and
279 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export * from './consoleLogger'; | ||
export * from './types'; |
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,62 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { DiagLogFunction, DiagLogger, DiagLogLevel } from '../types'; | ||
import { createNoopDiagLogger } from './noopLogger'; | ||
|
||
export function createLogLevelDiagLogger( | ||
maxLevel: DiagLogLevel, | ||
logger: DiagLogger | ||
): DiagLogger { | ||
if (maxLevel < DiagLogLevel.NONE) { | ||
maxLevel = DiagLogLevel.NONE; | ||
} else if (maxLevel > DiagLogLevel.ALL) { | ||
maxLevel = DiagLogLevel.ALL; | ||
} | ||
|
||
if (!logger) { | ||
// this shouldn't happen, but return a noop logger to not break the user | ||
return createNoopDiagLogger(); | ||
} | ||
|
||
function _filterFunc( | ||
theLogger: DiagLogger, | ||
funcName: keyof DiagLogger, | ||
theLevel: DiagLogLevel | ||
): DiagLogFunction { | ||
if (maxLevel >= theLevel) { | ||
return function () { | ||
const orgArguments = arguments as unknown; | ||
const theFunc = theLogger[funcName]; | ||
if (theFunc && typeof theFunc === 'function') { | ||
return theFunc.apply( | ||
logger, | ||
orgArguments as Parameters<DiagLogFunction> | ||
); | ||
} | ||
}; | ||
} | ||
return function () {}; | ||
} | ||
|
||
return { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
error: _filterFunc(logger, 'error', DiagLogLevel.ERROR), | ||
warn: _filterFunc(logger, 'warn', DiagLogLevel.WARN), | ||
info: _filterFunc(logger, 'info', DiagLogLevel.INFO), | ||
debug: _filterFunc(logger, 'debug', DiagLogLevel.DEBUG), | ||
verbose: _filterFunc(logger, 'verbose', DiagLogLevel.VERBOSE), | ||
}; | ||
} |
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,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { DiagLogger } from '../types'; | ||
|
||
function noopLogFunction() {} | ||
|
||
/** | ||
* Returns a No-Op Diagnostic logger where all messages do nothing. | ||
* @implements {@link DiagLogger} | ||
* @returns {DiagLogger} | ||
*/ | ||
export function createNoopDiagLogger(): DiagLogger { | ||
return { | ||
verbose: noopLogFunction, | ||
debug: noopLogFunction, | ||
info: noopLogFunction, | ||
warn: noopLogFunction, | ||
error: noopLogFunction, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Ok, I know I said id mention that "m" word less, buuuutttt...
Does this result in smaller output? Looks like it might be close -- enough?
As this definitely looks easier to read. And while I can think of a few additional tricks, I'm not sure its worth it, basically
diagLoggerFunctions
but don't export from main project (effectively keeping internal)diag.ts
, here (which some funcky toUpper() for the level lookup) and in the noopLoger.ts.