Skip to content

Commit df0bd2b

Browse files
docs: Add custom logger configuration section to README
- Add new "Custom Logger" section with usage example - Document custom logger function signature with role, operation, and result parameters - Include example of integrating with external logging service - Document logger configuration options including enableLogger flag - Clarify that logger receives optional colorsEnabled parameter - Improve documentation completeness for logger customization features
1 parent 5304576 commit df0bd2b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ app.get('/products', canFindProducts, handler);
231231
For NestJS and Fastify you can use `createNestMiddleware` and `createFastifyMiddleware`
232232
respectively with a similar API.
233233

234+
### Custom Logger
235+
236+
You can provide a custom logger function to integrate with your logging infrastructure:
237+
238+
```ts
239+
const customLogger = (role: string, operation: string | RegExp, result: boolean) => {
240+
// Send to your logging service
241+
logger.info({ role, operation, result, timestamp: Date.now() });
242+
};
243+
244+
const rbac = RBAC({ logger: customLogger })(roles);
245+
```
246+
247+
The logger receives `role`, `operation`, `result`, and an optional `colorsEnabled` parameter. Disable logging with `enableLogger: false`.
248+
234249
### Logger Color Configuration
235250

236251
The default logger automatically detects color support and applies ANSI color codes when appropriate. You can manually control this behavior via the `colors` configuration option:

0 commit comments

Comments
 (0)