1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
|
3 | import { HttpPipelineLogLevel } from "../httpPipelineLogLevel";
|
4 | var BaseRequestPolicy = /** @class */ (function () {
|
5 | function BaseRequestPolicy(_nextPolicy, _options) {
|
6 | this._nextPolicy = _nextPolicy;
|
7 | this._options = _options;
|
8 | }
|
9 | /**
|
10 | * Get whether or not a log with the provided log level should be logged.
|
11 | * @param logLevel The log level of the log that will be logged.
|
12 | * @returns Whether or not a log with the provided log level should be logged.
|
13 | */
|
14 | BaseRequestPolicy.prototype.shouldLog = function (logLevel) {
|
15 | return this._options.shouldLog(logLevel);
|
16 | };
|
17 | /**
|
18 | * Attempt to log the provided message to the provided logger. If no logger was provided or if
|
19 | * the log level does not meat the logger's threshold, then nothing will be logged.
|
20 | * @param logLevel The log level of this log.
|
21 | * @param message The message of this log.
|
22 | */
|
23 | BaseRequestPolicy.prototype.log = function (logLevel, message) {
|
24 | this._options.log(logLevel, message);
|
25 | };
|
26 | return BaseRequestPolicy;
|
27 | }());
|
28 | export { BaseRequestPolicy };
|
29 | /**
|
30 | * Optional properties that can be used when creating a RequestPolicy.
|
31 | */
|
32 | var RequestPolicyOptions = /** @class */ (function () {
|
33 | function RequestPolicyOptions(_logger) {
|
34 | this._logger = _logger;
|
35 | }
|
36 | /**
|
37 | * Get whether or not a log with the provided log level should be logged.
|
38 | * @param logLevel The log level of the log that will be logged.
|
39 | * @returns Whether or not a log with the provided log level should be logged.
|
40 | */
|
41 | RequestPolicyOptions.prototype.shouldLog = function (logLevel) {
|
42 | return (!!this._logger &&
|
43 | logLevel !== HttpPipelineLogLevel.OFF &&
|
44 | logLevel <= this._logger.minimumLogLevel);
|
45 | };
|
46 | /**
|
47 | * Attempt to log the provided message to the provided logger. If no logger was provided or if
|
48 | * the log level does not meat the logger's threshold, then nothing will be logged.
|
49 | * @param logLevel The log level of this log.
|
50 | * @param message The message of this log.
|
51 | */
|
52 | RequestPolicyOptions.prototype.log = function (logLevel, message) {
|
53 | if (this._logger && this.shouldLog(logLevel)) {
|
54 | this._logger.log(logLevel, message);
|
55 | }
|
56 | };
|
57 | return RequestPolicyOptions;
|
58 | }());
|
59 | export { RequestPolicyOptions };
|
60 | //# sourceMappingURL=requestPolicy.js.map |
\ | No newline at end of file |