Coder Social home page Coder Social logo

node-graylog2's Introduction

node-graylog2

NPM version NPM license

Graylog2 client library for Node.js, based on node-graylog. This has been heavily modified to the point where there is not much left of the original; however, this library should still be compatible with the old one, except for configuration and the GLOBAL function setup (some optional arguments in logging calls are not supported; they will be logged as additional data).

** New: ** Chunked GELF is now supported.

Synopsis

Available functions

  • graylog.emergency
  • graylog.alert
  • graylog.critical
  • graylog.error
  • graylog.warning
  • graylog.notice
  • graylog.info
  • graylog.debug

Code snippets

var graylog2 = require("graylog2");
var logger = new graylog2.graylog({
    servers: [
        { 'host': '127.0.0.1', port: 12201 },
        { 'host': '127.0.0.2', port: 12201 }
    ],
    hostname: 'server.name', // the name of this host
                             // (optional, default: os.hostname())
    facility: 'Node.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);
});

Short message:

logger.log("What we've got here is...failure to communicate");

Long message:

logger.log("What we've got here is...failure to communicate", "Some men you just can't reach. So you get what we had here last week, which is the way he wants it... well, he gets it. I don't like it any more than you men.");

Short with additional data:

logger.log("What we've got here is...failure to communicate", { cool: 'beans' });

Long with additional data:

logger.log("What we've got here is...failure to communicate", "Some men you just can't reach. So you get what we had here last week, which is the way he wants it... well, he gets it. I don't like it any more than you men.",
    {
        cool: "beans"
    }
);

Flush all log messages and close down:

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

Example

See test.js.

What is graylog2 after all?

It's a miracle. Get it at http://www.graylog2.org/

Installation

npm install graylog2

Graylog2 Configuration

This module will send its data as GELF packets to Graylog2. In order to see your data in the correct format you need to create a GELF Input in your Graylog2 application.

You can do this by following these instructions:

  1. Go to System -> Inputs
  1. Select a GELF Input type. In this case we will be using GELF UDP as it doesn't need any additional configuration.
  1. Select the Nodes that will read the new Input type.
  1. Launch the new input!

node-graylog2's People

Contributors

awojcicki avatar danlangford avatar egorfine avatar feliperoberto avatar meiremans avatar notslang avatar omrilotan avatar stelcheck avatar wellsjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-graylog2's Issues

Seems like error handling doesn't work

I am running this code:

var graylog2 = require("graylog2");

var logger = new graylog2.graylog({
    servers: [{ host: 'localhost', port: 9999 }]
});

logger.on('error', function (error) {
    console.log('Error:', error);
});

logger.emergency("App crashed");

logger.close(function(){
    console.log('All good, exiting');
    process.exit();
});

And I can set any random ip/port combination (even unreachable host) and it doesn't trigger errors at all, just 'All good, exiting'. Maybe I am doing something wrong or my expectations are wrong?

P.S. It would be good to indicate somewhere on front page that this library can be used only with UDP graylog inputs.

Uncaught TypeError: dgram.createSocket is not a function

I get this error. I use this library in vuejs.

Screen Shot 2021-04-01 at 13 00 25

