veliovgroup / Meteor-logger

🧾 Meteor isomorphic logger. Store application logs in File (FS), MongoDB, or print in Console

Home Page:https://packosphere.com/ostrio/logger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Additional action on certain log levels?

meecect opened this issue · comments

I'm using logger console and logger mongo and both work perfectly. I'd like to send an email with the log message on error and critical levels. Rather than making a new logging interface, is there a way to execute a function when the log function is called, so that I can inspect the level and perform actions based on the level (like send an email in some cases).

thanks,
Cliff

@meecect one of the options I see right away — subscribe to the changes in MongoDB collection and trigger actions based on new entries.

Another one — implement .on() hook.

P.S. it's been 12 days, have you found a solution so far?

I ended up doing something kinda hacky:

log._error_orig = log.error;

log.error = function(message, data, userId) {
  var body;
  if (data) {
    if(typeof data == 'string') {
      body = data;
    } else {
      body = JSON.stringify(data,null, "  ");
    }
  } else {
    body = message;
  }
  Meteor.call(
    'sendEmail',
    message,
    body,
  );
  return log._error_orig(message, data, userId);
}

I'm not sure what .on() hook you are referring to. Is there an .on() hook in this project?

@meecect I meant implement .on() hook is another option to your issue

Feel free to close it in case if the issue is solved on your end.