pagarme / escriba Goto Github PK
View Code? Open in Web Editor NEW:scroll: Logging on steroids
License: MIT License
:scroll: Logging on steroids
License: MIT License
Escriba should get an in from a field that will be chosen by user.
example:
"logId": {
"name": "id",
"from": ["body", "header"]
}
@vitorabner Running the docker example there are one output without json wrap, this is expected?
{"id":"cj5mkq9di001l0glb65sh6e68","method":"DELETE","url":"/escriba","body":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot DELETE /escriba</pre>\n</body>\n</html>\n","httpVersion":"1.1","user-agent":"axios/0.16.2","statusCode":404,"level":"warn","from":"response","service":"Escriba App","startTime":1501168102904,"hostname":"725514a5094d","pid":16,"latency":1}
(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 30): Error: Request failed with status code 404
(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 32): Error: Request failed with status code 404
{"id":"cj5mkqbom001m0glb8o8ae6q1","message":"Info log","level":"info","service":"Escriba App","startTime":1501168105894,"hostname":"725514a5094d","pid":16}
{"id":"cj5mkqbom001n0glb4buqni43","message":"Warn log","level":"warn","service":"Escriba App","startTime":1501168105894,"hostname":"725514a5094d","pid":16}
{"id":"cj5mkqbom001o0glb163prdu5","message":"Error log","level":"error","service":"Escriba App","startTime":1501168105894,"hostname":"725514a5094d","pid":16}
In my opinion, req.id
is a powerful tool that helps to trace a request between services, so why not log this by default?
When we try to log error object the escriba shows an empty object
hello everyone ๐ค
i'm using escriba in my projects and i always ask about the types. Many npm libs have a types (by community @types or itself generate .d.ts).
Most of my Node projects is written in TypeScript and @types doesn't seem like a good option.. My proposal is to refactor to TypeScript language and then for each published version a type declaration will be automatically generated.
Fork and branch: https://github.com/davidpvilaca/escriba/tree/refactor/typescript
I didn't have time to write types correctly but I hurried to present the idea to get a feedback.
I'm having some problems using the route.path
parameter on propsToLog
using nested routes with Express Router. Searching the internet I saw that this is an issue of the Express package itself.
Using express router with nested routes, for example:
// routes/users.js
const usersRouter = Router({ mergeParams: true });
usersRouter.get('/:id', (request, response) => {
console.log(request.route.path) // "/:id" (instead of "/users/:id")
return response.status(200).json([/* list of users */])
})
// app.js
const app = express();
app.use('/users', usersRoutes)
I would like to have a property on log that has the value /users/:id
but, using route.path
, I always get the value :id
which can be mixed with any other route that has a /:id
route, since they will log the same value. This ends up making it very difficult to filter the logs by route.
My suggestion: Can we create an own property of Escriba to handle this?
Using route.params
we can create a value that uses the request.originalUrl
and can create the same value as route.path
does but full with parent paths/suffixes.
Example code (suggestion by @asheba):
const reverseMapParamValuesToKeys = params => {
const entries = Object.entries(params);
return entries.reduce(
(map, [key, value]) => ({ ...map, [value]: `:${key}` }),
{},
);
};
const paramValuesToKeys = reverseMapParamValuesToKeys(request.params);
const originalUrl = request.originalUrl || '';
const splittedUrl = originalUrl.split('/');
const replaceWithParams = splittedUrl.map(
urlPart => paramValuesToKeys[urlPart] || urlPart,
);
const path = replaceWithParams.join('/');
const pathWithoutQueryString = path.split('?')[0];
const routePath = pathWithoutQueryString;
console.log(routePath) // /users/:id
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.