D
D
D_E_S2017-05-29 10:05:05
Node.js
D_E_S, 2017-05-29 10:05:05

How to use Winston to specify the path of the executable file in the console?

How to get the path of the current executable where message was assigned. It is currently displaying itself.

let logger = new (winston.Logger)({
    transports: [
        new winston.transports.Console({ level: config.get("LOGGER_LEVEL"),timestamp: function () {
            return moment().format('HH:mm:ss');
        },formatter: function(options) {
            let path = module.filename.split('/').slice(-2).join('/');
            return options.timestamp() + ' - ' +  options.level+': '+options.message +
                "\n\r" + path;
        },colorize: true}),
        new winston.transports.File({ filename: './log/server.log', level: 'verbose',timestamp: function () {
            return moment().format('YYYY-MM-DD HH:mm:ss')
        } })
    ]
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
de1m, 2017-05-29
@de1m

The question is not entirely clear, as I understand it, you want to get the path to the * .js file that is once executed.

var path = require('path');
...
var scriptdir = path.dirname(process.argv[1]); //get dir of scripts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question