0

I have a node.js app and I need to implement statistics for it. I have two ways: writing into the console.log and then capturing it using some tool (AWS CloudWatch Metrics) or calling AWS API and send stats over the Internet. The thing is:

  • Writing anything into the console requires resources and time.
  • But calling an API to publish my stats also requires resources and time.

I am curious which way is more effective? Which way I am using less CPU resources?

Ruslan Plastun
  • 1,985
  • 3
  • 21
  • 48
  • *I am curious which way is more effective?* - this is microoptimisation. Unless there's a ton of log entries, this doesn't matter. It makes sense to use some abstraction like Winston, this way logging will be more flexible, requests could be send in batch, etc. – Estus Flask Sep 10 '18 at 15:01
  • So there is almost no diff between calling API and logging and I should choose simply what I want? And what do you mean by _'batch'_? – Ruslan Plastun Sep 10 '18 at 15:28
  • And also, choosing between multiple log calls and one big log call is also a micro-optimization I think, right?)) – Ruslan Plastun Sep 10 '18 at 15:32
  • Relying on console.log in production app is bad practice. It cannot be considered proper logging. I'm not aware of your requirements but hard-coding the app to inflexible solution is more than microoptimisation (or the lack of it). Batch requests is one of many things that may be needed later. It's easy with Winston. – Estus Flask Sep 10 '18 at 15:37
  • I am new to batch requests)) Can you tell me what is that, please? – Ruslan Plastun Sep 10 '18 at 15:44
  • If the app spams logs, it makes sense to collect entries within time window and send them with one request. It's unknown if this may be a problem for your app but it will be easier if logging solution is flexible enough to allow this. – Estus Flask Sep 10 '18 at 16:19

0 Answers0