Skip to content

Commit 57e3748

Browse files
committed
docs(wxt-modules): Add logging examples/best practices
1 parent 155626f commit 57e3748

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/guide/essentials/wxt-modules.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,35 @@ console.log(config.myModule);
137137

138138
This is very useful when [generating runtime code](#generate-runtime-module).
139139

140+
#### Logging
141+
142+
There are two "correct" ways to add console logs to your modules:
143+
144+
1. Use `wxt.logger` for info, warnings, and errors
145+
2. Install [`obug`](https://www.npmjs.com/package/obug) for debug messages
146+
147+
```ts
148+
import { defineWxtModule } from 'wxt/modules';
149+
import { createDebug } from 'obug';
150+
151+
const debug = createDebug('my-module');
152+
153+
export default defineWxtModule({
154+
setup(wxt) {
155+
wxt.logger.info('Module loaded');
156+
debug('Debug details');
157+
},
158+
});
159+
```
160+
161+
`wxt.logger` is great for formatted, pretty messages that match the rest of WXT's logs.
162+
163+
`obug` makes it easy for devs to enable and filter debug logs when necessary:
164+
165+
```sh
166+
DEBUG=my-module wxt dev
167+
```
168+
140169
#### Add custom entrypoint options
141170

142171
Modules can add custom options to entrypoints by augmenting the entrypoint options types. This allows you to add custom configuration that can be accessed during the build process.

0 commit comments

Comments
 (0)