forked from cerc-io/laconic-console
Incremental
This commit is contained in:
parent
20e152f6e3
commit
44fd5a0830
@ -16,7 +16,10 @@ const oldLines = [];
|
||||
|
||||
const SignalLog = () => {
|
||||
const { config } = useContext(ConsoleContext);
|
||||
const data = useQueryStatusReducer(useQuery(SIGNAL_LOG, { pollInterval: config.api.intervalLog }));
|
||||
const data = useQueryStatusReducer(useQuery(SIGNAL_LOG, {
|
||||
pollInterval: config.api.intervalLog,
|
||||
variables: { first: oldLines.length === 0 }
|
||||
}));
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
@ -28,7 +31,7 @@ const SignalLog = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<Log log={oldLines.slice(0)} />
|
||||
<Log log={oldLines.slice(0)}/>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -2,8 +2,8 @@
|
||||
# Copyright 2020 DxOS.org
|
||||
#
|
||||
|
||||
query {
|
||||
signal_log {
|
||||
query ($incremental: Boolean) {
|
||||
signal_log(incremental: $incremental) {
|
||||
timestamp
|
||||
json
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
# Copyright 2020 DxOS.org
|
||||
#
|
||||
|
||||
query {
|
||||
wns_log {
|
||||
query($incremental: Boolean) {
|
||||
wns_log(incremental: $incremental) {
|
||||
timestamp
|
||||
json
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"build": {
|
||||
"name": "@dxos/console-app",
|
||||
"buildDate": "2020-06-10T22:08:16.919Z",
|
||||
"buildDate": "2020-06-10T22:43:33.469Z",
|
||||
"version": "1.0.0-beta.0"
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,16 @@ type JSONResult {
|
||||
#
|
||||
|
||||
type Query {
|
||||
app_log: JSONResult!
|
||||
app_log(incremental: Boolean): JSONResult!
|
||||
app_status: JSONResult!
|
||||
ipfs_log: JSONResult!
|
||||
ipfs_log(incremental: Boolean): JSONResult!
|
||||
ipfs_status: JSONResult!
|
||||
ipfs_swarm_log: JSONResult!
|
||||
ipfs_swarm_log(incremental: Boolean): JSONResult!
|
||||
ipfs_swarm_status: JSONResult!
|
||||
signal_log: JSONResult!
|
||||
signal_log(incremental: Boolean): JSONResult!
|
||||
signal_status: JSONResult!
|
||||
system_status: JSONResult!
|
||||
wns_log: JSONResult!
|
||||
wns_log(incremental: Boolean): JSONResult!
|
||||
wns_status: JSONResult!
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ class LogCache {
|
||||
}
|
||||
|
||||
const _caches = new Map();
|
||||
|
||||
const getLogCache = (name) => {
|
||||
let cache = _caches.get(name);
|
||||
if (!cache) {
|
||||
@ -38,48 +39,50 @@ const getLogCache = (name) => {
|
||||
return cache;
|
||||
}
|
||||
|
||||
const getLogs = async (name, lines = 100) => {
|
||||
const getLogs = async (name, incremental = false, lines = 100) => {
|
||||
const command = 'wire';
|
||||
const args = ['service', 'logs', '--lines', lines, name];
|
||||
|
||||
const child = spawnSync(command, args, { encoding: 'utf8' });
|
||||
const logLines = child.stdout.split(/\n/);
|
||||
const cache = getLogCache(name);
|
||||
return cache.append(logLines);
|
||||
const added = cache.append(logLines);
|
||||
|
||||
return incremental ? added : Array.from(cache.buffer);
|
||||
};
|
||||
|
||||
export const logResolvers = {
|
||||
Query: {
|
||||
wns_log: async () => {
|
||||
const logs = await getLogs('wns-lite');
|
||||
wns_log: async (_, { incremental }) => {
|
||||
const logs = await getLogs('wns-lite', incremental);
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
};
|
||||
},
|
||||
signal_log: async () => {
|
||||
const logs = await getLogs('signal');
|
||||
signal_log: async (_, { incremental }) => {
|
||||
const logs = await getLogs('signal', incremental);
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
};
|
||||
},
|
||||
ipfs_log: async () => {
|
||||
const logs = await getLogs('ipfs');
|
||||
ipfs_log: async (_, { incremental }) => {
|
||||
const logs = await getLogs('ipfs', incremental);
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
};
|
||||
},
|
||||
ipfs_swarm_log: async () => {
|
||||
const logs = await getLogs('ipfs');
|
||||
ipfs_swarm_log: async (_, { incremental }) => {
|
||||
const logs = await getLogs('ipfs-swarm-connect', incremental);
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
};
|
||||
},
|
||||
app_log: async () => {
|
||||
const logs = await getLogs('ipfs');
|
||||
app_log: async (_, { incremental }) => {
|
||||
const logs = await getLogs('app', incremental);
|
||||
return {
|
||||
timestamp: new Date().toUTCString(),
|
||||
json: JSON.stringify(logs)
|
||||
|
Loading…
Reference in New Issue
Block a user