Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger prints/output only first argument in v 3.2.0 #1614

Open
2 tasks
sujithkris opened this issue Mar 7, 2019 · 7 comments
Open
2 tasks

logger prints/output only first argument in v 3.2.0 #1614

sujithkris opened this issue Mar 7, 2019 · 7 comments

Comments

@sujithkris
Copy link

sujithkris commented Mar 7, 2019

Environment

Problem

logger.info('First', 'Second') is printing only First in the console and in File.
With 3.0, this is printing both arguments, First & Second. (Second in the new line)

What do you expect to happen instead?

Expecting output as
First Second

@DABH
Copy link
Contributor

DABH commented Mar 11, 2019

What formatters and other config are you using? In particular, handling of splats/metadata has changed from 3.0 to 3.2.

@sujithkris
Copy link
Author

sujithkris commented Mar 13, 2019

@DABH Can I get to see the change details w.r.t 3.2 ?
Below is the custom formatter function ___f__ and usage.

const ___f__ = winston.format.printf(info => {
    let log = '[Process : ' + process.pid + ' AT : ' + info.timestamp + '] ' + info.level + ' :  ' + (undefined !== info.message ? info.message : '');
    if(info.meta){
        log += '\n' + util.inspect(info.meta);
    }
    return log; 
});

........
........

winston.createLogger({
	level: 'debug',
	transports : {transports}
	exitOnError :  false,
	format: winston.format.combine(
		winston.format.timestamp(),
		winston.format.splat(),
		___f__
	),
	timestamp : {dateFormatterFunction}
});

@DABH
Copy link
Contributor

DABH commented Mar 24, 2019

You could log like logger.info(['First', 'Second']) if you need that kind of call. Generally winston isn't really designed for that call style; for the leveled log methods, the first param is a string message, and all other params are treated as splats/metas.

That being said, I think winstonjs/logform#85 with the metadataArray might help achieve what you want. I can leave this issue open till that gets merged.

@robertsLando
Copy link

robertsLando commented Apr 10, 2019

I think this is such a breaking change...

The partial solution is:

const wrapper = ( original ) => {
    return (...args) => {
      for (let index = 0; index < args.length; index++) {
        if(args[index] instanceof Error){
          args[index] = args[index].stack
        }
      }
      original(args.join(" "))
    }
};

logger.error = wrapper(logger.error);
logger.warn = wrapper(logger.warn);
logger.info = wrapper(logger.info);
logger.verbose = wrapper(logger.verbose);
logger.debug = wrapper(logger.debug);
logger.silly = wrapper(logger.silly);

@oakfire
Copy link

oakfire commented May 16, 2019

You could log like logger.info(['First', 'Second']) if you need that kind of call. Generally winston isn't really designed for that call style; for the leveled log methods, the first param is a string message, and all other params are treated as splats/metas.

That being said, I think winstonjs/logform#85 with the metadataArray might help achieve what you want. I can leave this issue open till that gets merged.

But util.format('First', 'Second') will output First Second, the same as console.log and winston@2. Why winston@3 with format splat break this behavior?

@thatmatthewxu
Copy link

thatmatthewxu commented Jun 12, 2019

I think this is such a breaking change...

The partial solution is:

const wrapper = ( original ) => {
    return (...args) => {
      for (let index = 0; index < args.length; index++) {
        if(args[index] instanceof Error){
          args[index] = args[index].stack
        }
      }
      original(args.join(" "))
    }
};

logger.error = wrapper(logger.error);
logger.warn = wrapper(logger.warn);
logger.info = wrapper(logger.info);
logger.verbose = wrapper(logger.verbose);
logger.debug = wrapper(logger.debug);
logger.silly = wrapper(logger.silly);

agree, it's the break change.

the meta key in the info object is gone under the new version.
the new key named as the numeric, such as { '0': 'string', '1': 'object'}

@chrisblossom
Copy link

chrisblossom commented Jun 12, 2019

Definitely a breaking change. Also the wrapper works in a very limited way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants