Skip to content

Commit

Permalink
Capture console.log to in-app log
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Feb 15, 2024
1 parent bf46d25 commit e976687
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@mui/icons-material": "^5.14.11",
"@mui/lab": "^5.0.0-alpha.146",
"@mui/material": "^5.14.11",
"capture-console-logs": "^2.0.1-rc.1",
"color-interpolate": "^1.0.5",
"css-element-queries": "^1.2.3",
"downloadjs": "^1.4.7",
Expand Down
2 changes: 2 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { useSettings } from "slices/settings";
import { SliceProvider as EnvironmentProvider } from "slices/SliceProvider";
import { makeTheme } from "theme";
import { TitleBar } from "components/title-bar/TitleBar";
import { LogCaptureService } from "services/LogCaptureService";

const services = [
ConnectionsService,
FeaturesService,
RendererService,
LayerService,
LogCaptureService,
];

function App() {
Expand Down
26 changes: 26 additions & 0 deletions client/src/services/LogCaptureService.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import CaptureConsole from "capture-console-logs";
import { useSnackbar } from "components/generic/Snackbar";
import { head, truncate } from "lodash";
import { useEffect } from "react";

export function LogCaptureService() {
const notify = useSnackbar();
useEffect(() => {
const cc = new CaptureConsole();
cc.start(true);
const interval = setInterval(() => {
const captures = cc.getCaptures();
if (captures.length) {
for (const { args } of captures) {
notify(`${truncate(head(args), { length: 200 })}`);
}
cc.flush();
}
}, 300);
return () => {
clearInterval(interval);
cc.stop();
};
}, []);
return <></>;
}

0 comments on commit e976687

Please sign in to comment.