@typespec/ts-http-runtime 0.2.1-alpha.20250417.3 → 0.2.1-alpha.20250418.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/browser/index.d.ts +1 -1
  2. package/dist/browser/index.js +1 -1
  3. package/dist/browser/index.js.map +1 -1
  4. package/dist/browser/logger/internal.d.ts +2 -0
  5. package/dist/browser/logger/internal.js +4 -0
  6. package/dist/browser/logger/internal.js.map +1 -0
  7. package/dist/browser/logger/logger.d.ts +70 -22
  8. package/dist/browser/logger/logger.js +91 -68
  9. package/dist/browser/logger/logger.js.map +1 -1
  10. package/dist/commonjs/index.d.ts +1 -1
  11. package/dist/commonjs/index.js +3 -1
  12. package/dist/commonjs/index.js.map +1 -1
  13. package/dist/commonjs/logger/internal.d.ts +2 -0
  14. package/dist/commonjs/logger/internal.js +8 -0
  15. package/dist/commonjs/logger/internal.js.map +1 -0
  16. package/dist/commonjs/logger/logger.d.ts +70 -22
  17. package/dist/commonjs/logger/logger.js +92 -68
  18. package/dist/commonjs/logger/logger.js.map +1 -1
  19. package/dist/esm/index.d.ts +1 -1
  20. package/dist/esm/index.js +1 -1
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/logger/internal.d.ts +2 -0
  23. package/dist/esm/logger/internal.js +4 -0
  24. package/dist/esm/logger/internal.js.map +1 -0
  25. package/dist/esm/logger/logger.d.ts +70 -22
  26. package/dist/esm/logger/logger.js +91 -68
  27. package/dist/esm/logger/logger.js.map +1 -1
  28. package/dist/react-native/index.d.ts +1 -1
  29. package/dist/react-native/index.js +1 -1
  30. package/dist/react-native/index.js.map +1 -1
  31. package/dist/react-native/logger/internal.d.ts +2 -0
  32. package/dist/react-native/logger/internal.js +4 -0
  33. package/dist/react-native/logger/internal.js.map +1 -0
  34. package/dist/react-native/logger/logger.d.ts +70 -22
  35. package/dist/react-native/logger/logger.js +91 -68
  36. package/dist/react-native/logger/logger.js.map +1 -1
  37. package/package.json +21 -2
@@ -11,7 +11,7 @@ declare global {
11
11
  }
12
12
  }
13
13
  export { AbortError } from "./abort-controller/AbortError.js";
14
- export { createClientLogger, TypeSpecRuntimeLogger, type TypeSpecRuntimeClientLogger, type Debugger, } from "./logger/logger.js";
14
+ export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, type Debugger, type TypeSpecRuntimeClientLogger, type TypeSpecRuntimeLogLevel, } from "./logger/logger.js";
15
15
  export type { BodyPart, FormDataValue, RawHttpHeaders, KeyObject, PxfObject, HttpClient, PipelineRequest, PipelineResponse, SendRequest, TlsSettings, Agent, RequestBodyType, FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, TransferProgressEvent, ProxySettings, RawHttpHeadersInput, PipelineRetryOptions, } from "./interfaces.js";
16
16
  export { createHttpHeaders } from "./httpHeaders.js";
17
17
  export * from "./auth/schemes.js";
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  export { AbortError } from "./abort-controller/AbortError.js";
4
- export { createClientLogger, TypeSpecRuntimeLogger, } from "./logger/logger.js";
4
+ export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, } from "./logger/logger.js";
5
5
  export { createHttpHeaders } from "./httpHeaders.js";
6
6
  export * from "./auth/schemes.js";
7
7
  export * from "./auth/oauth2Flows.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAuB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n TypeSpecRuntimeLogger,\n type TypeSpecRuntimeClientLogger,\n type Debugger,\n} from \"./logger/logger.js\";\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export { createLoggerContext, type CreateLoggerContextOptions, type LoggerContext, } from "./logger.js";
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export { createLoggerContext, } from "./logger.js";
4
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/logger/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,mBAAmB,GAGpB,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n createLoggerContext,\n type CreateLoggerContextOptions,\n type LoggerContext,\n} from \"./logger.js\";\n"]}
@@ -1,11 +1,5 @@
1
1
  import type { Debugger } from "./debug.js";
