Angular service to capture console logs and errors
npm install angular-console-capture> Angular 14+ service that captures all console.log() and console.error() calls globally ā perfect for debugging, diagnostics, and reporting.
---
- ā
Automatically captures all console.log() and console.error() calls.
- ā
Prevents self-logging when inspecting logs/errors.
- ā
Includes full error stack, name, and message.
- ā
Lightweight service ā no UI, no external dependencies.
- ā
Easy to plug into your app or extend with hotkey triggers.
---
š¹ getCapturedData() -
Returns all captured console logs and errors.
š¹ clearCapturedData() -
Clears all stored logs and errors.
š¹ stopCapturing()d -
Temporarily stops console capturing.
Useful before printing captured data to avoid recursive logging.
š¹ startCapturingAgain() -
Resumes console capturing after a manual stop.
npm install console-capture
Add service to your project
import { AngularConsoleCaptureModule } from 'angular-console-capture';
@NgModule({
imports: [AngularConsoleCaptureModule]
})
export class AppModule {}
add activation
constructor(private angularConsoleCaptureSrv: AngularConsoleCaptureModule){}
ngOnInit() {
// -> here you can set the exact method you will use to call data from the console
document.addEventListener('keydown', (event) => {
if (event.ctrlKey && event.key === 'b') {
this.angularConsoleCaptureSrv.pauseCapturing();
const capturedData = this.angularConsoleCaptureSrv.getCapturedData();
// call API to save in server if you need
console.log(capturedData)
this.angularConsoleCaptureSrv.unPauseCapturing();
}
});
}