Created
January 24, 2020 21:30
-
-
Save muradm/406fc080453d29bda15da9cf24dd9353 to your computer and use it in GitHub Desktop.
Angular polyfill.ts for remote console log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'zone.js/dist/zone' // Angular requirement | |
(window as any).enableRemoteLog = () => { | |
(window as any).originalConsole = console | |
const axios = import('axios') | |
console = (Object.keys(console) as (keyof Console)[]) | |
.map(k => | |
typeof console[k] === 'function' | |
? { | |
[k]: (...args: any[]) => { | |
axios.then(a => | |
a.default({ | |
method: 'POST', | |
url: '/api/log', | |
data: { when: new Date().toISOString(), function: k, args } | |
}) | |
) | |
} | |
} | |
: { [k]: console[k] } | |
) | |
.reduce<Console>((acc, f) => ({ ...acc, ...f }), {} as Console) | |
} | |
(window as any).disableRemoteLog = () => { | |
console = (window as any).originalConsole | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment