Search code examples
phantomjsgraylog2graylog

Send log from PhantomJS to Graylog2


I'm trying to send a log message from PhantomJS script to Graylog. Is there a way to do that?


Solution

  • I solved in this way:

    function remoteLog(message) {
    
    var page = require('webpage').create(),
    server = 'http://10.68.130.24:12202/gelf',
    data = '{"short_message":"' + message + '", "host":"phantomjs.smediresource.com", "project" : "Dynacare", "facility":"phantomJS", "environment":"QA", "application": "phantomJS", "content": "applicationLog"}';
    
    page.open(server, 'post', data, function (status) {
        if (status !== 'success') {
            console.error('Unable to post!');
        } 
        page.close();
    });
    
    }
    

    It works but generate some crashes due to a memory leak of PhantomJS.