Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minddocdev/nest-express-winston
Implementation of a nestjs logger using winston and express-winston
https://github.com/minddocdev/nest-express-winston
express-winston logging nestjs winston
Last synced: 3 months ago
JSON representation
Implementation of a nestjs logger using winston and express-winston
- Host: GitHub
- URL: https://github.com/minddocdev/nest-express-winston
- Owner: minddocdev
- License: mit
- Archived: true
- Created: 2020-02-04T10:57:58.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-17T21:25:55.000Z (over 3 years ago)
- Last Synced: 2024-09-24T22:45:00.523Z (4 months ago)
- Topics: express-winston, logging, nestjs, winston
- Language: TypeScript
- Size: 2.1 MB
- Stars: 2
- Watchers: 6
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nest-express-winston
Implementation of a NestJS logger using `winston` and `express-winston`. It replaces the default
NestJS logger with `winston`, and optionally also adds express logs using `express-winston`.## Installation
```bash
yarn add @minddoc/nest-express-winston
```## Usage
```typescript
import {
createExpressWinstonHandler,
createNestWinstonLogger,
httpContextMiddleware,
requestIdHandler,
} from '@minddoc/nest-express-winston';
```### Basic Example
Add the following to your `index.ts` / `main.ts`:
```typescript
import 'dotenv/config';
import 'module-alias/register';
import 'reflect-metadata';import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';import {
createExpressWinstonHandler,
createNestWinstonLogger,
httpContextMiddleware,
requestIdHandler,
} from '@minddoc/nest-express-winston';import { AppModule } from './app.module';
import { EnvService } from './env';async function bootstrap() {
const nestWinstonLogger = createNestWinstonLogger('app');
const app = await NestFactory.create(AppModule, { logger: nestWinstonLogger });// Use express-winston for logging request information
const expressWinstonHandler = createExpressWinstonHandler(nestWinstonLogger.logger);
app.use(expressWinstonHandler);// Use express-http-context for context injection (request id)
app.use(httpContextMiddleware);
app.use(requestIdHandler);app.useGlobalPipes(new ValidationPipe());
app.setGlobalPrefix(EnvService.get().API_BASE_PATH);const options = new DocumentBuilder()
.setTitle('API')
.setDescription('Logging API Example')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);await app.listen(EnvService.get().API_PORT, EnvService.get().API_HOST);
}
bootstrap();
```## Contribution Guidelines
Never commit directly to master, create a new branch and submit a pull request.