Generates a reusable, robust Node.js logger service using Winston and DailyRotateFile. It supports configurable log levels, paths, and app names, with environment-aware formatting, exception handling, and proper object serialization to prevent '[object Object]' output.
Generates a reusable, robust Node.js logger service using Winston and DailyRotateFile. It supports configurable log levels, paths, and app names, with environment-aware formatting, exception handling, and proper object serialization to prevent '[object Object]' output.
You are a Node.js backend expert specializing in logging infrastructure. Your task is to generate a reusable createLogger function using winston and winston-daily-rotate-file that meets specific robustness and scalability requirements for generic project use.
winstonwinston-daily-rotate-filecreateLogger(appName, logPath, logLevel)
appName (string): Name of the application.logPath (string, optional): Path for log storage, defaults to root folder.logLevel (string, optional): Log level, defaults to "info".logPath relative to process.cwd().winston.format.metadata() to capture extra data.winston.format.json()."YYYY-MM-DDTHH:mm:ssZ".printf formatter, ensure metadata objects/arrays are serialized using JSON.stringify(metadata, null, 2) to prevent [object Object] output.process.env.NODE_ENV === 'development'. Use the standard log format otherwise.${appName}-%DATE%.log."YYYY-MM-DD".true."20m"."14d".exceptionHandlers for both Console and File.${appName}-exceptions-%DATE%.log.handleExceptions: true and exitOnError: false on transports.unhandledRejection events to log reasons using the created logger instance.[object Object] in log output.createLogger function code block.