foreversd / forever

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)
http://github.com/foreverjs/forever
MIT License
13.87k stars 946 forks source link

Add Winston config option to prevent stray 'undefined' in output #1130

Open MatrixFrog opened 2 years ago

MatrixFrog commented 2 years ago

issue reported here: https://github.com/foreversd/forever/pull/1128#issuecomment-1025476725

mmrwoods commented 2 years ago

Thanks @MatrixFrog, this does remove the undefined from the output, but unfortunately doesn't solve the incompatibility with forever-service because Winston v3 also colorizes output by default (so the sed command to find the service status still fails).

Changing the format from winston.format.cli() to winston.format.simple() seems to work perfectly though, it removes the colors and generates output compatible with forever-service :-)

I guess to fix this properly, you'd have to check if the forever cli arguments --plain or --no-color were passed and use the appropriate format.

mmrwoods commented 2 years ago

FWIW, this addition solves the problem. I don't like it because of the need to require winston within cli.js, but as a PoC it does work...

diff --git a/lib/forever/cli.js b/lib/forever/cli.js
index d63163a..7d6a506 100644
--- a/lib/forever/cli.js
+++ b/lib/forever/cli.js
@@ -16,6 +16,7 @@ var fs = require('fs'),
     prettyjson = require('prettyjson'),
     clone = require('clone'),
     objectAssign = require('object-assign'),
+    winston = require("winston"),
     forever = require('../forever');

 var cli = exports;
@@ -627,6 +628,7 @@ cli.start = function () {
   //
   if ((typeof app.argv.colors !== 'undefined' && !app.argv.colors) || app.argv.plain) {
     colors.mode = 'none';
+    forever.log.format = winston.format.simple();
   }

   if (app.config.get('help')) {
MatrixFrog commented 2 years ago

feel free to update this PR with whatever changes you would like