This guide explains how the backend system logger is configured and what each setting changes at runtime.Documentation Index
Fetch the complete documentation index at: https://docs.xpertai.cn/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The current logger is built onnestjs-pino and pino.
- HTTP request logs and Nest application logs go through the same logger pipeline.
- Logs are written to the console and to a rotating file at the same time.
- In non-production environments the console output is prettified with
pino-pretty. - In production the console output stays as structured JSON on
stdout. - The default log file is
xpert-server.log.
Configuration
| Variable | Default | Description |
|---|---|---|
NODE_ENV | development | Controls console formatting. production keeps JSON output on stdout; other values use pretty single-line output. |
LOG_LEVEL | log | Base log level. Nest-style values are mapped to pino levels: verbose -> trace, debug -> debug, log -> info, warn -> warn, error -> error, fatal -> fatal. Direct pino levels such as trace, info, fatal, and silent also work. |
LOG_FILE_PATH | unset | Full path of the active log file. When set, it takes precedence over LOG_DIR. |
LOG_DIR | <process.cwd()>/logs | Log directory used when LOG_FILE_PATH is not set. The active file name is xpert-server.log. |
LOG_FILE_MAX_SIZE | 10m | Maximum size of the active log file before rotation. Supported units: b, k, kb, m, mb, g, gb. |
LOG_FILE_MAX_FILES | 5 | Total number of files kept, including the active file. |
Output behavior
Console
NODE_ENV=production: raw JSON logs are written tostdout.- Any other environment: logs are colorized, flattened to one line, and formatted with readable timestamps.
File
- File logs are always written as structured JSON.
- The destination directory is created automatically when needed.
- The logger opens the file in append mode, so restarts continue writing to the same active file.
- Path resolution follows this order:
LOG_FILE_PATH->LOG_DIR/xpert-server.log-><process.cwd()>/logs/xpert-server.log.
Rotation behavior
- Rotation happens before a write that would push the active file past
LOG_FILE_MAX_SIZE. - Rotated files are named like
xpert-server.log.1,xpert-server.log.2, and so on. LOG_FILE_MAX_FILES=5means 1 active file plus 4 backups.LOG_FILE_MAX_FILES=1keeps no backup files and replaces the active file on each rotation.
Request metadata and safety
Each request log is enriched with:service: xpert-serverenvtraceparenttracestate
- Reuses
x-request-idonly when the incoming header is a valid UUID. - Generates a new UUID when the request does not provide a valid request id.
- Returns the final request id in the response header
x-request-id. - Skips automatic access logging for
/healthand/api/health. - Redacts sensitive fields with
[Redacted].
req.headers.authorizationreq.headers.cookiereq.headers["x-api-key"]req.body.passwordreq.body.tokenreq.body.accessTokenreq.body.refreshToken
Bootstrap integration
The logger is wired into Nest during bootstrap:providePinoLoggerModule()registers the pino HTTP logger.app.useLogger(app.get(Logger))makes Nest use the pino-backed logger.NestLogger.overrideLogger(resolveNestLogLevels())keeps Nest log filtering aligned withLOG_LEVEL.
Recommended examples
Use a directory-based configuration:LOG_FILE_PATH is set, LOG_DIR is ignored.
Relevant source files
xpert/packages/server/src/logger/pino-logger.tsxpert/packages/server/src/logger/pino-rotating-file.stream.tsxpert/packages/config/src/environments/ienvironment.tsxpert/packages/server/src/bootstrap/index.ts