More logging.

This commit is contained in:
Thomas E Lackey 2020-06-10 17:15:07 -05:00
parent 5965c53696
commit 0fb12ec30f
8 changed files with 61 additions and 15 deletions

View File

@ -12,7 +12,7 @@ app:
api: api:
path: '/api' path: '/api'
port: 4000 port: 4004
intervalLog: 5000 intervalLog: 5000
pollInterval: 10000 pollInterval: 10000

View File

@ -106,6 +106,9 @@ const Log = ({ log = [] }) => {
); );
}; };
// TODO(telackey): Why do these display in reverse?
log.reverse();
return ( return (
<div className={classes.root}> <div className={classes.root}>
<div className={classes.log}> <div className={classes.log}>

View File

@ -11,6 +11,9 @@ import { ConsoleContext, useQueryStatusReducer } from '../../../hooks';
import Log from '../../../components/Log'; import Log from '../../../components/Log';
const MAX_LINES = 1000;
const oldLines = [];
const SignalLog = () => { const SignalLog = () => {
const { config } = useContext(ConsoleContext); const { config } = useContext(ConsoleContext);
const data = useQueryStatusReducer(useQuery(SIGNAL_LOG, { pollInterval: config.api.intervalLog })); const data = useQueryStatusReducer(useQuery(SIGNAL_LOG, { pollInterval: config.api.intervalLog }));
@ -18,8 +21,14 @@ const SignalLog = () => {
return null; return null;
} }
const newLines = JSON.parse(data.signal_log.json);
oldLines.push(...newLines);
if (oldLines.length > MAX_LINES) {
oldLines.splice(0, oldLines.length - MAX_LINES);
}
return ( return (
<Log log={data.signal_log.log} /> <Log log={oldLines.slice(0)} />
); );
}; };

View File

@ -11,16 +11,24 @@ import { ConsoleContext, useQueryStatusReducer } from '../../../hooks';
import Log from '../../../components/Log'; import Log from '../../../components/Log';
const MAX_LINES = 1000;
const oldLines = [];
const WNSLog = () => { const WNSLog = () => {
const { config } = useContext(ConsoleContext); const { config } = useContext(ConsoleContext);
const data = useQueryStatusReducer(useQuery(WNS_LOG, { pollInterval: config.api.intervalLog })); const data = useQueryStatusReducer(useQuery(WNS_LOG, { pollInterval: config.api.intervalLog }));
console.error(data);
if (!data) { if (!data) {
return null; return null;
} }
const newLines = JSON.parse(data.wns_log.json);
oldLines.push(...newLines);
if (oldLines.length > MAX_LINES) {
oldLines.splice(0, oldLines.length - MAX_LINES);
}
return ( return (
<Log log={JSON.parse(data.wns_log.json)} /> <Log log={oldLines.slice(0)} />
); );
}; };

View File

@ -3,8 +3,8 @@
# #
query { query {
signal_log @client { signal_log {
timestamp timestamp
log json
} }
} }

View File

@ -1,7 +1,7 @@
{ {
"build": { "build": {
"name": "@dxos/console-app", "name": "@dxos/console-app",
"buildDate": "2020-06-10T20:28:40.010Z", "buildDate": "2020-06-10T22:08:16.919Z",
"version": "1.0.0-beta.0" "version": "1.0.0-beta.0"
} }
} }

View File

@ -13,15 +13,17 @@ type JSONResult {
# #
type Query { type Query {
app_swarm_log: JSONResult! app_log: JSONResult!
app_status: JSONResult!
ipfs_log: JSONResult! ipfs_log: JSONResult!
ipfs_status: JSONResult! ipfs_status: JSONResult!
ipfs_swarm_log: JSONResult! ipfs_swarm_log: JSONResult!
ipfs_swarm_status: JSONResult!
signal_log: JSONResult!
signal_status: JSONResult! signal_status: JSONResult!
signal_swarm_log: JSONResult!
system_status: JSONResult! system_status: JSONResult!
wns_status: JSONResult!
wns_log: JSONResult! wns_log: JSONResult!
wns_status: JSONResult!
} }
schema { schema {

View File

@ -2,11 +2,7 @@
// Copyright 2020 DxOS.org // Copyright 2020 DxOS.org
// //
import moment from 'moment'; import { spawnSync } from 'child_process';
import pick from 'lodash.pick';
import os from 'os';
import si from 'systeminformation';
import { spawnSync } from "child_process";
class LogCache { class LogCache {
constructor(maxLines = 500) { constructor(maxLines = 500) {
@ -60,6 +56,34 @@ export const logResolvers = {
timestamp: new Date().toUTCString(), timestamp: new Date().toUTCString(),
json: JSON.stringify(logs) json: JSON.stringify(logs)
}; };
},
signal_log: async () => {
const logs = await getLogs('signal');
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
ipfs_log: async () => {
const logs = await getLogs('ipfs');
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
ipfs_swarm_log: async () => {
const logs = await getLogs('ipfs');
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
},
app_log: async () => {
const logs = await getLogs('ipfs');
return {
timestamp: new Date().toUTCString(),
json: JSON.stringify(logs)
};
} }
} }
}; };