Skip to content

Commit a952bc2

Browse files
committed
chore: update the docs
1 parent 943992d commit a952bc2

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

README.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,14 @@ import { consola, createConsola } from "consola/browser";
7373
import { createConsola } from "consola/core";
7474
```
7575

76-
## Methods
76+
## Consola Methods
7777

7878
#### `<type>(logObject)` `<type>(args...)`
7979

8080
Log to all reporters.
8181

8282
Example: `consola.info('Message')`
8383

84-
A list of available types can be found [here](./src/types.ts).
85-
8684
#### `await prompt(message, { type })`
8785

8886
Show an input prompt. Type can either of `text`, `confirm`, `select` or `multiselect`.
@@ -174,52 +172,57 @@ consola.mockTypes((typeName) => typeName === "fatal" && jest.fn());
174172
**NOTE:** Any instance of consola that inherits the mocked instance, will apply provided callback again.
175173
This way, mocking works for `withTag` scoped loggers without need to extra efforts.
176174

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
187176

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.
189178

190-
## `logObject`
179+
You can create a new reporter object that implements `{ log(logObject): () => { } }` interface.
191180

192-
The `logObject` is a free-to-extend object which will be passed to reporters.
181+
**Example:** Simple JSON reporter
193182

194-
Standard fields:
183+
```ts
184+
import { createConsola } from "consola";
195185

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+
});
201195

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+
```
203199

204-
- `badge`
200+
## Log Level
205201

206-
## Reporters
202+
Consola only shows logs with configured log level or below. (Default is `3`)
207203

208-
Choose between one of the built-in reporters or bring in your own one.
204+
Available log levels:
209205

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).
206+
- `0`: Fatal and Error
207+
- `1`: Warnings
208+
- `2`: Normal logs
209+
- `3`: Informational logs, success, fail, ready, start, ...
210+
- `4`: Debug logs
211+
- `5`: Trace logs
212+
- `-999`: Silent
213+
- `+999`: Verbose logs
211214

212-
### Creating a custom reporter
215+
You can set the log level by either:
213216

214-
A reporter (class or object) exposes `log(logObj)` method.
215-
To get more info about how to write your own reporter, take a look into the linked implementations above.
217+
- Passing `level` option to `createConsola`
218+
- Setting `consola.level` on instance
219+
- Using the `CONSOLA_LEVEL` environment variable (not supported for browser and core builds).
216220

217-
## Types
221+
## Log Types
218222

219-
Types are used to actually log messages to the reporters.
220-
Each type is attached to a _logging level_.
223+
Log types are exposed as `consola.[type](...)` and each is a preset of styles and log level.
221224

222-
A list of all available default types is [here](./src/types.ts).
225+
A list of all available built-in types is [available here](./src/constants.ts).
223226

224227
## Creating a new instance
225228

0 commit comments

Comments
 (0)