2
- export { Debugger } from "./debug.js";
3
- /**
4
- * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
5
- * By default, logs are sent to stderr.
6
- * Override the `log` method to redirect logs to another location.
7
- */
8
- export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
2
+ export type { Debugger };
9
3
  /**
10
4
  * The log levels supported by the logger.
11
5
  * The log levels in order of most verbose to least verbose are:
@@ -16,23 +10,9 @@ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
16
10
  */
17
11
  export type TypeSpecRuntimeLogLevel = "verbose" | "info" | "warning" | "error";
18
12
  /**
19
- * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
13
+ * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
20
14
  */
21
15
  export type TypeSpecRuntimeClientLogger = Debugger;
22
- /**
23
- * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
24
- * @param level - The log level to enable for logging.
25
- * Options from most verbose to least verbose are:
26
- * - verbose
27
- * - info
28
- * - warning
29
- * - error
30
- */
31
- export declare function setLogLevel(level?: TypeSpecRuntimeLogLevel): void;
32
- /**
33
- * Retrieves the currently specified log level.
34
- */
35
- export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
36
16
  /**
37
17
  * Defines the methods available on the SDK-facing logger.
38
18
  */
@@ -59,6 +39,74 @@ export interface TypeSpecRuntimeLogger {
59
39
  */
60
40
  verbose: Debugger;
61
41
  }
42
+ /**
43
+ * todo doc
44
+ */
45
+ export interface LoggerContext {
46
+ /**
47
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
48
+ * @param level - The log level to enable for logging.
49
+ * Options from most verbose to least verbose are:
50
+ * - verbose
51
+ * - info
52
+ * - warning
53
+ * - error
54
+ */
55
+ setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
56
+ /**
57
+ * Retrieves the currently specified log level.
58
+ */
59
+ getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
60
+ /**
61
+ * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
62
+ * @param namespace - The name of the SDK package.
63
+ * @hidden
64
+ */
65
+ createClientLogger(namespace: string): TypeSpecRuntimeLogger;
66
+ /**
67
+ * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.
68
+ * By default, logs are sent to stderr.
69
+ * Override the `log` method to redirect logs to another location.
70
+ */
71
+ logger: TypeSpecRuntimeClientLogger;
72
+ }
73
+ /**
74
+ * Option for creating a TypeSpecRuntimeLoggerContext.
75
+ */
76
+ export interface CreateLoggerContextOptions {
77
+ /**
78
+ * The name of the environment variable to check for the log level.
79
+ */
80
+ logLevelEnvVarName: string;
81
+ /**
82
+ * The namespace of the logger.
83
+ */
84
+ namespace: string;
85
+ }
86
+ /**
87
+ * Creates a logger context base on the provided options.
88
+ * @param options - The options for creating a logger context.
89
+ * @returns The logger context.
90
+ */
91
+ export declare function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext;
92
+ /**
93
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
94
+ * @param level - The log level to enable for logging.
95
+ * Options from most verbose to least verbose are:
96
+ * - verbose
97
+ * - info
98
+ * - warning
99
+ * - error
100
+ */
101
+ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
102
+ /**
103
+ * Retrieves the currently specified log level.
104
+ */
105
+ export declare function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
106
+ /**
107
+ * Retrieves the currently specified log level.
108
+ */
109
+ export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
62
110
  /**
63
111
  * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
64
112
  * @param namespace - The name of the SDK package.
@@ -1,29 +1,93 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import debug from "./debug.js";
4
- const registeredLoggers = new Set();
5
- const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env.TYPESPEC_RUNTIME_LOG_LEVEL) ||
6
- undefined;
7
- let typeSpecRuntimeLogLevel;
4
+ const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
5
+ const levelMap = {
6
+ verbose: 400,
7
+ info: 300,
8
+ warning: 200,
9
+ error: 100,
10
+ };
11
+ function patchLogMethod(parent, child) {
12
+ child.log = (...args) => {
13
+ parent.log(...args);
14
+ };
15
+ }
16
+ function isTypeSpecRuntimeLogLevel(level) {
17
+ return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level);
18
+ }
8
19
  /**
9
- * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
10
- * By default, logs are sent to stderr.
11
- * Override the `log` method to redirect logs to another location.
20
+ * Creates a logger context base on the provided options.
21
+ * @param options - The options for creating a logger context.
22
+ * @returns The logger context.
12
23
  */
