-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pipe logging in and parse and categorize it
- Loading branch information
1 parent
362321f
commit 83e5d16
Showing
7 changed files
with
154 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect, useState } from 'react' | ||
|
||
export default function useHolochainErrorAndLog() { | ||
const [wasmLogs, setWasmLogs] = useState<string[]>([]) | ||
const [holochainInfo, setHolochainInfo] = useState<object[]>([]) | ||
const [holochainWarn, setHolochainWarn] = useState<object[]>([]) | ||
const [holochainDebug, setHolochainDebug] = useState<object[]>([]) | ||
const [holochainError, setHolochainError] = useState<object[]>([]) | ||
const [holochainUnknown, setHolochainUnknown] = useState<string[]>([]) | ||
const [errors, setErrors] = useState<string[]>([]) | ||
|
||
const subscribeToEvents = async () => { | ||
if (window.require) { | ||
const { ipcRenderer } = window.require('electron') | ||
ipcRenderer.on('wasmLog', (event: object, log: string) => { | ||
setWasmLogs((logs) => [...logs, log]) | ||
}) | ||
ipcRenderer.on('holochainLog', (event: object, log: string) => { | ||
try { | ||
let parsedLog: object = JSON.parse(log) | ||
if (parsedLog['level'] === 'INFO') { | ||
setHolochainInfo((logs) => [...logs, parsedLog]) | ||
} else if (parsedLog['level'] === 'WARN') { | ||
setHolochainWarn((logs) => [...logs, parsedLog]) | ||
} else if (parsedLog['level'] === 'DEBUG') { | ||
setHolochainDebug((logs) => [...logs, parsedLog]) | ||
} else if (parsedLog['level'] === 'ERROR') { | ||
setHolochainError((logs) => [...logs, parsedLog]) | ||
} | ||
} catch (e) { | ||
setHolochainUnknown((logs) => [...logs, log]) | ||
} | ||
}) | ||
ipcRenderer.on('holochainError', (event: object, error: string) => { | ||
setErrors((errors) => [...errors, error]) | ||
}) | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
subscribeToEvents() | ||
}, []) | ||
|
||
return { | ||
wasmLogs, | ||
holochainLogs: { | ||
info: holochainInfo, | ||
warn: holochainWarn, | ||
debug: holochainDebug, | ||
error: holochainError, | ||
unknown: holochainUnknown, | ||
}, | ||
errors, | ||
} | ||
} |
This file contains 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
This file contains 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