Skip to content

Instantly share code, notes, and snippets.

@muradm
Created January 24, 2020 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muradm/406fc080453d29bda15da9cf24dd9353 to your computer and use it in GitHub Desktop.
Save muradm/406fc080453d29bda15da9cf24dd9353 to your computer and use it in GitHub Desktop.
Angular polyfill.ts for remote console log
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