Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for request id logging #24

Merged
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b6a9e83
Add a simple logging service to log info
silwalanish Sep 20, 2019
0f65998
Refactor middlewares and services to use the logging service
silwalanish Sep 20, 2019
71323a0
Update doSomething to call logRequestContext after 2sec to show that …
silwalanish Sep 20, 2019
cf168dd
Update output of example in README.md
silwalanish Sep 20, 2019
99b7cdf
Add type for parameter in docblock
silwalanish Sep 23, 2019
5af9ad8
Add debug method to log debug and Use short request id if available
silwalanish Sep 23, 2019
848dd8e
Add middleware to capture request query params 'a' and 'b'
silwalanish Sep 23, 2019
387ea7a
Add middleware to add the params 'a' and 'b' with a simulated delay o…
silwalanish Sep 23, 2019
bfe2a3b
Implement the new addition functionality instead of previous x-id log…
silwalanish Sep 23, 2019
49f6047
Update README.md to reflect changes in output and test cmd
silwalanish Sep 23, 2019
5c6f18c
Remove delay from add middleware
silwalanish Sep 23, 2019
199a175
Add full stop at the end of docs
silwalanish Sep 24, 2019
72fbc7b
Add new line before relative imports
silwalanish Sep 24, 2019
b0c191e
Fix docs text to explain more about the method
silwalanish Sep 24, 2019
c6e6f78
Change parameter name
silwalanish Sep 24, 2019
c3b3a9a
Remove unnecessary function
silwalanish Sep 24, 2019
64eda1a
Make doSomething create a 2sec delay
silwalanish Sep 24, 2019
b7164ac
Remove unnecessary middlewares
silwalanish Sep 24, 2019
1e06678
Update README.md to show the outputs with delay
silwalanish Sep 24, 2019
bb85478
Remove unnecessary async from function defination
silwalanish Sep 24, 2019
eab65a7
Change textcase to maintain consistency
silwalanish Sep 24, 2019
ced6824
Add unparsed input to store
silwalanish Sep 24, 2019
5055a98
Remove full stop
silwalanish Sep 24, 2019
d9f65f1
Modify info logger to maintain alignment while logging
silwalanish Sep 24, 2019
2ae6e83
Update README.md to show the latest logs output
silwalanish Sep 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add middleware to add the params 'a' and 'b' with a simulated delay o…
…f 2sec
  • Loading branch information
silwalanish committed Sep 23, 2019
commit 387ea7a92ab5447dd6008a3129275b661250d00f
22 changes: 22 additions & 0 deletions examples/express-ts/src/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ export function requestParams() {
};
}

/**
* Middleware to add the parameters `a` and `b` and set `sum` on the async store.
*
* @returns {(req, res, next) => void}
*/
export function add() {
return (req: Request, res: Response, next: NextFunction) => {
logger.info('Simulating Delay');
silwalanish marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(() => {
const a = store.get('a');
const b = store.get('b');

const sum = a + b;

store.set({ sum });
logger.debug(`Calculated sum: ${sum}`);

next();
}, 2000);
};
}

/**
* Middleware to set the request context `x-id` on the async store.
*
Expand Down