@thepassle/app-tools
Version:
Collection of tools I regularly use to build apps. Maybe they're useful to somebody else. Maybe not. Most of these are thin wrappers around native API's, like the native `<dialog>` element, `fetch` API, and `URLPattern`.
32 lines (30 loc) • 739 B
JavaScript
/**
* @param {{
* collapsed?: boolean
* }} options
* @returns {import('../index.js').Plugin}
*/
export function loggerPlugin({ collapsed = true } = {}) {
let m;
let start;
const group = collapsed ? "groupCollapsed" : "group";
return {
name: "logger",
beforeFetch: (meta) => {
console[group](
`[START] [${new Date().toLocaleTimeString()}] [${meta.method}] "${meta.url}"`,
);
console.table([meta]);
console.groupEnd();
start = Date.now();
m = meta;
},
afterFetch: ({ response }) => {
console.log(
`[END] [${m.method}] "${m.url}" Request took ${Date.now() - start}ms`,
);
return response;
},
};
}
export const logger = loggerPlugin();