13
- export const TypeSpecRuntimeLogger = debug("typeSpecRuntime");
14
- TypeSpecRuntimeLogger.log = (...args) => {
15
- debug.log(...args);
16
- };
17
- const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
18
- if (logLevelFromEnv) {
19
- // avoid calling setLogLevel because we don't want a mis-set environment variable to crash
20
- if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
21
- setLogLevel(logLevelFromEnv);
24
+ export function createLoggerContext(options) {
25
+ const registeredLoggers = new Set();
26
+ const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env[options.logLevelEnvVarName]) ||
27
+ undefined;
28
+ let logLevel;
29
+ const clientLogger = debug(options.namespace);
30
+ clientLogger.log = (...args) => {
31
+ debug.log(...args);
32
+ };
33
+ if (logLevelFromEnv) {
34
+ // avoid calling setLogLevel because we don't want a mis-set environment variable to crash
35
+ if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
36
+ setLogLevel(logLevelFromEnv);
37
+ }
38
+ else {
39
+ console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
40
+ }
22
41
  }
23
- else {
24
- console.error(`TYPESPEC_RUNTIME_LOG_LEVEL set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
42
+ function shouldEnable(logger) {
43
+ return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
25
44
  }
45
+ function createLogger(parent, level) {
46
+ const logger = Object.assign(parent.extend(level), {
47
+ level,
48
+ });
49
+ patchLogMethod(parent, logger);
50
+ if (shouldEnable(logger)) {
51
+ const enabledNamespaces = debug.disable();
52
+ debug.enable(enabledNamespaces + "," + logger.namespace);
53
+ }
54
+ registeredLoggers.add(logger);
55
+ return logger;
56
+ }
57
+ return {
58
+ setLogLevel(level) {
59
+ if (level && !isTypeSpecRuntimeLogLevel(level)) {
60
+ throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
61
+ }
62
+ logLevel = level;
63
+ const enabledNamespaces = [];
64
+ for (const logger of registeredLoggers) {
65
+ if (shouldEnable(logger)) {
66
+ enabledNamespaces.push(logger.namespace);
67
+ }
68
+ }
69
+ debug.enable(enabledNamespaces.join(","));
70
+ },
71
+ getLogLevel() {
72
+ return logLevel;
73
+ },
74
+ createClientLogger(namespace) {
75
+ const clientRootLogger = clientLogger.extend(namespace);
76
+ patchLogMethod(clientLogger, clientRootLogger);
77
+ return {
78
+ error: createLogger(clientRootLogger, "error"),
79
+ warning: createLogger(clientRootLogger, "warning"),
80
+ info: createLogger(clientRootLogger, "info"),
81
+ verbose: createLogger(clientRootLogger, "verbose"),
82
+ };
83
+ },
84
+ logger: clientLogger,
85
+ };
26
86
  }
87
+ const context = createLoggerContext({
88
+ logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
89
+ namespace: "typeSpecRuntime",
90
+ });
27
91
  /**
28
92
  * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
29
93
  * @param level - The log level to enable for logging.
@@ -33,67 +97,26 @@ if (logLevelFromEnv) {
33
97
  * - warning
34
98
  * - error
35
99
  */
36
- export function setLogLevel(level) {
37
- if (level && !isTypeSpecRuntimeLogLevel(level)) {
38
- throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
39
- }
40
- typeSpecRuntimeLogLevel = level;
41
- const enabledNamespaces = [];
42
- for (const logger of registeredLoggers) {
43
- if (shouldEnable(logger)) {
44
- enabledNamespaces.push(logger.namespace);
45
- }
46
- }
47
- debug.enable(enabledNamespaces.join(","));
100
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
101
+ export const TypeSpecRuntimeLogger = context.logger;
102
+ /**
103
+ * Retrieves the currently specified log level.
104
+ */
105
+ export function setLogLevel(logLevel) {
106
+ context.setLogLevel(logLevel);
48
107
  }
49
108
  /**
50
109
  * Retrieves the currently specified log level.
51
110
  */
52
111
  export function getLogLevel() {
53
- return typeSpecRuntimeLogLevel;
112
+ return context.getLogLevel();
54
113
  }
55
- const levelMap = {
56
- verbose: 400,
57
- info: 300,
58
- warning: 200,
59
- error: 100,
60
- };
61
114
  /**
62
115
  * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
63
116
  * @param namespace - The name of the SDK package.
64
117
  * @hidden
65
118
  */
66
119
  export function createClientLogger(namespace) {
67
- const clientRootLogger = TypeSpecRuntimeLogger.extend(namespace);
68
- patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);
69
- return {
70
- error: createLogger(clientRootLogger, "error"),
71
- warning: createLogger(clientRootLogger, "warning"),
72
- info: createLogger(clientRootLogger, "info"),
73
- verbose: createLogger(clientRootLogger, "verbose"),
74
- };
75
- }
76
- function patchLogMethod(parent, child) {
77
- child.log = (...args) => {
78
- parent.log(...args);
79
- };
80
- }
81
- function createLogger(parent, level) {
82
- const logger = Object.assign(parent.extend(level), {
83
- level,
84
- });
85
- patchLogMethod(parent, logger);
86
- if (shouldEnable(logger)) {
87
- const enabledNamespaces = debug.disable();
88
- debug.enable(enabledNamespaces + "," + logger.namespace);
89
- }
90
- registeredLoggers.add(logger);
91
- return logger;
92
- }
93
- function shouldEnable(logger) {
94
- return Boolean(typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel]);
95
- }
96
- function isTypeSpecRuntimeLogLevel(logLevel) {
97
- return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel);
120
+ return context.createClientLogger(namespace);
98
121
  }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ACnC,KAA8B;IAE9B,MAAM,MAAM,GAA4B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;QAC1E,KAAK;KACN,CAAC,CAAC;IAEH,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1C,KAAK,CAAC,MAAM,CAAC,iBAAiB,GAAG,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAED,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,MAA+B;IACnD,OAAO,OAAO,CACZ,uBAAuB,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,uBAAuB,CAAC,CACvF,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,QAAgB;IACjD,OAAO,2BAA2B,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Debugger } from \"./debug.js\";\nimport debug from \"./debug.js\";\nexport { Debugger } from \"./debug.js\";\n\nconst registeredLoggers = new Set<TypeSpecRuntimeDebugger>();\nconst logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env.TYPESPEC_RUNTIME_LOG_LEVEL) ||\n undefined;\n\nlet typeSpecRuntimeLogLevel: TypeSpecRuntimeLogLevel | undefined;\n\n/**\n * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = debug(\"typeSpecRuntime\");\nTypeSpecRuntimeLogger.log = (...args) => {\n debug.log(...args);\n};\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype TypeSpecRuntimeDebugger = Debugger & { level: TypeSpecRuntimeLogLevel };\n\n/**\n * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\nif (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `TYPESPEC_RUNTIME_LOG_LEVEL set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n}\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport function setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n typeSpecRuntimeLogLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return typeSpecRuntimeLogLevel;\n}\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = TypeSpecRuntimeLogger.extend(namespace);\n patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n}\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | TypeSpecRuntimeDebugger,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n): TypeSpecRuntimeDebugger {\n const logger: TypeSpecRuntimeDebugger = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n}\n\nfunction shouldEnable(logger: TypeSpecRuntimeDebugger): boolean {\n return Boolean(\n typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel],\n );\n}\n\nfunction isTypeSpecRuntimeLogLevel(logLevel: string): logLevel is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel as any);\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,MAAM,YAAY,CAAC;AAiG/B,MAAM,2BAA2B,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAI5E,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,GAAG;IACZ,IAAI,EAAE,GAAG;IACT,OAAO,EAAE,GAAG;IACZ,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,SAAS,cAAc,CACrB,MAAmC,EACnC,KAAyD;IAEzD,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,KAAa;IAC9C,OAAO,2BAA2B,CAAC,QAAQ,CAAC,KAAY,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmC;IACrE,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC1D,MAAM,eAAe,GACnB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC1F,SAAS,CAAC;IAEZ,IAAI,QAA6C,CAAC;IAElD,MAAM,YAAY,GAAgC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3E,YAAY,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;QAC7B,KAAK,CAAC,GAAG,CAAC,GA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,WAAW;IACzB,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport debug from \"./debug.js\";\n\nimport type { Debugger } from \"./debug.js\";\nexport type { Debugger };\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\n\n/**\n * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * todo doc\n */\nexport interface LoggerContext {\n /**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;\n\n /**\n * Retrieves the currently specified log level.\n */\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined;\n\n /**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\n createClientLogger(namespace: string): TypeSpecRuntimeLogger;\n\n /**\n * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\n logger: TypeSpecRuntimeClientLogger;\n}\n\n/**\n * Option for creating a TypeSpecRuntimeLoggerContext.\n */\nexport interface CreateLoggerContextOptions {\n /**\n * The name of the environment variable to check for the log level.\n */\n logLevelEnvVarName: string;\n\n /**\n * The namespace of the logger.\n */\n namespace: string;\n}\n\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype DebuggerWithLogLevel = Debugger & { level: TypeSpecRuntimeLogLevel };\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | DebuggerWithLogLevel,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction isTypeSpecRuntimeLogLevel(level: string): level is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level as any);\n}\n\n/**\n * Creates a logger context base on the provided options.\n * @param options - The options for creating a logger context.\n * @returns The logger context.\n */\nexport function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext {\n const registeredLoggers = new Set<DebuggerWithLogLevel>();\n const logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env[options.logLevelEnvVarName]) ||\n undefined;\n\n let logLevel: TypeSpecRuntimeLogLevel | undefined;\n\n const clientLogger: TypeSpecRuntimeClientLogger = debug(options.namespace);\n clientLogger.log = (...args) => {\n debug.log(...args);\n };\n\n if (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n }\n\n function shouldEnable(logger: DebuggerWithLogLevel): boolean {\n return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);\n }\n\n function createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n ): DebuggerWithLogLevel {\n const logger: DebuggerWithLogLevel = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n }\n\n return {\n setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n logLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n },\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return logLevel;\n },\n createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = clientLogger.extend(namespace);\n patchLogMethod(clientLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n },\n logger: clientLogger,\n };\n}\n\nconst context = createLoggerContext({\n logLevelEnvVarName: \"TYPESPEC_RUNTIME_LOG_LEVEL\",\n namespace: \"typeSpecRuntime\",\n});\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = context.logger;\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void {\n context.setLogLevel(logLevel);\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return context.getLogLevel();\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n return context.createClientLogger(namespace);\n}\n"]}
