coreybutler / node-windows

Windows support for Node.JS scripts (daemons, eventlog, UAC, etc).
Other
2.8k stars 356 forks source link

Where are winston log files kept when running as a windows service? #176

Closed DrYSG closed 7 years ago

DrYSG commented 7 years ago

I have been using the winston log service to write log files to the console and to at file (zipped archive). https://github.com/winstonjs/winston. This has all been working fine, since when the app is started with the command $node app.js, and it puts everything in the current folder.

The issue is that that I need to run the node program as windows service, which creates a /deamon/ folder and runs a EXE from that folder which wraps node.exe and runs the application from the /deamon/folder. I am creating the service with the node-windows tool: (https://github.com/coreybutler/node-windows ) and directing the console messages (stdout) to a file (which I do see being created and filled). But the .gz log files are nowhere to be found. Any idea where they might be?

This how I configure the logger:

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.Console)({
            colorize: true,
            timestamp: true,
            prettyPrint: true
        }
        ),
        new (winston.transports.File)({
            colorize: false,
            timestamp: true,
            filename: logfile,
            maxsize: 50 * 1024,
            maxFiles: 10,
            prettyPrint: true,
            zippedArchive: true
        })
    ]
});
``

and this is how I start the service with node-windows

const watsonApp = path.join(__dirname, "..", "..", "..", "Watson", "app.js") let svc = new Service({ name: 'EGPL Watson Service', description: 'The Watson Web Service', script: watsonApp, env: { name: "NODE_ENV", value: process.env["NODE_ENV"] } });

exports.setup = function () { global.DASH.stats.watsonInstalled = svc.exists };

exports.install = function (cb) { if (svc.exists) return; svc.on('install', () => { global.DASH.stats.watsonInstalled = svc.exists; cb(null) return }) svc.on('error', () => { err = new Error('svc install error') err.description = 'svc install error' + "\n" + err.message cb(err) return }) svc.on('invalidinstallation ', () => { err = new Error('svc invalidinstallation') err.description = 'svc iinvalidinstallation' + "\n" + err.message cb(err) return }) svc.install() }

coreybutler commented 7 years ago

Please see the wiki.

Your log file is most likely in the daemon directory. I suspect your code is using relative paths instead of absolute paths. Use process.cwd() instead of __dirname... specifically when defining the path to your winston logfile attribute.

DrYSG commented 7 years ago

@coreybutler well, as I said, only the data dumping to the console is there. What winston allows is to fork the output and put it both in a file (zipped in this case) and put the output to the console. So yes, I see the console output (but not the log being written to the file) [And my winston is configured to rotate the log files with the 10 most recent files being kept). Which is why I would rather not just get the console output. (besides it has lots of color escape codes).

coreybutler commented 7 years ago

Right - my point was the path to your log file needs to be identified with an absolute path.

const watsonApp = path.join(__dirname, "..", "..", "..", "Watson", "app.js")

probably needs to be

const watsonApp = path.join(process.cwd(), "..", "..", "..", "Watson", "app.js")