Comments (8)
Doing this for now:
setTimeout(function() { //sleep for graylog to get last messages
callback(null);
}, 10);
from node-graylog2.
How does your script finish? Do you call process.exit()?
from node-graylog2.
Hmm... not really sure. my code runs on AWS Lambda and I create a handler function which is then runned. Don't really now how they implemented it. If it helps function definition looks like this:
exports.handler = function(event, context, callback)
more docs: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
from node-graylog2.
Can you show me a more complete example of what you're running?
from node-graylog2.
I do think I understand the reason though. Our log functions don't have callback arguments, but they do asynchronous work. If you bail out (in your case, calling your callback which may kill a process in that tick) there are 2 things that won't have had a chance to complete: gzip compressing of your log message, UDP-send of your message.
This is a fundamental issue in this module. We need to work on this.
from node-graylog2.
Well really nothing special. Here is my log.write function from log module:
module.exports.write = function (title, message) {
if (typeof message === 'undefined') {
message = "";
}
if ( process.env.NODE_ENV !== 'test' ) {
console.log(module.exports.timestamp()+'\t'+title+'\t'+message);
if (message!=="") {
if (title=='Error') logger.error(message, message);
else if (title=='Warning') logger.warning(message, message);
else if (title=='Info') logger.info(message, message);
else logger.error(title, message);
}
}
}
and my main program function:
/**
* Main event handler for Lambda
*
* @param {Object} event AWS Lambda event
* @param {Object} context AWS Lambda context
* @callback callback function(err)
* @param {Error} err
*/
exports.handler = function(event, context, callback) {
var operation = event.operation;
delete event.operation;
if (operation) {
log.write('Info', 'Operation ' + operation +' requested ');
}
//create tmp folder for this lambda session
fs.createFolderLocal('/tmp/'+common.getGuid());
switch (operation) {
case 'transform':
exports.transform(event,context, function (err) {
if (err) context.fail(err);
else {
setTimeout(function() { //sleep for graylog to get last messages
callback(null);
}, 10);
//context.done();
}
});
break;
default:
context.fail(new Error('Unrecognized operation "' + operation + '"'));
}
};
trough the rest of the code i just call log.write.
But yeah i suppose the problem is that lib functions should have async and sync way of calling (with callback or without) like its a common style with node.js
from node-graylog2.
There is no sync way to call functions that do UDP, but we need to allow callbacks to wait for gzipping and sending to complete (although iirc the callback on UDP sends is really a callback post-DNS-resolve).
from node-graylog2.
Hello,
I have this exact issue on my code right now. I need to wait for the logs to finish processing, but my app exits before that.
I see you are working on a new implementation. Is there any ETA?
Will it be backwards compatible?
from node-graylog2.
Related Issues (20)
- zlib deflate results in a memory leak HOT 3
- possible typo in graylog2.js line 118 HOT 5
- Random EADDRINUSE errors when logging HOT 2
- Support for Typescript HOT 5
- Is it possible to configure what levels get logged? HOT 1
- Feature request: Handle circular JSON HOT 1
- node-graylo2 not sending messages in correct format to Graylog2 HOT 9
- Dont get errors
- No error message on connection error HOT 1
- Chunk message problem HOT 1
- Not getting log in server and also not getting any error HOT 1
- not getting any error if graylog failure
- How to log additional fields?
- How to log additional fields as standard?
- Is there anyway to log stream on TCP? HOT 1
- New version for NPM to replace 0.2.1?
- Logging error object fails HOT 3
- [Question] Is project dead?
- Uncaught TypeError: dgram.createSocket is not a function HOT 3
- Module not found: Error: Can't resolve 'dgram' OR dgram.createSocket is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-graylog2.