// Main.js
const graylog2 = require("graylog2");
const logger = new graylog2.graylog({
  servers: [
    { 'host': {myHost}', port: {myPort} }
  ],
  hostname: 'myProjectName', // the name of this host
  // (optional, default: os.hostname())
  facility: 'Node.js',     // the facility for these log messages
  // (optional, default: "Node.js")
  bufferSize: 1400         // 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("Graylog test");

Can you help me solve the problem?

graylog not log if you are using with some keywords

graylog not log!
i am using graylog2 in several projects. nodeJS and meteorJS
but seems that some logs are missed!!
after a lot of headache we figured out exactly what was the problem.
in json object that we sent as detailes, we used with keywords from graylog for field names.
graylog don't log them! and not raised any error or warning!!!
it's crazy! how the developer can found this problem? and how he can know from which keywords he need to avoid??

for example: 'error', 'host' are keyword .
so if you write:

catch(ex){
   logger.error("error in registration", "an exception raised through registration process", {error: ex})
}

nothing log!!!

but if :

logger.error("error in registration", "an exception raised through registration process", {err: ex})

all it's ok!!!!

Optional console logging

Would be great if you could also console log messages during development so if you don't have access to graylog you can instantly get feedback without duplicating logging messages.

possible typo in graylog2.js line 118

line 112 - 121

var payload,
fileinfo,
that = this,
field = '',
message = {
version : '1.0',
118 -->> timestamp : (timestamp || new Date()).getTime() / 1000, <<--
host : this.hostname,
facility : this.facility,
level : level
};

No error message on connection error

It took us a while to figure out why our messages were not being logged.

Our GrayLog2 GELF port was firewalled, but we didn't receive any feedback at all. It would be great to have more reliable error messages.

Thanks!

not getting any error if graylog failure

i am not getting any error if gray log failure . this event listener is not working

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

How to log additional fields as standard?

I know we can log additional fields, using a parameter in the functions:
function (short_message, full_message, additionalFields, timestamp)

But I'd like to set an additional field at the initial configuration:

var logger = new graylog2.graylog({
    servers: [
        { 'host': '127.0.0.1', port: 12201 },
        { 'host': '127.0.0.2', port: 12201 }
    ],
    hostname: 'server.name', // the name of this host
                             // (optional, default: os.hostname())
    facility: 'Node.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)
   ///////////////additional field
   "_additionalField": "content"
}); 

Is it possible?

Attempt to send large message crashes application

Attempting to send a large message causes a problem in graylog2.js (167):

  if (chunkCount > 128) {
    return that.emit('error', new Error('Cannot log messages bigger than ' + (dataSize * 128) +  ' bytes'));
  }

This is causing my application to crash. Is it possible to log a warning, and continue the application? I don't want to have to wrap all my logging calls with exception handling.

zlib deflate results in a memory leak

This is a node issue, but your library uses zlib, and it causes a memory leak that has been crashing our docker containers on EC2. Unfortunately that means we can no longer use your library, and have to opt for another lib that doesn't use zlib.

It's really easy to recreate the issue:

let zlib = require('zlib');

let message = {
  some:"data"
};
let payload = new Buffer(JSON.stringify(message));

for(var i =0; i < 30000; ++i){
  zlib.deflate(payload, function (err, buffer) {
  });
}

setTimeout(()=>{}, 2000000);

Here's the related node issue:
nodejs/node#8871

Random EADDRINUSE errors when logging

Hi

I have a small problem with random crashes wit a EADDRINUSE error. The environment consists of multiple services run with pm2 and scripts started from cron. In both cases i see errors once or twice per day. The error is as below.

bind EADDRINUSE 0.0.0.0
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at dgram.js:221:18
    at _combinedTickCallback (internal/process/next_tick.js:77:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

I haven't been able to confirm it but from the dgram docs I think it might be solve by setting reuseAddr to true

Dont get errors

when i put wrong ip or port i dont get connection error, even graylog server gets down then also i dont get any error.. my requirement is to switch other logger server if graylog server is down or unable to connect but i dont get any error for it so i am unable to switch to other logger server. Please look into these issue

node-graylo2 not sending messages in correct format to Graylog2

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:

bug

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

I assume this is either a config issue, or the module is not communication correctly with graylog2.

on error does not get called if server is down

hello, i was assuming that if the graylog server was down , the on error would be called.
if the server is up, my messages are being sent correctly and can be seen on graylog
i am using version 0.1.3

this is my code snippet:

thanks for any help

var gl2 = new graylog2.graylog({
      servers: config.loggingService.graylog2.servers,       
      bufferSize: config.loggingService.graylog2.bufferSize   
    });
gl2.on('error', function (error) {
      console.error('Error while trying to write to graylog2:', error);
    });


How to log additional fields?

GELF documentation specifies that we can log additional fields by adding underscore before them. How can we do that in this library?

Not getting log in server and also not getting any error

Hi,

I am using below Code, but I am not getting logs in my server also I am not getting any Error in Node Console.

       `logMsg = "Some Random String";
        let logger = new graylog2.graylog({
        servers: [
            { 'host': 'XXX.XXX.XXX.XXX', port: 12201 }
        ],
        // hostname: 'server.name', // the name of this host
                                 // (optional, default: os.hostname())
        facility: 'MyAPP',     // 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.log("info", logMsg);`

Can someone please help me?

Logging error object fails

TypeError: Cannot read property 'split' of undefined
    at graylog.log [as _log] (/Users/.....node_modules/graylog2/graylog.js:146:34)
    at graylog.error (/Users/.....node_modules/graylog2/graylog.js:93:17)

Graylog code:

    } else if (short_message.stack && short_message.message) {

        // Short message is an Error message, we process accordingly
        message.short_message = short_message.message;
        message.full_message  = short_message.stack;

        // extract error file and line
        fileinfo = message.stack.split('\n')[0];

Looking at this, the last line message.stack should be short_message.stack.
Message is a newly build object within the library which does not contain a stack trace by default.

Chunk message problem

Hi,
I am unable to send messages in chunks. In the source code I see, when the payload size exceeds a certain buffer limit, the message is sent in chunks. However, I do not see those messages in my graylog.

Is there some way we can debug this? There are no messages in error logs.

Module not found: Error: Can't resolve 'dgram' OR dgram.createSocket is not a function

Hello!
After installing this module, graylog2 ran into a problem.
After npm i graylog2 was building nodejs 16.13.0 and getting Module not found: Error: Can't resolve 'dgram'
dgram

Then found a solution by adding to webpack.mix.js
mix.webpackConfig ({
node: {
fs: 'empty',
dgram: 'empty',
}
});
The build error did not appear anymore. but when using the graylog2 module itself in my project another error occurred: "dgram.createSocket is not a function"
dgram createSocket is not a function

How can you solve these problems in order to use this module by means of the front?

"vuex": "3.5.1",
"webpack": "4.44.2",
"vue": "2.6.10"
nodejs: 16.13.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.