Our web app generates a large amount of logs. These logs include both events regarding background operations in the app (data arrives from the server, ajax failures, inter-component communication, etc.); and also user initiated actions (user clicked a button, user wrote text, etc.).
We built our own logging library with different adapters (print to console, send to server, etc.); and currently send all the logs to our server for persistence. These logs are used to analyze the behaviour and flow of the app, monitor errors, client-side exceptions, etc.
We now have a new requirement of tracking user behaviour in the app, and we consider 2 approaches:
- Enrich our current in-code logs (which are sent to the server) and log every user action we need to track. Then use ETL jobs to collect and analyze the data using some third party service (Omninute, Kibana, etc.).
- Integrate a third party service with its own JS library (Omniture, Google Analytics) and adapt our code to use that service (manually sending events from JS, HTML tagging, etc.).
The first approach keeps our code base cleaner and with less duplication (only one logging mechanism).
The second approach involves modifying the app's code to send all the events we want to track to the analytics service, in addition to logging them with our own logging service. But it allows the analytics service to gather additional data which we don't need to implement ourselves (geotracking, browser and OS versions, etc.).
What approach should I take so the code can meet both logging requirements without unnecessary code duplication and complexity?