Home > Software design >  No winston log files are created during pre-run check
No winston log files are created during pre-run check

Time:01-26

I have a typescript project using winston and winston-daily-rotate-file. At the start of the project I check for environment variables that are present. If not, I want to log the missing variable using logger.error(). But for some reason the error log is never created. The logs do appear in my console.

Note:

The logger and function to check environment variables come from a custom npm module, because I want to reuse this logic for all other projects of mine. So the logger is actually placed in node_modules/my-custom-project/util/logger.ts

Console output:
yarn run v1.22.19
$ ts-node src/index.ts
Debugger attached.
info: Starting project Test {"timestamp":"2023-01-19T07:49:53.342Z","type":"start-project"}
error: Missing environment variable DEFAULT_REQUIRED_VARIABLE {"timestamp":"2023-01-19T07:49:53.348Z"}
error: Exiting because of missing environment variables {"data":["DEFAULT_REQUIRED_VARIABLE"],"timestamp":"2023-01-19T07:50:05.447Z"}
node_modules/my-custom-project/util/logger.ts
import * as winston from "winston";
import DailyRotateFile from "winston-daily-rotate-file";

const infoTransport: DailyRotateFile = new DailyRotateFile({
  level: "info",
  filename: "./logs/           
  • Related