Skip to content

Commit

Permalink
log-server: display exported logs count
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinRoy committed Jan 31, 2024
1 parent 237d935 commit 289f5f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-walls-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': minor
---

Display count of exported logs during export when output is a file.
35 changes: 33 additions & 2 deletions packages/log-server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import loglevel from 'loglevel';
import yargs from 'yargs';
import { SQLiteStore, LogServer } from './index.js';
import { csvExportStream, jsonExportStream } from './export.js';
import { Transform } from 'node:stream';

// Constants and setup
// -------------------
Expand Down Expand Up @@ -121,9 +122,39 @@ async function exportLogs({
: jsonExportStream(store, filter);
if (output === undefined) {
stream.pipe(process.stdout).on('error', handleError);
} else {
stream.pipe(createWriteStream(output)).on('error', handleError);
return;
}
let startDate = new Date();
let logCount = 0;
process.stdout.write(`${logCount.toLocaleString('en')} logs exported...`);
stream
.pipe(
new Transform({
writableObjectMode: true,
transform(chunk, encoding, callback) {
process.stdout.cursorTo(0);
logCount += 1;
process.stdout.write(
`${logCount.toLocaleString('en')} logs exported...`,
);
callback(null, chunk);
},
}),
)
.pipe(createWriteStream(output))
.on('error', handleError)
.on('finish', () => {
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
let durationInSeconds = (Date.now() - startDate.getTime()) / 1000;
process.stdout.write(
`${logCount.toLocaleString(
'en',
)} logs exported in ${durationInSeconds.toLocaleString(
'en',
)} seconds.\n`,
);
});
}

type MigrateDatabaseParameter = {
Expand Down

0 comments on commit 289f5f6

Please sign in to comment.