Sending logs to graylog using node-graylog2 (Node.js)

Hi, I just recently tried your package with the following code snippet:

const graylog2 = require("graylog2");

const logger = new graylog2.graylog({
    servers: [
        { "host": "52.136.248.240", port: 8514 }
    ],
    // hostname: "test.name", // the name of this host
    // (optional, default: os.hostname())
    facility: "Banana.js",     // the facility for these log messages
    // (optional, default: "Node.js")
    // bufferSize: 1350         // max UDP packet size, should never exceed the
    // MTU of your system (optional, default: 1400)
});

logger.on("error", function (error) {
    console.error("Error while trying to write to graylog2:", error);
});

logger.log("InvalidChecksum", JSON.stringify({ name: "Error", message: "The packet is corrupted. CRC-16-IBM not matching.", info: 1 }));

logger.close(function(){
    console.log('All done - cookie now?');
    process.exit();
});

So, as you can see, there are several things I ought to expect when check the graylog logs, like for example, the facility being “Banana.js”.

This however, is not the case. graylog2 seems to be unable to understand my log, and parses everything as a single string. I have attached a screenshot that exemplifies this:

From the image, you can see that a few things are not quite right:

  1. facility is Unknown
  2. level is -1
  3. If show the column “Full message”, it will be empty

The package is widely used, so I suppose this is a configuration issue.

  1. Am I missing something in my small code snippet?
  2. Is there any graylog2 configuration I need to make?

You’re sending GELF messages to a Plaintext or Syslog input. I’d suggest sending GELF messages to a GELF input. :wink:

AHhh… Right!
How do I do that exactly? Am I missing any parameters in the code?

You have to create a GELF input in Graylog and send the messages to that input.

Ha!, Thanks for the tip!
I sure wish there was more documentation regarding Node.js applications for Graylog. Good thing the interface is not that hard to figure out!

I searched for beginner tutuorials regarding graylog but I was quite overwhelmed. If you have any suggestions feel free!

I will now close the discussion. Thanks for hopping in!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.