hg-pyun / axios-logger Goto Github PK
View Code? Open in Web Editor NEWBeautify Axios Logging Messages
License: MIT License
Beautify Axios Logging Messages
License: MIT License
Change to test based dev env.
const config = {
dataFilter: regex
headFilter: ['custom-header']
}
output
prefix url response-code filtered-head filtered-data
Currently, this source developed by global tsc. This can cause version issues.
TBD
Support simple introduce page using github.io
Add issue templates
I'd like to be able to use this in our typescript app, but in order to do that I need typescript types. You don't have to rewrite to typescript just include the typescript definition file in the release
Hi! Sometimes the axios error comes with config null or undefined, and the errorLogger crashes with this exception
ERROR: Cannot destructure property `method` of 'undefined' or 'null'.
As a workaround I resolved it by adding this validation in the axios interceptor
axiosInstance.interceptors.response.use(responseLogger, (error) => {
if (error.config && error.response) {
return errorLogger(error)
}
return Promise.reject(error)
})
But I think the best solution is to add a validation in the errorLogger
to prevent this type of crashes (if I catch some free time I can solve this and create the PR).
Thanks!
Note: I think is related with this issue #50
Refactoring via typescript
When logging the bodies of large requests or responses it would make sense to allow them to be limited to a certain size. Otherwise large bodies clutter the console without adding value.
If you do header: true then you do not get headers, because if you look in the code it is looking for headers plural.
Providing the headers option instead of header fixes this.
Documentation needs updating to use plural.
I'm sorry I'm late. When all the functions below are developed, we will publish 2.4.0.
It will be distributed sometime in August. Thank you for waiting.
Thank you for feedback @ClintEsteMadera, @Fylipp, @mirfilip, @xenoterracide, and others.
I have axios-logger installed via NPM, v2.2.0.
Based on github, that release should have makeHeader included: https://github.com/hg-pyun/axios-logger/releases
Which is also backed up by the commit/tag that corresponds with the release: a6c3fd4
Yet looking at the code that NPM fetched, makeHeader doesn't exist in the module's lib/ directory.
If I download the 2.2.0 zip asset, I see the same issue, the lib/ directory is outdated. The src/ directory has the latest code, so the assets weren't properly built.
Tagging @hg-pyun
const config = {
saveLocal: true,
logRotate: true,
filePath: './var/log'
}
Add change log
improve logging features. please comment feature if you have idea.
printLog only knows about global configs:
function printLog (text: string) {
getGlobalConfig().logger(text);
}
need to have it merge with provided config overrides
What is the required parameters?
I'd like to be able to log using winston in our app, but I want the output string that you generate. to pass to it.
Describe the bug
It seems the destructuring does not work when using baseURL in config
To Reproduce
const API_URL = 'http://localhost:5000'
const api = axios.create({
baseURL: API_URL,
method: 'post'
})
if (process.env.NODE_ENV !== 'production') {
api.interceptors.request.use(
AxiosLogger.requestLogger,
AxiosLogger.errorLogger
)
api.interceptors.response.use(
AxiosLogger.responseLogger,
AxiosLogger.errorLogger
)
}
// Request
async function get(args){
const { data } = await api.post(`/validate/${args.code}`, {})
return data
}
get()
// Cannot destructure property `url` of 'undefined' or 'null'.
Expected behavior
error could be logged
Is your feature request related to a problem? Please describe.
We would like to log request headers (among the HTTP method) for making tests more readable.
Describe the solution you'd like
The typings for this behaviour (RequestLogConfig
) seems to be in place already. We would like the configuration to be respected when printing logs.
Additional context
We think this is the relevant area, where the headers flag should be used.
https://github.com/hg-pyun/axios-logger/blob/master/src/logger/request.ts#L12-L21
Thank you!
logger field is required if config is supplied, but request/responseLogger functions don't actually use it.
I have, e.g. this
return responseLogger(request, {
prefixText: 'Contentful',
logger: (): void => {},
});
but that logger method is required in the types, but it's not actually used. I'd like for the field to be optional, in case the default is fine. also have printjs use the individual request/response logger settings by default, because in our case we have Contentful which wraps axios, and we have our own axios calls, so having different logger settings would be ideal.
There is no need to push transpiled code into the repository. It should be added into .gitignore
. Also a prepare
script should be added into package.json
to make sure that lib
is regenerated before publishing the package into npm.
Error Log Prototyping
Write down test case. using test tool such as mocha, jest, and etc.
Thank you for this library! Could you please add response data to errors? Would help with debugging :)
This lib looks like a decently thought out thing, apart from hardcoded usage of console.log
. Is there a reason other general loggers are not allowed?
Majority of people use a real logger like Pino, Bunyan etc.
It is always frustrating when request/response contains a buffer. Dumping in console as is totally useless because of huge amount of data inside and causes a harder debug of other requests.
#55 will help in a certain way. Though it will be nice to have an option to completely exclude buffer data from logging.
Now
[Axios][Response] GET http://example.com/some_file_.pdf {"type":"Buffer","data [255,216,255,224,0,16,74,70,73,70,0,1,1,0,
0,72,0,72,0,0,255,219,0,67,0,1,1,1,1,1,1,2,1,1,2,3,2,2,2,3,4,3,3,3,3,4,6,4,4,4,4,4,6,7,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,9,9,9,9,9,
11,11,11,11,11,11,11,11,11,11,255,219,0,67,1,2,2,2,3,3,3,5,3,3,5,11,8,6,8,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,255,194,0,17,8,3,32,4,176,3,1,34,0,2,17,1,3,17,1,255,196,0,
29,0,1,0,1,4,3,1,0,0,0,0,0,0,0,0,0,0,0,2,1,6,7,8,3,5,9,4,255,196,0,27,1,1,0,2,3,1,1,0,0,0,0,0,0,0,0,0,0,0,4,6,2,3,5,7,1,255,218,0,12,3,1,
0,2,16,3,16,0,0,1,188,120,143,90,240,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,225,157,182,215,178,225,91,207,171,
151,231,232,128,103,172,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,188,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
...and so on....
...many lines...
Want to
[Axios][Response] GET http://example.com/some_file_.pdf [Buffer]
Update readme.md
Save logs on debug mode
When using Axios' baseURL
property (as seen in this example), baseURL
is ignored, and only the url
suffix is shown in logs.
When the url
config is set to true
, both baseURL
and url
should be concatenated, maybe demarcating the base with a different color, or providing an extra flag for not showing the base.
import axios from 'axios';
import * as AxiosLogger from 'axios-logger';
const instance = axios.create({
baseURL: 'https://github.com',
});
instance.interceptors.request.use(AxiosLogger.requestLogger, AxiosLogger.errorLogger);
instance.get('/hg-pyun');
[Axios][Request] GET https://github.com/hg-pyun
[Axios][Request] GET /hg-pyun
TBD
Basic usage document
interface config {
prefixText?: string | boolean,
dateFormat?: string | boolean,
data?: boolean,
url?: boolean,
method?: boolean,
headers?: boolean,
status?: boolean,
statusText?: boolean,
code?: boolean,
}
Both requestLogger
and responseLogger
accept CommonConfig
properties. However, errorLogger
for some reason doesn't. I would like to set local configuration for errorLogger
.
NPM
, exclusive source file/src/
Is your feature request related to a problem? Please describe.
This is a handy lib, ideally it would plug into a standard display format as used by grafana (formats in here - https://grafana.com/docs/loki/latest/logql/#Metric-Queries)
Describe the solution you'd like
Return Json or logfmt
Describe alternatives you've considered
Writing long hand regex, but that seems pretty brittle.
documentation suggests I should get
POST http://.../api/3.0/drink/pickup {...}
instead I get
[Axios][Request] 2020-06-30T14:57:51-0500 3.0/drink/pickup POST {"order_id":851869,"code":"123"}
the lack of the baseurl is problematic for me as I was just sending to the wrong url
axios.interceptors.request.use((req) => {
return requestLogger(req, {
method: true,
url: true,
});
}, errorLogger);
axios.interceptors.response.use(responseLogger, errorLogger);```
improve error formatting
Merge #31
Webpack 5 has no longer NodeJs polyfills
https://webpack.js.org/migrate/5/#test-webpack-5-compatibility
There is no error building with Webpack 4 but it crashes with Webpack 5 because of chalk
dependency
vendors.js:53270 Uncaught ReferenceError: process is not defined
at Object.../../node_modules/axios-logger/node_modules/chalk/index.js (vendors.js:53270)
at __webpack_require__ (runtime.js:22)
at Object.../../node_modules/axios-logger/lib/common/string-builder.js (vendors.js:52803)
at __webpack_require__ (runtime.js:22)
at Object.../../node_modules/axios-logger/lib/logger/request.js (vendors.js:53007)
at __webpack_require__ (runtime.js:22)
at Object.../../node_modules/axios-logger/lib/index.js (vendors.js:52926)
at __webpack_require__ (runtime.js:22)
at Module.../shared/src/api/axios.ts (main.js:22861)
at __webpack_require__ (runtime.js:22)
I guess latest version of chalk
doesnt use process.platform
anymore.
Maybe it is time to update it? :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.