@@ -11,7 +11,7 @@ declare global {
11
11
  }
12
12
  }
13
13
  export { AbortError } from "./abort-controller/AbortError.js";
14
- export { createClientLogger, TypeSpecRuntimeLogger, type TypeSpecRuntimeClientLogger, type Debugger, } from "./logger/logger.js";
14
+ export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, type Debugger, type TypeSpecRuntimeClientLogger, type TypeSpecRuntimeLogLevel, } from "./logger/logger.js";
15
15
  export type { BodyPart, FormDataValue, RawHttpHeaders, KeyObject, PxfObject, HttpClient, PipelineRequest, PipelineResponse, SendRequest, TlsSettings, Agent, RequestBodyType, FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, TransferProgressEvent, ProxySettings, RawHttpHeadersInput, PipelineRetryOptions, } from "./interfaces.js";
16
16
  export { createHttpHeaders } from "./httpHeaders.js";
17
17
  export * from "./auth/schemes.js";
@@ -2,12 +2,14 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createRestError = exports.operationOptionsToRequestParameters = exports.getClient = exports.uint8ArrayToString = exports.stringToUint8Array = exports.isRestError = exports.RestError = exports.createPipelineRequest = exports.createHttpHeaders = exports.TypeSpecRuntimeLogger = exports.createClientLogger = exports.AbortError = void 0;
5
+ exports.createRestError = exports.operationOptionsToRequestParameters = exports.getClient = exports.uint8ArrayToString = exports.stringToUint8Array = exports.isRestError = exports.RestError = exports.createPipelineRequest = exports.createHttpHeaders = exports.TypeSpecRuntimeLogger = exports.setLogLevel = exports.getLogLevel = exports.createClientLogger = exports.AbortError = void 0;
6
6
  const tslib_1 = require("tslib");
