Ayush Goyal
Ayush Goyal12mo ago

where does opts.path and opts.type came from ? i guess by default it only stores ctx ,next and input

const loggerMiddleware = middleware(async (opts) => {
const start = Date.now();
 
const result = await opts.next();
 
const durationMs = Date.now() - start;
const meta = { path: opts.path, type: opts.type, durationMs };
 
result.ok
? console.log('OK request timing:', meta)
: console.error('Non-OK request timing', meta);
 
return result;
});
 
export const loggedProcedure = publicProcedure.use(loggerMiddleware);
const loggerMiddleware = middleware(async (opts) => {
const start = Date.now();
 
const result = await opts.next();
 
const durationMs = Date.now() - start;
const meta = { path: opts.path, type: opts.type, durationMs };
 
result.ok
? console.log('OK request timing:', meta)
: console.error('Non-OK request timing', meta);
 
return result;
});
 
export const loggedProcedure = publicProcedure.use(loggerMiddleware);
the code is from middleware documentation
1 Reply
Solution
Ayush Goyal
Ayush Goyal12mo ago