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

TypeError: cleanedMessage.substring is not a function #73

Open
shuat opened this issue May 27, 2019 · 6 comments
Open

TypeError: cleanedMessage.substring is not a function #73

shuat opened this issue May 27, 2019 · 6 comments

Comments

@shuat
Copy link

shuat commented May 27, 2019

It seems that this transport does not allow for logging of objects. Winston which this is built for allows logging of object and so does console.log.

@schfkt
Copy link
Collaborator

schfkt commented May 27, 2019

@shuat can you show an example (I mean the code that fails) how you log an object using this transport? So that I can quickly see what's the issue.

@schfkt
Copy link
Collaborator

schfkt commented May 27, 2019

@shuat AFAIK, it's possible to log objects with this transport, but an object must have some certain fields (message, etc.). See: https://github.com/namshi/winston-graylog2#upgrading-from-earlier-versions-of-winston-graylog2

logger.info({ message: 'this is an info message', answer: 42 });
// or equivalently
logger.info('this is an info message', { answer: 42 });

@Caperious
Copy link

I have the same error and no idea how to resolve it or why it occurs..

@harishgupta42
Copy link

harishgupta42 commented Sep 10, 2020

I'm facing same error while using following code:

const loggerFormat = printf(({ level, message, label, timestamp, meta }) => {
   return `${timestamp} [${label}] ${level}: ${message} ${meta ? meta : ''} `
})
const logger = winston.createLogger({
   exitOnError: false,
   format: combine(format.colorize(), format.json(), format.prettyPrint(), format.metadata(), label({ label: process.env.NODE_ENV || `localhost` }), timestamp(), loggerFormat),
   transports: [
      new transports.Console({
         level: 'debug', // Debug messages will be
         handleExceptions: true
      })
   ]
})

@bwgz
Copy link

bwgz commented Apr 30, 2022

I think I know the problem. The winston-graylog2 code does this ...

log(info, callback) {
  const {message, level, metadata} = info;
  const meta = Object.assign({}, metadata, this.staticMeta);
  const cleanedMessage = message || '';
  const shortMessage = cleanedMessage.substring(0, 100);

If message is an object and not a string then cleanedMessage.substring(0, 100) is going to fail. Looks to me the code assumes the message will be a string or undefined. It could check if the message is an object and then deal with that differently.

@GabrielScotaCTF
Copy link

I think I know the problem. The winston-graylog2 code does this ...

log(info, callback) {
  const {message, level, metadata} = info;
  const meta = Object.assign({}, metadata, this.staticMeta);
  const cleanedMessage = message || '';
  const shortMessage = cleanedMessage.substring(0, 100);

If message is an object and not a string then cleanedMessage.substring(0, 100) is going to fail. Looks to me the code assumes the message will be a string or undefined. It could check if the message is an object and then deal with that differently.

I try to send a logger.info({'hello': 123}), just to test it and you are right, it fails with the exactly error on issue name. As a work around, I just check my messages type, and if is an object I convert it using JSON.stringify(message)

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