Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 8, 2024
1 parent 9d6dfb0 commit 62c35cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,17 @@ const { stripAnsi } = require("consola/utils");

## Raw logging methods

In rare conditions, Objects sent to the reporter could lead to unexpected output when object is close to internal object structure having both `message` and `args` props. To enforce the object to be interpreted as pure object, you can use the `raw` method chained to any log type.
Objects sent to the reporter could lead to unexpected output when object is close to internal object structure containing either `message` or `args` props. To enforce the object to be interpreted as pure object, you can use the `raw` method chained to any log type.

See [examples/raw.ts](./examples/raw.ts).
**Example:**

```js
// Prints "hello"
consola.log({ message: "hello" });

// Prints "{ message: 'hello' }"
consola.log.raw({ message: "hello" });
```

> [!NOTE]
> As his usage is mostly for an advanced usage of consola and for debugging, the `raw` method could be change in future.
Expand Down
12 changes: 6 additions & 6 deletions examples/raw.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { consola } from "./utils";

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

consola.log.raw({ foo: "bar" });
consola.log.raw({ foo: "bar", args: [{ hello: "world" }] });
}
consola.log('consola.log.raw({ message: "hello" })');
// Prints "{ message: 'hello' }"
consola.log.raw({ message: "hello" });

Check warning on line 9 in examples/raw.ts

View check run for this annotation

Codecov / codecov/patch

examples/raw.ts#L2-L9

Added lines #L2 - L9 were not covered by tests

0 comments on commit 62c35cb

Please sign in to comment.