diff --git a/README.md b/README.md index 53877f2..820ec03 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,37 @@ instance.interceptors.response.use(AxiosLogger.responseLogger, (err) => { }); ``` +## Configuration Settings + +You can adjust several features as desired through configuration file. +If you want to set config globally, using `setGlobalConfig` method. + +```javascript +setGlobalConfig({ + prefixText: 'your prefix', + dateFormat: 'HH:MM:ss', + status: false, +}); +``` + +Or it can also be passed on as a second argument and applied locally. + +```javascript +instance.interceptors.request.use((config) => { + // write down your request intercept. + return AxiosLogger.requestLogger(config, { + prefixText: 'your prefix', + dateFormat: 'HH:MM:ss', + status: false, + }); +}); +``` + +#### Enable config list + +- prefixText: string | false (default Axios) +- dateFormat: [dateformat](https://github.com/felixge/node-dateformat) | false (default isoDateTime) + ## CONTRIBUTE I always welcome Feedback and Pull Request :) diff --git a/lib/common/config.d.ts b/lib/common/config.d.ts index 3a11a00..f89cb0e 100644 --- a/lib/common/config.d.ts +++ b/lib/common/config.d.ts @@ -9,19 +9,15 @@ declare function mergeWithGlobalConfig(config?: RequestLogConfig | ResponseLogCo status?: boolean | undefined; statusText?: boolean | undefined; code?: boolean | undefined; - usePrefix?: boolean | undefined; - prefixText?: string | undefined; - useDate?: boolean | undefined; - dateFormat?: string | undefined; + prefixText?: string | boolean | undefined; + dateFormat?: string | boolean | undefined; } | { data?: boolean | undefined; url?: boolean | undefined; method?: boolean | undefined; headers?: boolean | undefined; - usePrefix?: boolean | undefined; - prefixText?: string | undefined; - useDate?: boolean | undefined; - dateFormat?: string | undefined; + prefixText?: string | boolean | undefined; + dateFormat?: string | boolean | undefined; status?: boolean | undefined; statusText?: boolean | undefined; code?: boolean | undefined; @@ -30,20 +26,16 @@ declare function mergeWithGlobalConfig(config?: RequestLogConfig | ResponseLogCo status?: boolean | undefined; statusText?: boolean | undefined; headers?: boolean | undefined; - usePrefix?: boolean | undefined; - prefixText?: string | undefined; - useDate?: boolean | undefined; - dateFormat?: string | undefined; + prefixText?: string | boolean | undefined; + dateFormat?: string | boolean | undefined; url?: boolean | undefined; method?: boolean | undefined; code?: boolean | undefined; } | { data?: boolean | undefined; code?: boolean | undefined; - usePrefix?: boolean | undefined; - prefixText?: string | undefined; - useDate?: boolean | undefined; - dateFormat?: string | undefined; + prefixText?: string | boolean | undefined; + dateFormat?: string | boolean | undefined; url?: boolean | undefined; method?: boolean | undefined; headers?: boolean | undefined; diff --git a/lib/common/string-builder.d.ts b/lib/common/string-builder.d.ts index c252899..f87a893 100644 --- a/lib/common/string-builder.d.ts +++ b/lib/common/string-builder.d.ts @@ -3,7 +3,7 @@ declare class StringBuilder { private config; private printQueue; constructor(config: GlobalLogConfig); - makePrefix(logType: string): this; + makePrefix(logType: string | false): this; makeDateFormat(): this; makeUrl(url?: string): this; makeMethod(method?: string): this; diff --git a/lib/common/string-builder.js b/lib/common/string-builder.js index 465b521..0c351e5 100644 --- a/lib/common/string-builder.js +++ b/lib/common/string-builder.js @@ -33,12 +33,14 @@ class StringBuilder { } makePrefix(logType) { - const prefix = this.config.prefixText ? `[${this.config.prefixText}][${logType}]` : `[Axios][${logType}]`; + const prefix = + this.config.prefixText === false ? `[${logType}]` : `[${this.config.prefixText || 'Axios'}][${logType}]`; this.printQueue.push(_chalk.default.green(prefix)); return this; } makeDateFormat() { + // @ts-ignore const dateFormat = (0, _dateformat.default)(new Date(), this.config.dateFormat || 'isoDateTime'); this.printQueue.push(dateFormat); return this; @@ -71,4 +73,4 @@ class StringBuilder { var _default = StringBuilder; exports.default = _default; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vc3RyaW5nLWJ1aWxkZXIudHMiXSwibmFtZXMiOlsiU3RyaW5nQnVpbGRlciIsImNvbnN0cnVjdG9yIiwiY29uZmlnIiwicHJpbnRRdWV1ZSIsIm1ha2VQcmVmaXgiLCJsb2dUeXBlIiwicHJlZml4IiwicHJlZml4VGV4dCIsInB1c2giLCJjaGFsayIs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2FzZSgpKSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG1ha2VEYXRhKGRhdGE6IG9iamVjdCkge1xuICAgICAgICBpZihkYXRhKSB0aGlzLnByaW50UXVldWUucHVzaChKU09OLnN0cmluZ2lmeShkYXRhKSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG1ha2VTdGF0dXMoc3RhdHVzPzpudW1iZXIsIHN0YXR1c1RleHQ/OiBzdHJpbmcpIHtcbiAgICAgICAgaWYoc3RhdHVzICYmIHN0YXR1c1RleHQpIHRoaXMucHJpbnRRdWV1ZS5wdXNoKGAke3N0YXR1c306JHtzdGF0dXNUZXh0fWApO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBidWlsZCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMucHJpbnRRdWV1ZS5qb2luKCcgJyk7XG4gICAgfVxufVxuXG5leHBvcnQgZGVmYXVsdCBTdHJpbmdCdWlsZGVyOyJdfQ== +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vc3RyaW5nLWJ1aWxkZXIudHMiXSwibmFtZXMiOlsiU3RyaW5nQnVpbGRlciIsImNvbnN0cnVjdG9yIiwiY29uZmlnIiwicHJpbnRRdWV1ZSIsIm1ha2VQcmVmaXgiLCJsb2dUeXBlIiwicHJlZml4IiwicHJlZml4VGV4dCIsInB1c2giLCJjaGFsayIsImdyZWVuIiwibWFrZURhdGVGb3JtYXQiLCJkYXRlRm9ybWF0IiwiRGF0ZSIsIm1ha2VVcmwiLCJ1cmwiLCJtYWtlTWV0aG9kIiwibWV0aG9kIiwieWVsbG93IiwidG9VcHBlckNhc2UiLCJtYWtlRGF0YSIsImRhdGEiLCJKU09OIiwic3RyaW5naWZ5IiwibWFrZVN0YXR1cyIsInN0YXR1cyIsInN0YXR1c1RleHQiLCJidWl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2goSlNPTi5zdHJpbmdpZnkoZGF0YSkpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBtYWtlU3RhdHVzKHN0YXR1cz86bnVtYmVyLCBzdGF0dXNUZXh0Pzogc3RyaW5nKSB7XG4gICAgICAgIGlmKHN0YXR1cyAmJiBzdGF0dXNUZXh0KSB0aGlzLnByaW50UXVldWUucHVzaChgJHtzdGF0dXN9OiR7c3RhdHVzVGV4dH1gKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnByaW50UXVldWUuam9pbignICcpO1xuICAgIH1cbn1cblxuZXhwb3J0IGRlZmF1bHQgU3RyaW5nQnVpbGRlcjsiXX0= diff --git a/lib/common/types.d.ts b/lib/common/types.d.ts index 1dae82a..0771780 100644 --- a/lib/common/types.d.ts +++ b/lib/common/types.d.ts @@ -1,8 +1,6 @@ export interface CommonConfig { - usePrefix?: boolean; - prefixText?: string; - useDate?: boolean; - dateFormat?: string; + prefixText?: string | boolean; + dateFormat?: string | boolean; } export interface GlobalLogConfig extends CommonConfig { data?: boolean; diff --git a/package.json b/package.json index 0522861..ae5cfbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "axios-logger", - "version": "2.0.1", + "version": "2.1.0", "description": "Beautify Axios Logging Messages", "main": "lib/index.js", "keywords": [ diff --git a/src/common/string-builder.ts b/src/common/string-builder.ts index e2dad4c..14bb4f9 100644 --- a/src/common/string-builder.ts +++ b/src/common/string-builder.ts @@ -11,13 +11,14 @@ class StringBuilder { this.printQueue = []; } - makePrefix(logType: string) { - const prefix = this.config.prefixText ? `[${this.config.prefixText}][${logType}]` : `[Axios][${logType}]`; + makePrefix(logType: string | false) { + const prefix = this.config.prefixText === false ? `[${logType}]` : `[${this.config.prefixText || 'Axios'}][${logType}]`; this.printQueue.push(chalk.green(prefix)); return this; } makeDateFormat() { + // @ts-ignore const dateFormat = dateformat(new Date(), this.config.dateFormat || 'isoDateTime'); this.printQueue.push(dateFormat); return this; diff --git a/src/common/types.ts b/src/common/types.ts index d023075..1492e22 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -1,8 +1,6 @@ export interface CommonConfig { - usePrefix?: boolean, - prefixText?: string, - useDate?: boolean, - dateFormat?: string, + prefixText?: string | boolean, + dateFormat?: string | boolean, } export interface GlobalLogConfig extends CommonConfig { diff --git a/src/logger/__test__/error.spec.js b/src/logger/__test__/error.spec.js index 1119b35..6ef78c4 100644 --- a/src/logger/__test__/error.spec.js +++ b/src/logger/__test__/error.spec.js @@ -78,3 +78,14 @@ test('if both global and local config are defined, local config should override expect(printLog).toHaveBeenCalled(); expect(printLog).toBeCalledWith(expect.stringContaining('[local custom prefix]')); }); + +test('if prefixText is false, remove prefix', () => { + const globalConfig = { + prefixText: false, + }; + + setGlobalConfig(globalConfig); + errorLoggerWithoutPromise(axiosError); + expect(printLog).toHaveBeenCalled(); + expect(printLog).toBeCalledWith(expect.not.stringContaining('[Axios]')); +}); diff --git a/src/logger/__test__/request.spec.js b/src/logger/__test__/request.spec.js index b327715..d8addea 100644 --- a/src/logger/__test__/request.spec.js +++ b/src/logger/__test__/request.spec.js @@ -66,3 +66,14 @@ test('if both global and local config are defined, local config should override expect(printLog).toHaveBeenCalled(); expect(printLog).toBeCalledWith(expect.stringContaining('[local custom prefix]')); }); + +test('if prefixText is false, remove prefix', () => { + const globalConfig = { + prefixText: false, + }; + + setGlobalConfig(globalConfig); + requestLogger(axiosRequestConfig); + expect(printLog).toHaveBeenCalled(); + expect(printLog).toBeCalledWith(expect.not.stringContaining('[Axios]')); +}); diff --git a/src/logger/__test__/response.spec.js b/src/logger/__test__/response.spec.js index e410644..a234d09 100644 --- a/src/logger/__test__/response.spec.js +++ b/src/logger/__test__/response.spec.js @@ -76,3 +76,14 @@ test('if both global and local config are defined, local config should override expect(printLog).toHaveBeenCalled(); expect(printLog).toBeCalledWith(expect.stringContaining('[local custom prefix]')); }); + +test('if prefixText is false, remove prefix', () => { + const globalConfig = { + prefixText: false, + }; + + setGlobalConfig(globalConfig); + responseLogger(axiosResponse); + expect(printLog).toHaveBeenCalled(); + expect(printLog).toBeCalledWith(expect.not.stringContaining('[Axios]')); +});