dimanche 28 avril 2019

How to separate Business logic and metrics log?

In lots of Applications, we need to log statistics metrics, such as hist, guage and so on. This will pollute the business logic. For example:

boolean buy(int id) {
  metrics.increament(); // for qps maybe.. 
  int remain = checkRemain();
  metrics.hist(remain); // log remain amount..
  if (remain > 0)
    return true;
  else
    return false;
}

which, I hope, I can only write down the biz logic, such as:

boolean buy(int id) {
  int remain = checkRemain();
  if (remain > 0)
    return true;
  else
    return false;
}

But also I can get the metrics.

My question is: what's the best practice to separate Business logic and metrics log?

I know AOP may solve this, do I have any other choice?

Aucun commentaire:

Enregistrer un commentaire