Skip to content

Commit f288ba1

Browse files
authored
data loader logs (#132)
supersedes #111 closes #88
1 parent 77bc43f commit f288ba1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/dataloader.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export class Loader {
7575
let command = runningCommands.get(this.path);
7676
if (command) return command;
7777
command = (async () => {
78+
console.info(`${this.path} start`);
79+
const time = performance.now();
7880
const outputPath = join(".observablehq", "cache", this.targetPath);
7981
const cachePath = join(this.sourceRoot, outputPath);
8082
const loaderStat = await maybeStat(this.path);
@@ -91,6 +93,11 @@ export class Loader {
9193
subprocess.on("close", resolve);
9294
});
9395
await tempFd.close();
96+
console.info(
97+
`${this.path} ${`${code === 0 ? success("success") : error("error")} ${outputBytes(
98+
(await maybeStat(tempPath))?.size
99+
)} in ${Math.floor(performance.now() - time)}ms`}`
100+
);
94101
if (code === 0) {
95102
await mkdir(dirname(cachePath), {recursive: true});
96103
await rename(tempPath, cachePath);
@@ -105,3 +112,17 @@ export class Loader {
105112
return command;
106113
}
107114
}
115+
116+
const error = color(31);
117+
const success = color(32);
118+
const warning = color(33);
119+
120+
function color(code) {
121+
return process.stdout.isTTY ? (text) => `\x1b[${code}m${text}\x1b[0m` : String;
122+
}
123+
124+
function outputBytes(size) {
125+
if (!size) return warning("empty output");
126+
const e = Math.floor(Math.log(size) / Math.log(1024));
127+
return `output ${+(size / 1024 ** e).toFixed(2)} ${["bytes", "KiB", "MiB", "GiB", "TiB"][e]}`;
128+
}

0 commit comments

Comments
 (0)