unify the logging between electron and wavesrv (emain now proxies the wavesrv logs)

This commit is contained in:
sawka 2024-06-12 19:33:44 -07:00
parent 391c4f20d5
commit 336dd0c0e3
4 changed files with 20 additions and 26 deletions

View File

@ -62,6 +62,9 @@ func stdinReadWatch() {
}
func main() {
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.SetPrefix("[wavesrv] ")
err := service.ValidateServiceMap()
if err != nil {
log.Printf("error validating service map: %v\n", err)

View File

@ -4,6 +4,7 @@
import * as electron from "electron";
import * as child_process from "node:child_process";
import * as path from "path";
import * as readline from "readline";
import { debounce } from "throttle-debounce";
import * as services from "../frontend/app/store/services";
@ -59,13 +60,6 @@ function getWaveSrvPath(): string {
return path.join(getGoAppBasePath(), "bin", "wavesrv");
}
function getWaveSrvCmd(): string {
const waveSrvPath = getWaveSrvPath();
const waveHome = getWaveHomeDir();
const logFile = path.join(waveHome, "wavesrv.log");
return `"${waveSrvPath}" >> "${logFile}" 2>&1`;
}
function getWaveSrvCwd(): string {
return getWaveHomeDir();
}
@ -83,9 +77,9 @@ function runWaveSrv(): Promise<boolean> {
envCopy[WaveDevVarName] = "1";
}
envCopy[WaveSrvReadySignalPidVarName] = process.pid.toString();
const waveSrvCmd = getWaveSrvCmd();
const waveSrvCmd = getWaveSrvPath();
console.log("trying to run local server", waveSrvCmd);
const proc = child_process.execFile("bash", ["-c", waveSrvCmd], {
const proc = child_process.spawn(getWaveSrvPath(), {
cwd: getWaveSrvCwd(),
env: envCopy,
});
@ -102,11 +96,19 @@ function runWaveSrv(): Promise<boolean> {
console.log("error running wavesrv", e);
pReject(e);
});
proc.stdout.on("data", (_) => {
return;
const rlStdout = readline.createInterface({
input: proc.stdout,
terminal: false,
});
proc.stderr.on("data", (_) => {
return;
rlStdout.on("line", (line) => {
console.log(line);
});
const rlStderr = readline.createInterface({
input: proc.stderr,
terminal: false,
});
rlStderr.on("line", (line) => {
console.log(line);
});
return rtnPromise;
}

View File

@ -235,12 +235,12 @@ func (bc *BlockController) Run(bdata *wstore.Block) {
for genCmd := range bc.InputCh {
switch cmd := genCmd.(type) {
case *BlockInputCommand:
fmt.Printf("INPUT: %s | %q\n", bc.BlockId, cmd.InputData64)
log.Printf("INPUT: %s | %q\n", bc.BlockId, cmd.InputData64)
if bc.ShellInputCh != nil {
bc.ShellInputCh <- cmd
}
default:
fmt.Printf("unknown command type %T\n", cmd)
log.Printf("unknown command type %T\n", cmd)
}
}
}

View File

@ -725,14 +725,3 @@ func IndentString(indent string, str string) string {
}
return rtn.String()
}
func PrintIndentedStr(indent string, str string) {
splitArr := strings.Split(str, "\n")
for _, line := range splitArr {
if line == "" {
fmt.Printf("\n")
continue
}
fmt.Printf("%s%s\n", indent, line)
}
}