7
7
  var AbortError_js_1 = require("./abort-controller/AbortError.js");
8
8
  Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return AbortError_js_1.AbortError; } });
9
9
  var logger_js_1 = require("./logger/logger.js");
10
10
  Object.defineProperty(exports, "createClientLogger", { enumerable: true, get: function () { return logger_js_1.createClientLogger; } });
11
+ Object.defineProperty(exports, "getLogLevel", { enumerable: true, get: function () { return logger_js_1.getLogLevel; } });
12
+ Object.defineProperty(exports, "setLogLevel", { enumerable: true, get: function () { return logger_js_1.setLogLevel; } });
11
13
  Object.defineProperty(exports, "TypeSpecRuntimeLogger", { enumerable: true, get: function () { return logger_js_1.TypeSpecRuntimeLogger; } });
12
14
  var httpHeaders_js_1 = require("./httpHeaders.js");
13
15
  Object.defineProperty(exports, "createHttpHeaders", { enumerable: true, get: function () { return httpHeaders_js_1.createHttpHeaders; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAUlC,kEAA8D;AAArD,2GAAA,UAAU,OAAA;AACnB,gDAK4B;AAJ1B,+GAAA,kBAAkB,OAAA;AAClB,kHAAA,qBAAqB,OAAA;AA0BvB,mDAAqD;AAA5C,mHAAA,iBAAiB,OAAA;AAC1B,4DAAkC;AAClC,gEAAsC;AAUtC,2DAA0F;AAAjF,2HAAA,qBAAqB,OAAA;AAE9B,+CAA+E;AAAtE,yGAAA,SAAS,OAAA;AAAE,2GAAA,WAAW,OAAA;AAC/B,4DAAoG;AAA3F,sHAAA,kBAAkB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAC/C,sDAAkD;AAAzC,yGAAA,SAAS,OAAA;AAClB,gFAAyF;AAAhF,gJAAA,mCAAmC,OAAA;AAC5C,sDAAwD;AAA/C,+GAAA,eAAe,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n TypeSpecRuntimeLogger,\n type TypeSpecRuntimeClientLogger,\n type Debugger,\n} from \"./logger/logger.js\";\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAUlC,kEAA8D;AAArD,2GAAA,UAAU,OAAA;AACnB,gDAQ4B;AAP1B,+GAAA,kBAAkB,OAAA;AAClB,wGAAA,WAAW,OAAA;AACX,wGAAA,WAAW,OAAA;AACX,kHAAA,qBAAqB,OAAA;AA4BvB,mDAAqD;AAA5C,mHAAA,iBAAiB,OAAA;AAC1B,4DAAkC;AAClC,gEAAsC;AAUtC,2DAA0F;AAAjF,2HAAA,qBAAqB,OAAA;AAE9B,+CAA+E;AAAtE,yGAAA,SAAS,OAAA;AAAE,2GAAA,WAAW,OAAA;AAC/B,4DAAoG;AAA3F,sHAAA,kBAAkB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAC/C,sDAAkD;AAAzC,yGAAA,SAAS,OAAA;AAClB,gFAAyF;AAAhF,gJAAA,mCAAmC,OAAA;AAC5C,sDAAwD;AAA/C,+GAAA,eAAe,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
@@ -0,0 +1,2 @@
1
+ export { createLoggerContext, type CreateLoggerContextOptions, type LoggerContext, } from "./logger.js";
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createLoggerContext = void 0;
6
+ var logger_js_1 = require("./logger.js");
7
+ Object.defineProperty(exports, "createLoggerContext", { enumerable: true, get: function () { return logger_js_1.createLoggerContext; } });
8
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/logger/internal.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC,yCAIqB;AAHnB,gHAAA,mBAAmB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n createLoggerContext,\n type CreateLoggerContextOptions,\n type LoggerContext,\n} from \"./logger.js\";\n"]}
@@ -1,11 +1,5 @@
1
1
  import type { Debugger } from "./debug.js";
