hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

how can i generate multiple log files for custom tags? #522

Closed shubsaini09 closed 8 years ago

shubsaini09 commented 8 years ago
const options = {
  ops: {
    interval: 1000
  },
  reporters: {
    debug: [{
      module: 'good-squeeze',
      name: 'Squeeze',
      args: [{
        'debug': ''
      }]
    }, {
      module: 'good-squeeze',
      name: 'SafeJson'
    }, {
      module: 'good-file',
      args: ['./test/fixtures/debug_log']
    }]
    error: [{
      module: 'good-squeeze',
      name: 'Squeeze',
      args: [{
        'error': ''
      }]
    }, {
      module: 'good-squeeze',
      name: 'SafeJson'
    }, {
      module: 'good-file',
      args: ['./test/fixtures/error_log']
    }]
  }
};
server.route({
  method: 'GET',
  path: '/debug',
  handler: function(req, reply) {
    reply('debug msg');
    server.log('debug', 'hello this is debug log');
  }
});
server.route({
  method: 'GET',
  path: '/error',
  handler: function(req, reply) {
    reply('error msg');
    server.log('error', 'hello this is error log');
  }
});

What happens is calling both the routes logs both messages in both file, whereas i want debug message to be in debug_log and error message in error_log.

arb commented 8 years ago

First, please make sure you code is formatted and wrapped in "```" before posting questions. Unformatted code is almost impossible to read. I fixed it for you on this issue, but please keep this in mind in the future.

Second, debug and is not an event you can filter on, and error isn't even happening in your server. Change the arguments to good-squeeze to log: "debug" and `log: "error" for each reporter. That should fix your issue.

shubsaini09 commented 8 years ago

Thanks for formatting my code but i did use the option insert code from the comment toolbar and placed my code inside two backticks but it didn't format my code. I don't know why i couldn't format it :/

log: "debug" and log: "error" did fix my issue but facing a error

throw new Error(msgs.join(' ') || 'Unknown error'); Error: Unknown event type [{"type":"onPostStop"},{"type":"onPreStart"}]

arb commented 8 years ago

That's not enough information to work on. I need the stack trace. What version of node and hapi and good are you using? Did you charge your config from your first post?

shubsaini09 commented 8 years ago

First i was using it in my practice, now when i am implementing it in my actual code, i am getting this error.

versions -

myproject $ node -v
v5.2.0
"engines": {
    "node": "0.10.x"
  },
"dependencies": {
    "good": "^7.0.2",
    "good-console": "^6.1.2",
    "good-file": "^6.0.1",
    "good-squeeze": "^5.0.0",
    "hapi": "^8.0.0"
}

this is how i am registering

server.register([
     {
         register: require("good"),
         options: options
    },
    { 
       other plugin
    },
    { 
       other plugin
    }], (err) => {

    if (err) {
        return console.error(err);
    }
    server.start(function() {
        console.log('Server started at: ' + server.info.uri);
    });
});
arb commented 8 years ago

As you can see from package.json (and you're probably getting console warnings about this too that you are ignoring) you need version 10.0.0 or greater for good version 7. Either use an older version of good or a modern version of hapi. Version 8 support ended a long time ago.

shubsaini09 commented 8 years ago

Sorry for late reply. I did update my version of hapi to recent one. The current issue seem to be fixed but i am not able to test it as my code has broken due to latest version of hapi. Fixing it might take time and i have other work which is on priority as well. I am closing this issue as of now but if any other doubt i will reopen it.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.