Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs about raw method #271

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -225,6 +225,17 @@ Log types are exposed as `consola.[type](...)` and each is a preset of styles an

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

## Raw output

Objects sent to reporter by logging them could lead to unexcepted output when object is close to internal object structure ([see how consola consider object as non-conflictual](https://github.com/unjs/consola/blob/ce2b368f43813aa95e54d6124425b1c6badc087e/src/utils/log.ts#L5)).
To enforce the object to be interpreted, you can use the `raw` method chained to any log type.

See [examples/raw.ts](./examples/raw.ts).

> [!NOTE]
> As his usage is mostly for an advanced usage of consola and for debugging, the `raw` method could be change in future


## Creating a new instance

Consola has a global instance and is recommended to use everywhere.
Expand Down
9 changes: 9 additions & 0 deletions examples/raw.ts
@@ -0,0 +1,9 @@
import { consola } from "./utils";

async function main() {
consola.log({ foo: 'bar' })
consola.log({ foo: 'bar', args: [ { hello: 'world' }] })

consola.log.raw({ foo: 'bar' })
consola.log.raw({ foo: 'bar', args: [ { hello: 'world' }] })
}