You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**NOTE:** Any instance of consola that inherits the mocked instance, will apply provided callback again.
175
173
This way, mocking works for `withTag` scoped loggers without need to extra efforts.
176
174
177
-
## Fields
178
-
179
-
#### `reporters`
180
-
181
-
An array of active reporters.
182
-
183
-
#### `level`
184
-
185
-
The level to display logs. Any logs at or above this level will be displayed.
186
-
List of available levels [here](./src/types.ts).
175
+
## Custom Reporters
187
176
188
-
You can set the log level using the `CONSOLA_LEVEL` environment variable, which must have the numeric log level as its value.
177
+
Consola ships with 3 built-in reporters out of the box. A fancy colored reporter by default and fallsback to a basic reporter if running in a testing or CI environment detected using [unjs/std-env](https://github.com/unjs/std-env) and a basic browser reporter.
189
178
190
-
## `logObject`
179
+
You can create a new reporter object that implements `{ log(logObject): () => { } }` interface.
191
180
192
-
The `logObject` is a free-to-extend object which will be passed to reporters.
181
+
**Example:** Simple JSON reporter
193
182
194
-
Standard fields:
183
+
```ts
184
+
import { createConsola } from"consola";
195
185
196
-
-`message`
197
-
-`additional`
198
-
-`args`
199
-
-`date`
200
-
-`tag`
186
+
const consola =createConsola({
187
+
reporters: [
188
+
{
189
+
log: (logObj) => {
190
+
console.log(JSON.stringify(logObj));
191
+
},
192
+
},
193
+
],
194
+
});
201
195
202
-
Extra fields:
196
+
// Prints {"date":"2023-04-18T12:43:38.693Z","args":["foo bar"],"type":"log","level":2,"tag":""}
197
+
consola.log("foo bar");
198
+
```
203
199
204
-
-`badge`
200
+
## Log Level
205
201
206
-
## Reporters
202
+
Consola only shows logs with configured log level or below. (Default is `3`)
207
203
208
-
Choose between one of the built-in reporters or bring in your own one.
204
+
Available log levels:
209
205
210
-
Consola uses a fancy colored reporter by default and fallsback to a basic reporter if running in a testing or CI environment detected using [unjs/std-env](https://github.com/unjs/std-env).
0 commit comments