2
- export { Debugger } from "./debug.js";
3
- /**
4
- * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
5
- * By default, logs are sent to stderr.
6
- * Override the `log` method to redirect logs to another location.
7
- */
8
- export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
2
+ export type { Debugger };
9
3
  /**
10
4
  * The log levels supported by the logger.
11
5
  * The log levels in order of most verbose to least verbose are:
@@ -16,23 +10,9 @@ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
16
10
  */
17
11
  export type TypeSpecRuntimeLogLevel = "verbose" | "info" | "warning" | "error";
18
12
  /**
19
- * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
13
+ * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
20
14
  */
21
15
  export type TypeSpecRuntimeClientLogger = Debugger;
22
- /**
23
- * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
24
- * @param level - The log level to enable for logging.
25
- * Options from most verbose to least verbose are:
26
- * - verbose
27
- * - info
28
- * - warning
29
- * - error
30
- */
31
- export declare function setLogLevel(level?: TypeSpecRuntimeLogLevel): void;
32
- /**
33
- * Retrieves the currently specified log level.
34
- */
35
- export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
36
16
  /**
37
17
  * Defines the methods available on the SDK-facing logger.
38
18
  */
@@ -59,6 +39,74 @@ export interface TypeSpecRuntimeLogger {
59
39
  */
60
40
  verbose: Debugger;
61
41
  }
