0

I am trying to upload my logs in the azure storage. I used the winstonAzureBlob library. But I am getting this error 'TS2740: Type 'WinstonAzureBlob' is missing the following properties from type 'TransportStream': writable, writableEnded, writableFinished, writableHighWaterMark, and 32 more.
ERROR in ./libs/server/shared/logger/src/lib/logger.util.ts:13:9 TS2740: Type 'WinstonAzureBlob' is missing the following properties from type 'TransportStream': writable, writableEnded, writableFinished, writableHighWaterMark, and 32 more.'

This worked fine in another new project that I made. When I use the code in my original project, I always have this error.

import * as winston from 'winston';
import { winstonAzureBlob } from 'winston-azure-blob';
import { utilities as nestWinstonModuleUtilities, WinstonModule } from 'nest-winston';

async function bootstrap() {
    const formatter= winston.format.combine(
        winston.format.timestamp(),
        winston.format.printf(({ level, message, timestamp }) => {
            return `${timestamp} [${level.toUpperCase()}]: ${message}`;
        }),
    );
    const app = await NestFactory.create(
        AppModule.forRoot({
            providers: [...environment.storage.providers()],
        }),
        {logger:WinstonModule.createLogger({
            levels: winston.config.syslog.levels,
            level: 'info',
            format: formatter,
            transports: [
                new winston.transports.Console({format:nestWinstonModuleUtilities.format.nestLike()}),
                winstonAzureBlob({
                    account: {
                        connectionString: "DefaultEndpointsProtocol=https;AccountName=logstestss;AccountKey=<myaccountkey>;EndpointSuffix=core.windows.net",
                    },
                    blobName: "logs.log",
                    bufferLogSize: 1,
                    containerName: "logs",
                    level: 'info',
                    rotatePeriod: "YYYY-MM-DD",
                    syncTimeout: 0,
                })
            ],
       })
    });

I tried using another library, import { winstonAzureBlob } from 'winston3-azureblob-transport';. It still gives the same error as before with the missing properties.

1 Answers1

0
  • The error you are encountering is due to version incompatibility between the Winston-azure-blob library and the Winston package. Installed packages from this reference.

npm install winston winston-azure-blob

npm install winston winston-azure-blob @nestjs/core --save

// logger.service.ts

import { Injectable } from '@nestjs/common';
import * as winston from 'winston';
import { winstonAzureBlob } from 'winston-azure-blob';

@Injectable()
export class LoggerService {
  private readonly logger = winston.createLogger({
    format: winston.format.combine(
      winston.format.timestamp(),
      winston.format.splat(),
      winston.format.json()
    ),
    transports: [
      winstonAzureBlob({
        account: {
          connectionString: "DefaultEndpointsProtocol=https;AccountName=logstestss;AccountKey=<myaccountkey>;EndpointSuffix=core.windows.net",
        },
        blobName: "logs.log",
        bufferLogSize: 1,
        containerName: "logs",
        level: "info",
        rotatePeriod: "YYYY-MM-DD",
        syncTimeout: 0,
      }),
    ],
  });

  log(message: string) {
    this.logger.info(message);
  }

  error(message: string) {
    this.logger.error(message);
  }

  warn(message: string) {
    this.logger.warn(message);
  }
}
// app.controller.ts

import { Controller, Get, Logger } from '@nestjs/common';
import { LoggerService } from './logger.service';

@Controller()
export class AppController {
  private readonly logger = new Logger(AppController.name);

  constructor(private readonly loggerService: LoggerService) {}

  @Get()
  getHello(): string {
    this.logger.log('Hello from NestJS Logger!');
    this.loggerService.log('This message is logged via winston-azure-blob');
    return 'Hello World!';
  }
}
// app.module.ts

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { LoggerService } from './logger.service';

@Module({
  imports: [],
  controllers: [AppController],
  providers: [AppService, LoggerService], // Add LoggerService here
})
export class AppModule {}

enter image description here

enter image description here

enter image description here

Sampath
  • 810
  • 2
  • 2
  • 13