@breadstone/archipel-platform-logging
v0.0.41
Published
Configurable logging module for NestJS applications with log-level management.
Readme
@breadstone/archipel-platform-logging
Configurable logging module for NestJS with log-level management, request-scoped context propagation, and structured logging.
Features
- Log-level management — Configurable via
APP_LOG_LEVELwith startup validation - Request context propagation —
RequestContextStore(AsyncLocalStorage-based) stores a per-requestrequestIdand optionaluserId - Request ID middleware —
RequestIdMiddlewareextracts or generates ax-request-idheader and wraps the request in a context store - Structured logger —
ContextLoggerenriches every log entry with the current request context automatically
⚠️ Environment Variables
| Variable | Required | Default | Description |
| --------------- | -------- | ------- | ------------- |
| APP_LOG_LEVEL | no | warn | Logging level |
Startup validation: The module validates
APP_LOG_LEVELat initialization. If the value is not one ofdebug,info,warn, orerror, the module logs a warning and falls back towarn.
Quick Start
import { LoggerModule } from '@breadstone/archipel-platform-logging';
import { RequestIdMiddleware } from '@breadstone/archipel-platform-logging';
// 1. Import the module
@Module({
imports: [LoggerModule],
})
export class AppModule implements NestModule {
// 2. Apply the request ID middleware
public configure(consumer: MiddlewareConsumer): void {
consumer.apply(RequestIdMiddleware).forRoutes('*');
}
}// 3. Use ContextLogger in services
import { ContextLogger } from '@breadstone/archipel-platform-logging';
@Injectable()
export class OrderService {
private readonly _logger = new ContextLogger(OrderService.name);
public async placeOrder(dto: CreateOrderDto): Promise<void> {
this._logger.log('Placing order', { orderId: dto.orderId });
// Log output automatically includes requestId + userId
}
}Peer Dependencies
| Package | Required | Notes |
| ---------------- | -------- | ---------------------------------------- |
| @nestjs/common | Yes | NestJS core |
| express | Yes | Required for RequestIdMiddleware types |
Documentation
📖 Package Docs: .docs/packages/platform-logging/index.md
Development
# Build
yarn nx build platform-logging
# Test
yarn nx test platform-logging
# Lint
yarn nx lint platform-logging