diff --git a/packages/opentelemetry-api/src/api/diag.ts b/packages/opentelemetry-api/src/api/diag.ts index d55a5caba56..f9914b3f066 100644 --- a/packages/opentelemetry-api/src/api/diag.ts +++ b/packages/opentelemetry-api/src/api/diag.ts @@ -146,9 +146,8 @@ export class DiagAPI implements DiagLogger { public debug!: DiagLogFunction; public info!: DiagLogFunction; public warn!: DiagLogFunction; + public startupInfo!: DiagLogFunction; public error!: DiagLogFunction; public critical!: DiagLogFunction; public terminal!: DiagLogFunction; - - public forcedInfo!: DiagLogFunction; } diff --git a/packages/opentelemetry-api/src/diag/consoleLogger.ts b/packages/opentelemetry-api/src/diag/consoleLogger.ts index e720dcf84b4..27f7cb9fbb7 100644 --- a/packages/opentelemetry-api/src/diag/consoleLogger.ts +++ b/packages/opentelemetry-api/src/diag/consoleLogger.ts @@ -24,7 +24,7 @@ const consoleMap: { n: keyof DiagLogger; c: keyof Console }[] = [ { n: 'info', c: 'info' }, { n: 'debug', c: 'debug' }, { n: 'verbose', c: 'trace' }, - { n: 'forcedInfo', c: 'info' }, + { n: 'startupInfo', c: 'info' }, ]; /** @@ -73,6 +73,13 @@ export class DiagConsoleLogger implements DiagLogger { /** Log an error scenario that was not expected and caused the requested operation to fail. */ public error!: DiagLogFunction; + /** + * Logs a general informational message that is used for logging component startup and version + * information without causing additional general informational messages when the logging level + * is set to DiagLogLevel.WARN or lower. + */ + public startupInfo!: DiagLogFunction; + /** * Log a warning scenario to inform the developer of an issues that should be investigated. * The requested operation may or may not have succeeded or completed. @@ -102,12 +109,4 @@ export class DiagConsoleLogger implements DiagLogger { * in a production environment. */ public verbose!: DiagLogFunction; - - /** - * Log a general informational message that should always be logged regardless of the - * current {@Link DiagLogLevel) and configured filtering level. This type of logging is - * useful for logging component startup and version information without causing additional - * general informational messages when the logging level is set to DiagLogLevel.WARN or lower. - */ - public forcedInfo!: DiagLogFunction; } diff --git a/packages/opentelemetry-api/src/diag/logLevel.ts b/packages/opentelemetry-api/src/diag/logLevel.ts index d85e4cef656..31241801ca8 100644 --- a/packages/opentelemetry-api/src/diag/logLevel.ts +++ b/packages/opentelemetry-api/src/diag/logLevel.ts @@ -24,38 +24,41 @@ import { DiagLogger, DiagLogFunction, createNoopDiagLogger } from './logger'; * compatibility/migration issues for any implementation that assume the numeric ordering. */ export enum DiagLogLevel { - /** DIagnostic Logging level setting to disable all logging (except and forced logs) */ - NONE = -99, + /** Diagnostic Logging level setting to disable all logging (except and forced logs) */ + NONE = 0, /** * Identifies a terminal situation that would cause the API to completely fail to initialize, * if this type of error is logged functionality of the API is not expected to be functional. */ - TERMINAL = -2, + TERMINAL = 10, /** * Identifies a critical error that needs to be addressed, functionality of the component * that emits this log detail may non-functional. */ - CRITICAL = -1, + CRITICAL = 20, /** Identifies an error scenario */ - ERROR = 0, + ERROR = 30, + + /** Identifies startup and failure (lower) scenarios */ + STARTUP = 40, /** Identifies a warning scenario */ - WARN = 1, + WARN = 50, /** General informational log message */ - INFO = 2, + INFO = 60, /** General debug log message */ - DEBUG = 3, + DEBUG = 70, /** * Detailed trace level logging should only be used for development, should only be set * in a development environment. */ - VERBOSE = 4, + VERBOSE = 80, /** Used to set the logging level to include all logging */ ALL = 9999, @@ -79,11 +82,11 @@ const fallbackLoggerFuncMap: { [n: string]: keyof Logger } = { info: 'info', debug: 'debug', verbose: 'debug', - forcedInfo: 'info', + startupInfo: 'info', }; /** Mapping from DiagLogger function name to logging level. */ -const levelMap: { n: keyof DiagLogger; l: DiagLogLevel; f?: boolean }[] = [ +const levelMap: { n: keyof DiagLogger; l: DiagLogLevel }[] = [ { n: 'terminal', l: DiagLogLevel.TERMINAL }, { n: 'critical', l: DiagLogLevel.CRITICAL }, { n: 'error', l: DiagLogLevel.ERROR }, @@ -91,7 +94,7 @@ const levelMap: { n: keyof DiagLogger; l: DiagLogLevel; f?: boolean }[] = [ { n: 'info', l: DiagLogLevel.INFO }, { n: 'debug', l: DiagLogLevel.DEBUG }, { n: 'verbose', l: DiagLogLevel.VERBOSE }, - { n: 'forcedInfo', l: DiagLogLevel.INFO, f: true }, + { n: 'startupInfo', l: DiagLogLevel.ERROR }, ]; /** @@ -130,10 +133,9 @@ export function createLogLevelDiagLogger( function _filterFunc( theLogger: DiagLogger, funcName: keyof DiagLogger, - theLevel: DiagLogLevel, - isForced?: boolean + theLevel: DiagLogLevel ): DiagLogFunction { - if (isForced || maxLevel >= theLevel) { + if (maxLevel >= theLevel) { return function () { const orgArguments = arguments as unknown; const theFunc = @@ -152,7 +154,7 @@ export function createLogLevelDiagLogger( const newLogger = {} as DiagLogger; for (let i = 0; i < levelMap.length; i++) { const name = levelMap[i].n; - newLogger[name] = _filterFunc(logger, name, levelMap[i].l, levelMap[i].f); + newLogger[name] = _filterFunc(logger, name, levelMap[i].l); } return newLogger; diff --git a/packages/opentelemetry-api/src/diag/logger.ts b/packages/opentelemetry-api/src/diag/logger.ts index 79d31317ccd..6b01ff9b1b9 100644 --- a/packages/opentelemetry-api/src/diag/logger.ts +++ b/packages/opentelemetry-api/src/diag/logger.ts @@ -53,6 +53,13 @@ export interface DiagLogger { /** Log an error scenario that was not expected and caused the requested operation to fail. */ error: DiagLogFunction; + /** + * Logs a general informational message that is used for logging component startup and version + * information without causing additional general informational messages when the logging level + * is set to DiagLogLevel.WARN or lower. + */ + startupInfo: DiagLogFunction; + /** * Log a warning scenario to inform the developer of an issues that should be investigated. * The requested operation may or may not have succeeded or completed. @@ -82,15 +89,6 @@ export interface DiagLogger { * in a production environment. */ verbose: DiagLogFunction; - - /** - * Log a general informational message that should always be logged regardless of the - * current or configured logging level {@Link DiagLogLevel} except when the level is set - * to {@Link DiagLogLevel.NONE). This type of logging is useful for logging component - * startup and version information without causing additional general informational messages - * when the logging level is set to DiagLogLevel.WARN or lower. - */ - forcedInfo: DiagLogFunction; } // DiagLogger implementation @@ -99,10 +97,10 @@ export const diagLoggerFunctions: Array<keyof DiagLogger> = [ 'debug', 'info', 'warn', + 'startupInfo', 'error', 'critical', 'terminal', - 'forcedInfo', ]; function noopLogFunction() {} diff --git a/packages/opentelemetry-api/test/diag/consoleLogger.test.ts b/packages/opentelemetry-api/test/diag/consoleLogger.test.ts index 9a79265022c..b1150308f86 100644 --- a/packages/opentelemetry-api/test/diag/consoleLogger.test.ts +++ b/packages/opentelemetry-api/test/diag/consoleLogger.test.ts @@ -35,7 +35,7 @@ const expectedConsoleMap: { [n: string]: keyof Console } = { info: 'info', debug: 'debug', verbose: 'trace', - forcedInfo: 'info', + startupInfo: 'info', }; describe('DiagConsoleLogger', () => { diff --git a/packages/opentelemetry-api/test/diag/logLevel.test.ts b/packages/opentelemetry-api/test/diag/logLevel.test.ts index 4872bbe4f5c..b984135e1c6 100644 --- a/packages/opentelemetry-api/test/diag/logLevel.test.ts +++ b/packages/opentelemetry-api/test/diag/logLevel.test.ts @@ -42,7 +42,7 @@ const expectedIncompleteMap: { [n: string]: keyof Console } = { info: 'info', debug: 'debug', verbose: 'debug', - forcedInfo: 'info', + startupInfo: 'info', }; describe('LogLevelFilter DiagLogger', () => { @@ -54,7 +54,7 @@ describe('LogLevelFilter DiagLogger', () => { info: null, debug: null, verbose: null, - forcedInfo: null, + startupInfo: null, }; let dummyLogger: DiagLogger; @@ -118,16 +118,31 @@ describe('LogLevelFilter DiagLogger', () => { { message: 'CRITICAL', level: DiagLogLevel.CRITICAL, - ignoreFuncs: ['verbose', 'debug', 'info', 'warn', 'error'], + ignoreFuncs: [ + 'verbose', + 'debug', + 'info', + 'warn', + 'error', + 'startupInfo', + ], }, { message: 'TERMINAL', level: DiagLogLevel.TERMINAL, - ignoreFuncs: ['verbose', 'debug', 'info', 'warn', 'error', 'critical'], + ignoreFuncs: [ + 'verbose', + 'debug', + 'info', + 'warn', + 'error', + 'critical', + 'startupInfo', + ], }, { message: 'between TERMINAL and NONE', - level: -10, + level: 1, ignoreFuncs: [ 'verbose', 'debug', @@ -136,6 +151,7 @@ describe('LogLevelFilter DiagLogger', () => { 'error', 'critical', 'terminal', + 'startupInfo', ], }, { @@ -149,7 +165,7 @@ describe('LogLevelFilter DiagLogger', () => { 'error', 'critical', 'terminal', - 'forcedInfo', + 'startupInfo', ], }, { @@ -163,7 +179,7 @@ describe('LogLevelFilter DiagLogger', () => { 'error', 'critical', 'terminal', - 'forcedInfo', + 'startupInfo', ], }, ]; diff --git a/packages/opentelemetry-api/test/diag/logger.test.ts b/packages/opentelemetry-api/test/diag/logger.test.ts index 2242908f040..d1629e964e8 100644 --- a/packages/opentelemetry-api/test/diag/logger.test.ts +++ b/packages/opentelemetry-api/test/diag/logger.test.ts @@ -31,7 +31,7 @@ describe('DiagLogger functions', () => { info: null, debug: null, verbose: null, - forcedInfo: null, + startupInfo: null, }; let dummyLogger: DiagLogger; diff --git a/packages/opentelemetry-core/src/common/types.ts b/packages/opentelemetry-core/src/common/types.ts index 8b543c4f0ba..d24f7f1e5c8 100644 --- a/packages/opentelemetry-core/src/common/types.ts +++ b/packages/opentelemetry-core/src/common/types.ts @@ -20,10 +20,10 @@ import { Exception } from '@opentelemetry/api'; * @see {@link DiagLogLevel} from the api */ export enum LogLevel { - ERROR = 0, - WARN = 1, - INFO = 2, - DEBUG = 3, + ERROR, + WARN, + INFO, + DEBUG, } /**