mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-09 13:46:33 +00:00
Better output format
This commit is contained in:
parent
a936e4c505
commit
037efbaba2
@ -57,13 +57,13 @@ export class ArduinoDaemon implements BackendApplicationContribution {
|
|||||||
|
|
||||||
if (daemon.stdout) {
|
if (daemon.stdout) {
|
||||||
daemon.stdout.on('data', data => {
|
daemon.stdout.on('data', data => {
|
||||||
this.toolOutputService.publishNewOutput('daemon', data.toString());
|
this.toolOutputService.publishNewOutput('daemon', DaemonLog.toPrettyString(data.toString()));
|
||||||
DaemonLog.log(this.logger, data.toString());
|
DaemonLog.log(this.logger, data.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (daemon.stderr) {
|
if (daemon.stderr) {
|
||||||
daemon.stderr.on('data', data => {
|
daemon.stderr.on('data', data => {
|
||||||
this.toolOutputService.publishNewOutput('daemon error', data.toString());
|
this.toolOutputService.publishNewOutput('daemon error', DaemonLog.toPrettyString(data.toString()));
|
||||||
DaemonLog.log(this.logger, data.toString());
|
DaemonLog.log(this.logger, data.toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -32,36 +32,49 @@ export namespace DaemonLog {
|
|||||||
const segments = toLog.split('time').filter(s => s.trim().length > 0);
|
const segments = toLog.split('time').filter(s => s.trim().length > 0);
|
||||||
for (const segment of segments) {
|
for (const segment of segments) {
|
||||||
const maybeDaemonLog = parse(`time${segment}`.trim());
|
const maybeDaemonLog = parse(`time${segment}`.trim());
|
||||||
if (is(maybeDaemonLog)) {
|
for (const logMsg of maybeDaemonLog) {
|
||||||
const { msg } = maybeDaemonLog;
|
logger.log(toLogLevel(logMsg), logMsg.msg);
|
||||||
logger.log(toLogLevel(maybeDaemonLog), msg);
|
|
||||||
} else {
|
|
||||||
logger.info(toLog.trim());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Super naive.
|
// Super naive.
|
||||||
function parse(toLog: string): string | DaemonLog {
|
function parse(toLog: string): DaemonLog[] {
|
||||||
const rawSegments = toLog.split(/(\s+)/)
|
const messages = toLog.split('\ntime=');
|
||||||
.map(segment => segment.replace(/['"]+/g, ''))
|
const result: DaemonLog[] = [];
|
||||||
.map(segment => segment.trim())
|
for (let i = 0; i < messages.length; i++) {
|
||||||
.filter(segment => segment.length > 0);
|
const msg = (i > 0 ? 'time=' : '') + messages[i];
|
||||||
|
const rawSegments = msg.split(/(\s+)/)
|
||||||
|
.map(segment => segment.replace(/['"]+/g, ''))
|
||||||
|
.map(segment => segment.trim())
|
||||||
|
.filter(segment => segment.length > 0);
|
||||||
|
|
||||||
const timeIndex = rawSegments.findIndex(segment => segment.startsWith('time='));
|
const timeIndex = rawSegments.findIndex(segment => segment.startsWith('time='));
|
||||||
const levelIndex = rawSegments.findIndex(segment => segment.startsWith('level='));
|
const levelIndex = rawSegments.findIndex(segment => segment.startsWith('level='));
|
||||||
const msgIndex = rawSegments.findIndex(segment => segment.startsWith('msg='));
|
const msgIndex = rawSegments.findIndex(segment => segment.startsWith('msg='));
|
||||||
if (rawSegments.length > 2
|
if (rawSegments.length > 2
|
||||||
&& timeIndex !== -1
|
&& timeIndex !== -1
|
||||||
&& levelIndex !== -1
|
&& levelIndex !== -1
|
||||||
&& msgIndex !== -1) {
|
&& msgIndex !== -1) {
|
||||||
return {
|
result.push({
|
||||||
time: rawSegments[timeIndex].split('=')[1],
|
time: rawSegments[timeIndex].split('=')[1],
|
||||||
level: rawSegments[levelIndex].split('=')[1] as Level,
|
level: rawSegments[levelIndex].split('=')[1] as Level,
|
||||||
msg: [rawSegments[msgIndex].split('=')[1], ...rawSegments.slice(msgIndex + 1)].join(' ')
|
msg: [rawSegments[msgIndex].split('=')[1], ...rawSegments.slice(msgIndex + 1)].join(' ')
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
result.push({
|
||||||
|
time: new Date().toString(),
|
||||||
|
level: 'info',
|
||||||
|
msg: msg
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, log the string as is.
|
// Otherwise, log the string as is.
|
||||||
return toLog;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toPrettyString(logMessage: string): string {
|
||||||
|
const parsed = parse(logMessage);
|
||||||
|
return parsed.map(msg => `[${msg.level.toUpperCase() || 'INFO'}] ${msg.msg}\n`).join('');
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user