Winston <> AWS Cloudwatch log stream name

207 Views Asked by At

so i am using winston and winston-aws-coudwatch npm packages for logging. I have successfully been. able to log to cloudwatch to a particular logstream which is generated by the Date package.
Now what I want to achieve is if the day changes, a new stream should be created automatically. I have a logger.js file where I initiate the winston logger and export it

logger.add(new WinstonCloudWatch({
        logGroupName: 'testing',
        logStreamName: new Date().toISOString().split('T')[0],
        createLogGroup: true,
        createLogStream: true,
        awsConfig: {
            awsAccessKeyId: process.env.AWS_CLOUDWATCH_ACCESS_KEY,
            awsSecretKey: process.env.AWS_CLOUDWATCH_SECRET_KEY,
            awsRegion: process.env.AWS_REGION,
        },
        formatLog: (item) => JSON.stringify({
            timestamp: item.meta.timestamp,
            method: item.meta.method,
            url: item.meta.url,
            status: item.meta.status,
            content_length: item.meta.content_length,
            response_time: item.meta.response_time,
            level: item.level,
            message: item.message,
            stack: item.meta.stack,
        }),
    }));

How do i make it that as soon as the clock hits 12am, it creates a new stream and not write on the same older stream

0

There are 0 best solutions below