axios-logger
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -12,6 +12,4 @@ import { ErrorLogConfig, GlobalLogConfig, RequestLogConfig, ResponseLogConfig } from './types'; | ||
code?: boolean | undefined; | ||
usePrefix?: boolean | undefined; | ||
prefixText?: string | undefined; | ||
useDate?: boolean | undefined; | ||
dateFormat?: string | undefined; | ||
prefixText?: string | boolean | undefined; | ||
dateFormat?: string | boolean | undefined; | ||
} | { | ||
@@ -22,6 +20,4 @@ data?: 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; | ||
@@ -35,6 +31,4 @@ 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; | ||
@@ -46,6 +40,4 @@ method?: 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; | ||
@@ -52,0 +44,0 @@ method?: boolean | undefined; |
@@ -6,3 +6,3 @@ import { GlobalLogConfig } from './types'; | ||
constructor(config: GlobalLogConfig); | ||
makePrefix(logType: string): this; | ||
makePrefix(logType: string | false): this; | ||
makeDateFormat(): this; | ||
@@ -9,0 +9,0 @@ makeUrl(url?: string): this; |
@@ -36,3 +36,4 @@ 'use strict'; | ||
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)); | ||
@@ -43,2 +44,3 @@ return this; | ||
makeDateFormat() { | ||
// @ts-ignore | ||
const dateFormat = (0, _dateformat.default)(new Date(), this.config.dateFormat || 'isoDateTime'); | ||
@@ -76,2 +78,2 @@ this.printQueue.push(dateFormat); | ||
exports.default = _default; | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vc3RyaW5nLWJ1aWxkZXIudHMiXSwibmFtZXMiOlsiU3RyaW5nQnVpbGRlciIsImNvbnN0cnVjdG9yIiwiY29uZmlnIiwicHJpbnRRdWV1ZSIsIm1ha2VQcmVmaXgiLCJsb2dUeXBlIiwicHJlZml4IiwicHJlZml4VGV4dCIsInB1c2giLCJjaGFsayIsImdyZWVuIiwibWFrZURhdGVGb3JtYXQiLCJkYXRlRm9ybWF0IiwiRGF0ZSIsIm1ha2VVcmwiLCJ1cmwiLCJtYWtlTWV0aG9kIiwibWV0aG9kIiwieWVsbG93IiwidG9VcHBlckNhc2UiLCJtYWtlRGF0YSIsImRhdGEiLCJKU09OIiwic3RyaW5naWZ5IiwibWFrZVN0YXR1cyIsInN0YXR1cyIsInN0YXR1c1RleHQiLCJidWlsZCIsImpvaW4iXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFBQTs7QUFFQTs7Ozs7O0FBRUEsTUFBTUEsYUFBTixDQUFvQjtBQUloQkMsRUFBQUEsV0FBVyxDQUFDQyxNQUFELEVBQTBCO0FBQUE7O0FBQUE7O0FBQ2pDLFNBQUtBLE1BQUwsR0FBY0EsTUFBZDtBQUNBLFNBQUtDLFVBQUwsR0FBa0IsRUFBbEI7QUFDSDs7QUFFREMsRUFBQUEsVUFBVSxDQUFDQyxPQUFELEVBQWtCO0FBQ3hCLFVBQU1DLE1BQU0sR0FBRyxLQUFLSixNQ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YXRlVGltZScpO1xuICAgICAgICB0aGlzLnByaW50UXVldWUucHVzaChkYXRlRm9ybWF0KTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgbWFrZVVybCh1cmw/OiBzdHJpbmcpIHtcbiAgICAgICAgaWYodXJsKSB0aGlzLnByaW50UXVldWUucHVzaCh1cmwpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBtYWtlTWV0aG9kKG1ldGhvZD86IHN0cmluZykge1xuICAgICAgICBpZihtZXRob2QpIHRoaXMucHJpbnRRdWV1ZS5wdXNoKGNoYWxrLnllbGxvdyhtZXRob2QudG9VcHBlckNhc2UoKSkpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBtYWtlRGF0YShkYXRhOiBvYmplY3QpIHtcbiAgICAgICAgaWYoZGF0YSkgdGhpcy5wcmludFF1ZXVlLnB1c2goSlNPTi5zdHJpbmdpZnkoZGF0YSkpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBtYWtlU3RhdHVzKHN0YXR1cz86bnVtYmVyLCBzdGF0dXNUZXh0Pzogc3RyaW5nKSB7XG4gICAgICAgIGlmKHN0YXR1cyAmJiBzdGF0dXNUZXh0KSB0aGlzLnByaW50UXVldWUucHVzaChgJHtzdGF0dXN9OiR7c3RhdHVzVGV4dH1gKTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfVxuXG4gICAgYnVpbGQoKSB7XG4gICAgICAgIHJldHVybiB0aGlzLnByaW50UXVldWUuam9pbignICcpO1xuICAgIH1cbn1cblxuZXhwb3J0IGRlZmF1bHQgU3RyaW5nQnVpbGRlcjsiXX0= |
export interface CommonConfig { | ||
usePrefix?: boolean; | ||
prefixText?: string; | ||
useDate?: boolean; | ||
dateFormat?: string; | ||
prefixText?: string | boolean; | ||
dateFormat?: string | boolean; | ||
} | ||
@@ -7,0 +5,0 @@ export interface GlobalLogConfig extends CommonConfig { |
{ | ||
"name": "axios-logger", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Beautify Axios Logging Messages", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -87,4 +87,35 @@ # axios-logger | ||
## 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 :) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32779
121
413