-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create platform specific implementations to get log level
Signed-off-by: Naseem <[email protected]>
- Loading branch information
Naseem
committed
May 17, 2020
1 parent
4d450e9
commit c4516f7
Showing
9 changed files
with
134 additions
and
24 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
24 changes: 24 additions & 0 deletions
24
packages/opentelemetry-core/src/platform/browser/log-level.ts
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,24 @@ | ||
/** | ||
* Copyright 2020, 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. | ||
*/ | ||
|
||
/** | ||
* @returns the default log level for opentelemetry. | ||
*/ | ||
import { LogLevel } from '../../common/types'; | ||
|
||
export function getLogLevel(): LogLevel { | ||
return LogLevel.INFO; | ||
} |
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
26 changes: 26 additions & 0 deletions
26
packages/opentelemetry-core/src/platform/node/log-level.ts
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,26 @@ | ||
/** | ||
* Copyright 2020, 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. | ||
*/ | ||
|
||
/** | ||
* Returns an environmentally set log level if set. | ||
* Defaults to INFO. | ||
* @returns the log level for opentelemetry. | ||
*/ | ||
import { LogLevel, LogLevelString } from '../../common/types'; | ||
|
||
export function getLogLevel(): LogLevel { | ||
return LogLevel[(process.env.OTEL_LOG_LEVEL as LogLevelString) ?? 'INFO']; | ||
} |
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
73 changes: 73 additions & 0 deletions
73
packages/opentelemetry-core/test/platform/log-level.test.ts
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,73 @@ | ||
/*! | ||
* Copyright 2019, 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 * as assert from 'assert'; | ||
import { ConsoleLogger } from '../../src/common/ConsoleLogger'; | ||
|
||
describe('Log level', () => { | ||
const origDebug = console.debug; | ||
const origInfo = console.info; | ||
const origWarn = console.warn; | ||
const origError = console.error; | ||
let debugCalledArgs: unknown; | ||
let infoCalledArgs: unknown; | ||
let warnCalledArgs: unknown; | ||
let errorCalledArgs: unknown; | ||
|
||
beforeEach(() => { | ||
// mock | ||
console.debug = (...args: unknown[]) => { | ||
debugCalledArgs = args; | ||
}; | ||
console.info = (...args: unknown[]) => { | ||
infoCalledArgs = args; | ||
}; | ||
console.warn = (...args: unknown[]) => { | ||
warnCalledArgs = args; | ||
}; | ||
console.error = (...args: unknown[]) => { | ||
errorCalledArgs = args; | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
// restore | ||
debugCalledArgs = null; | ||
infoCalledArgs = null; | ||
warnCalledArgs = null; | ||
errorCalledArgs = null; | ||
console.debug = origDebug; | ||
console.info = origInfo; | ||
console.warn = origWarn; | ||
console.error = origError; | ||
if (typeof process !== 'undefined' && process.release.name === 'node') | ||
delete process.env.OTEL_LOG_LEVEL; | ||
}); | ||
|
||
if (typeof process !== 'undefined' && process.release.name === 'node') | ||
it('should log with environmentally set level in Node', () => { | ||
process.env.OTEL_LOG_LEVEL = 'WARN'; | ||
const consoleLogger = new ConsoleLogger(); | ||
consoleLogger.error('error called'); | ||
assert.deepStrictEqual(errorCalledArgs, ['error called']); | ||
consoleLogger.warn('warn called %s', 'param1'); | ||
assert.deepStrictEqual(warnCalledArgs, ['warn called %s', 'param1']); | ||
consoleLogger.info('info called %s', 'param1'); | ||
assert.deepStrictEqual(infoCalledArgs, undefined); | ||
consoleLogger.debug('debug called %s', 'param1'); | ||
assert.deepStrictEqual(debugCalledArgs, undefined); | ||
}); | ||
}); |
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