Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log-server: Store export improvements #224

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rotten-maps-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lightmill/log-server': minor
---

Significantly increase default select query limit of SQLiteStore
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
2 changes: 1 addition & 1 deletion packages/log-server/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import loglevel, { LogLevelDesc } from 'loglevel';
import { groupBy, last } from 'remeda';
import { arrayify } from './utils.js';

const DEFAULT_SELECT_QUERY_LIMIT = 10000;
const DEFAULT_SELECT_QUERY_LIMIT = 1000000;

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const migrationFolder = path.join(__dirname, 'db-migrations');
Expand Down