Skip to content

Commit eb33736

Browse files
committed
shift logs to logger
1 parent 5d9d3cb commit eb33736

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

packages/server/bin/run-simulation-child.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type {
88

99
main(function* () {
1010
const args = process.argv.slice(2);
11-
console.dir({ args });
1211
if (args.length < 1) {
1312
throw new Error("usage: run-simulation-child.js <modulePath>");
1413
}
@@ -59,7 +58,6 @@ main(function* () {
5958
console.log(out);
6059
yield* suspend();
6160
} finally {
62-
console.log("shutting down gracefully...");
6361
try {
6462
if (listening && typeof listening.ensureClose === "function") {
6563
yield* until(listening.ensureClose());

packages/server/src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { parseArgs } from "node:util";
22
import { main, suspend, type Operation } from "effection";
33
import type { ServiceGraph, ServiceDefinition } from "./services.ts";
44

5-
export function* simulationCLIOp<S extends Record<string, any>>(
6-
serviceGraph: (subset?: string[] | string) => Operation<ServiceGraph<S>>
5+
export function* simulationCLIOp<S extends Record<string, any>, T = any>(
6+
serviceGraph: (subset?: string[] | string) => Operation<ServiceGraph<S, T>>
77
) {
88
try {
99
const { values } = parseArgs({
@@ -20,7 +20,7 @@ export function* simulationCLIOp<S extends Record<string, any>>(
2020
});
2121

2222
function* printUsage() {
23-
console.log(
23+
process.stdout.write(
2424
`Usage: cli [-s|--services serviceName] [--watch] [--watch-debounce ms]`
2525
);
2626
}

packages/server/src/services.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "effection";
1010

1111
import { type ServiceUpdate, useWatcher } from "./watch.ts";
12+
import { stdout } from "./logging.ts";
1213

1314
export type ServiceDefinition<
1415
S,
@@ -116,7 +117,7 @@ export function useServiceGraph<
116117
}
117118
effectiveServices = picked as typeof services;
118119

119-
console.log(
120+
yield* stdout(
120121
`service graph: starting with services: ${Array.from(included).join(
121122
", "
122123
)}`
@@ -217,7 +218,7 @@ export function useServiceGraph<
217218
try {
218219
for (let service of Object.keys(effectiveServices)) {
219220
yield* spawn(function* () {
220-
console.log(`service graph: starting service '${service}'`);
221+
yield* stdout(`service graph: starting service '${service}'`);
221222
yield* withRestarts(service);
222223
});
223224
}
@@ -229,7 +230,7 @@ export function useServiceGraph<
229230
servicePorts,
230231
});
231232
} finally {
232-
console.log("shutting down service graph");
233+
yield* stdout("shutting down service graph");
233234
}
234235
});
235236
}

packages/server/src/simulation.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export function useSimulation<L extends object = Record<string, unknown>>(
2323
createSim.listen()
2424
);
2525

26-
console.log(`${name} simulation started on port ${listening.port}`);
26+
yield* stdout(`${name} simulation started on port ${listening.port}`);
2727

2828
try {
2929
yield* provide(listening);
3030
} finally {
3131
yield* until(listening.ensureClose());
32-
console.log(`${name} simulation closed on port ${listening.port}`);
32+
yield* stdout(`${name} simulation closed on port ${listening.port}`);
3333
}
3434
});
3535
}
@@ -65,8 +65,6 @@ export function useChildSimulation<L extends object = Record<string, unknown>>(
6565
for (let line of yield* each(process.stdout)) {
6666
const buf = Buffer.from(line);
6767
const str = buf.toString();
68-
console.log(`stdout: ${str}`);
69-
yield* stdout(str);
7068

7169
if (!listening) {
7270
try {
@@ -76,10 +74,15 @@ export function useChildSimulation<L extends object = Record<string, unknown>>(
7674
port: parsed.port,
7775
} as FoundationSimulatorListening<L>;
7876
ready.resolve(Ok(listening));
77+
} else {
78+
yield* stdout(str);
7979
}
8080
} catch (_) {
8181
// ignore lines that are not JSON
82+
yield* stdout(str);
8283
}
84+
} else {
85+
yield* stdout(str);
8386
}
8487

8588
yield* each.next();
@@ -114,12 +117,14 @@ export function useChildSimulation<L extends object = Record<string, unknown>>(
114117
// we know listening is defined here
115118
listening = listening!;
116119

117-
console.log(`${name} process simulation started on port ${listening.port}`);
120+
yield* stdout(
121+
`${name} process simulation started on port ${listening.port}`
122+
);
118123

119124
try {
120125
yield* provide(listening);
121126
} finally {
122-
console.log(`${name} simulation closed on port ${listening?.port}`);
127+
yield* stdout(`${name} simulation closed on port ${listening?.port}`);
123128
}
124129
});
125130
}

0 commit comments

Comments
 (0)