---
title: "Best practices"
description: "Write messages that group well and stay useful."
canonical_url: "https://docs.logstrace.dev/guides/sending-logs/best-practices"
---
# Best practices

> Write messages that group well and stay useful.

## Send objects, not sentences

The best shape is an object with an `event` name and one key per value. Every key becomes a named column right away, numbers stay numbers, and nothing depends on word order.

<code-group>

```json [Best]
{ "channel": "orders", "event": "order.paid", "orderId": "10293", "amount": 49.90, "currency": "USD", "method": "card" }
```

```json [Also works]
{ "channel": "orders", "text": "Order 10293 paid 49.90 USD by card" }
```

</code-group>

- Use one `event` name per kind of thing that happened (`order.paid`, `user.signup`), not per value.
- Keep the same keys for the same event; a new or missing key starts a new table. Send `null` instead of leaving a key out.
- Keep long free text (error messages, stack traces) in `data`, not as top-level fields.

The rest of this page is for plain messages.

## Keep the sentence fixed, put values in it

LogsTrace groups messages by their fixed words. Write the same sentence each time and let only the values change.

<code-group>

```text [Good]
Order 10293 paid 49.90 USD by card
Order 10294 paid 12.00 USD by wallet
```

```text [Avoid]
Order 10293 was paid (49.90 USD) using a card
Paid! order=10294 amount=12.00USD method=wallet
```

</code-group>

## Put each value in its own word

`amount=49.90` is one word, so the column holds `amount=49.90` instead of a number you can total. Write `amount 49.90`, or just `49.90`.

## Keep the word count stable

Messages with a different number of words go to different tables. Put variable-length text (user input, error messages, stack traces) **at the end** or in `data`:

```json
{ "text": "Job 551 failed after 3 attempts", "level": "error",
  "data": { "error": "connect ECONNREFUSED 10.0.0.5:5432", "stack": "…" } }
```

## Use one channel per area

`orders`, `payments`, `auth`. Not one channel per user or per request: that splits every table. See [Channels](https://docs.logstrace.dev/guides/sending-logs/channels).

## Don't log secrets

Masking hides IPs, emails and common token shapes from viewers, but admins and owners still see them. Never send passwords, full card numbers or private keys. See [Masking](https://docs.logstrace.dev/guides/teams/masking).

## Batch and don't block

Send in the background, in batches, and never let a logging failure break your app. See [Batching](https://docs.logstrace.dev/guides/sending-logs/batching).


## Sitemap

See the full [sitemap](https://docs.logstrace.dev/sitemap.md) for all pages.
