Skip to content

Commit

Permalink
handling boolean type for the logger option (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
15fathoms authored Jul 7, 2024
1 parent 14cd04e commit 8e0227d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface Options {
spacer?: number;
prefix?: string;
logger?: (method: string, space: string, path: string) => void;
logger?: ((method: string, space: string, path: string) => void) | boolean;
color?: boolean;
}

Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ function getStacks(app) {
return [];
}



module.exports = function expressListRoutes(app, opts) {
const stacks = getStacks(app);
const options = { ...defaultOptions, ...opts };
Expand All @@ -99,7 +101,11 @@ module.exports = function expressListRoutes(app, opts) {
const stackPath = path
.normalize([options.prefix, stack.routerPath, stack.route.path, route.path].filter((s) => !!s).join(''))
.trim();
options.logger(stackMethod, stackSpace, stackPath);
if (options.logger === true) {
defaultOptions.logger(stackMethod, stackSpace, stackPath);
} else if (typeof options.logger === 'function') {
options.logger(stackMethod, stackSpace, stackPath);
}
paths.push({ method, path: stackPath });
routeLogged[method] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can pass a second argument to set some options
{
prefix: '', // A prefix for router Path
spacer: 7 // Spacer between router Method and Path
logger: console.info // A custom logger function
logger: console.info // A custom logger function or a boolean (true for default logger, false for no logging)
color: true // If the console log should color the method name
}
```
Expand Down

0 comments on commit 8e0227d

Please sign in to comment.