@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`.
27 lines (26 loc) • 683 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: (r) => {
console.log(`[END] [${m.method}] "${m.url}" Request took ${Date.now() - start}ms`);
return r;
}
}
}
export const logger = loggerPlugin();