From 03fb0479c0c5389d2569d622b6bec188fcee0ad6 Mon Sep 17 00:00:00 2001 From: Lacey Pevey <7490308+pevey@users.noreply.github.com> Date: Sun, 6 Aug 2023 07:14:49 -0600 Subject: [PATCH] feat(medusa): Allow logging to file (#4696) * enable additional log transport to file if FILE_NAME env var is set * change var declaration to const * Create chilly-geckos-look.md --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> --- .changeset/chilly-geckos-look.md | 6 ++++++ packages/medusa-cli/src/reporter/index.ts | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changeset/chilly-geckos-look.md diff --git a/.changeset/chilly-geckos-look.md b/.changeset/chilly-geckos-look.md new file mode 100644 index 0000000000..ada47fab7f --- /dev/null +++ b/.changeset/chilly-geckos-look.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa": patch +"@medusajs/medusa-cli": patch +--- + +Feat/allow logging to file diff --git a/packages/medusa-cli/src/reporter/index.ts b/packages/medusa-cli/src/reporter/index.ts index 7ed1bd2e3c..cea2fda23d 100644 --- a/packages/medusa-cli/src/reporter/index.ts +++ b/packages/medusa-cli/src/reporter/index.ts @@ -8,6 +8,7 @@ import { panicHandler } from "./panic-handler" import * as Transport from "winston-transport" const LOG_LEVEL = process.env.LOG_LEVEL || "silly" +const LOG_FILE = process.env.LOG_FILE || "" const NODE_ENV = process.env.NODE_ENV || "development" const IS_DEV = NODE_ENV.startsWith("dev") @@ -26,6 +27,14 @@ if (!IS_DEV) { ) } +if (LOG_FILE) { + transports.push( + new winston.transports.File({ + filename: LOG_FILE + }) + ) +} + const loggerInstance = winston.createLogger({ level: LOG_LEVEL, levels: winston.config.npm.levels,