Get log with winston log

Thomas Cerqueira 0 Reputation points
2023-07-25T17:41:36.3066667+00:00

Hi, I'm quite new to Azure and I want to know if it's possible to do this:

I have my NodeTs on azure and logging with winston:

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.json(),
  ),
  transports: [
    new DailyRotateFile({
      filename: 'logs/application-%DATE%.log',
      datePattern: 'YYYY-MM-DD',
      zippedArchive: true,
      maxSize: '20m',
      maxFiles: '14d',
    }),
	new winston.transports.Console({
       format: winston.format.simple()
     }),
	new winston.transports.File({
       filename: 'app.log'
     })
  ],
});

I want to know if there is a way to get the log from winston to be sorted as this:

User's image

I'm a beginner so please don't be mean, I have search the documentation for a while but can't get the right thing.....

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,647 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2023-08-01T18:42:12.0033333+00:00

    @Thomas Cerqueira Logging in Azure Functions happens in the runtime, which is a C# ASP.NET Application of its own. JavaScript Functions (and other non-C# languages) run in a worker process that runs alongside the core runtime.

    The runtime is already instrumented to push metrics and logs into Azure Application Insights once configured, and with it you get the view that you have shared. This is the recommended approach for most function apps.

    But you are still free to use your own logging mechanisms as required. In the case of winston, the current setup you have writes to files which are not persisted.

    Instead, you should use a transport like this one (not an official Microsoft package FYI) which pushes the logs to Azure Application Insights for example. If you have other logging backends in place, you will have to use a transport built for that backend.

    While I would not recommend it, if you still require logging to files, you could consider using a Linux function app and mount file shares to it, and direct logs to there.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.