# LogEntry

**Kind:** Interface

**Source:** [`packages/microservices/external/kafka.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/external/kafka.interface.ts#L626)

**Part of:** [Microservices](subsystem-packages-microservices)

`LogEntry` defines the structured payload used to represent a log message in the Kafka microservices integration. It combines routing and classification metadata (`namespace`, `level`, and `label`) with the actual logger content in `log`, enabling consistent log publishing and consumption across services.

## Properties

| Property | Type |
|---|---|
| `namespace` | `string` |
| `level` | `logLevel` |
| `label` | `string` |
| `log` | `LoggerEntryContent` |

## Diagram

```mermaid
graph LR
  A[Application or Microservice] --> B[LogEntry]
  B --> C[namespace: string]
  B --> D[level: logLevel]
  B --> E[label: string]
  B --> F[log: LoggerEntryContent]
  B --> G[Kafka Logging Pipeline]
```

## Usage

```ts
import type { LogEntry } from './kafka.interface';

const logEntry: LogEntry = {
  namespace: 'payments-service',
  level: 'error',
  label: 'payment-processing',
  log: {
    message: 'Failed to process payment',
    transactionId: 'txn_12345',
    error: 'Card authorization declined',
  },
};

// Example: send the structured entry through a Kafka producer.
await kafkaProducer.send({
  topic: 'service-logs',
  messages: [{ value: JSON.stringify(logEntry) }],
});
```

## AI Coding Instructions

- Populate `namespace` with a stable service or application identifier so consumers can filter logs reliably.
- Use valid `logLevel` values rather than arbitrary strings when setting `level`.
- Keep `label` concise and action-oriented, such as `database-query` or `payment-processing`.
- Store structured context in `log` instead of serializing important metadata into a message string.
- Preserve the full `LogEntry` shape when publishing to or consuming from Kafka topics.