42
+ /**
43
+ * todo doc
44
+ */
45
+ export interface LoggerContext {
46
+ /**
47
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
48
+ * @param level - The log level to enable for logging.
49
+ * Options from most verbose to least verbose are:
50
+ * - verbose
51
+ * - info
52
+ * - warning
53
+ * - error
54
+ */
55
+ setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
56
+ /**
57
+ * Retrieves the currently specified log level.
58
+ */
59
+ getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
60
+ /**
61
+ * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
62
+ * @param namespace - The name of the SDK package.
63
+ * @hidden
64
+ */
65
+ createClientLogger(namespace: string): TypeSpecRuntimeLogger;
66
+ /**
67
+ * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.
68
+ * By default, logs are sent to stderr.
69
+ * Override the `log` method to redirect logs to another location.
70
+ */
71
+ logger: TypeSpecRuntimeClientLogger;
72
+ }
73
+ /**
74
+ * Option for creating a TypeSpecRuntimeLoggerContext.
75
+ */
76
+ export interface CreateLoggerContextOptions {
77
+ /**
78
+ * The name of the environment variable to check for the log level.
79
+ */
80
+ logLevelEnvVarName: string;
81
+ /**
82
+ * The namespace of the logger.
83
+ */
84
+ namespace: string;
85
+ }
86
+ /**
87
+ * Creates a logger context base on the provided options.
88
+ * @param options - The options for creating a logger context.
89
+ * @returns The logger context.
90
+ */
91
+ export declare function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext;
92
+ /**
93
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
94
+ * @param level - The log level to enable for logging.
95
+ * Options from most verbose to least verbose are:
96
+ * - verbose
97
+ * - info
98
+ * - warning
99
+ * - error
100
+ */
101
+ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
102
+ /**
103
+ * Retrieves the currently specified log level.
104
+ */
105
+ export declare function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
106
+ /**
107
+ * Retrieves the currently specified log level.
108
+ */
109
+ export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
62
110
  /**
63
111
  * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
64
112
  * @param namespace - The name of the SDK package.