Skip to content

Commit fa90217

Browse files
authored
feat(cli-repl): use mongodb log format for log files MONGOSH-944 (#1066)
Switch the log format to a mongod-style log format, and split out the implementation parts that could be shared by another application (specifically, Compass). This uses log message ids starting from 1000000 to avoid conflicts with mongod log ids.
1 parent 94ca4d9 commit fa90217

14 files changed

+683
-303
lines changed

packages/cli-repl/package-lock.json

Lines changed: 27 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli-repl/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
"ansi-escape-sequences": "^5.1.2",
5555
"askcharacter": "^1.0.0",
5656
"askpassword": "^1.2.4",
57+
"bson": "^4.4.1",
5758
"is-recoverable-error": "^1.0.2",
5859
"lodash.set": "^4.3.2",
5960
"mongodb-redact": "^0.2.2",
6061
"nanobus": "^4.4.0",
61-
"pino": "^5.16.0",
6262
"pretty-bytes": "^5.3.0",
6363
"pretty-repl": "^3.1.1",
6464
"semver": "^7.1.2",
@@ -73,7 +73,6 @@
7373
"@types/chai-as-promised": "^7.1.3",
7474
"@types/lodash.set": "^4.3.6",
7575
"@types/node": "^14.14.5",
76-
"@types/pino": "^6.3.3",
7776
"@types/text-table": "^0.2.1",
7877
"@types/yargs-parser": "^15.0.0",
7978
"chai-as-promised": "^7.1.1",

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('CliRepl', () => {
2626
const tmpdir = useTmpdir();
2727

2828
async function log(): Promise<any[]> {
29-
return readReplLogfile(path.join(tmpdir.path, `${cliRepl.logId}_log`));
29+
return readReplLogfile(path.join(tmpdir.path, `${cliRepl.logWriter.logId}_log`));
3030
}
3131

3232
async function startWithExpectedImmediateExit(cliRepl: CliRepl, host: string): Promise<void> {
@@ -165,22 +165,22 @@ describe('CliRepl', () => {
165165
});
166166

167167
it('writes syntax errors to the log file', async() => {
168-
expect((await log()).filter(entry => entry.stack?.startsWith('SyntaxError:'))).to.have.lengthOf(0);
168+
expect((await log()).filter(entry => entry.attr?.stack?.startsWith('SyntaxError:'))).to.have.lengthOf(0);
169169
input.write('<cat>\n');
170170
await waitBus(cliRepl.bus, 'mongosh:error');
171-
expect((await log()).filter(entry => entry.stack?.startsWith('SyntaxError:'))).to.have.lengthOf(1);
171+
expect((await log()).filter(entry => entry.attr?.stack?.startsWith('SyntaxError:'))).to.have.lengthOf(1);
172172
});
173173

174174
it('writes JS errors to the log file', async() => {
175175
input.write('throw new Error("plain js error")\n');
176176
await waitBus(cliRepl.bus, 'mongosh:error');
177-
expect((await log()).filter(entry => entry.stack?.startsWith('Error: plain js error'))).to.have.lengthOf(1);
177+
expect((await log()).filter(entry => entry.attr?.stack?.startsWith('Error: plain js error'))).to.have.lengthOf(1);
178178
});
179179

180180
it('writes Mongosh errors to the log file', async() => {
181181
input.write('db.auth()\n');
182182
await waitBus(cliRepl.bus, 'mongosh:error');
183-
expect((await log()).filter(entry => entry.stack?.startsWith('MongoshInvalidInputError:'))).to.have.lengthOf(1);
183+
expect((await log()).filter(entry => entry.attr?.stack?.startsWith('MongoshInvalidInputError:'))).to.have.lengthOf(1);
184184
});
185185

186186
it('emits the error event when exit() fails', async() => {
@@ -191,7 +191,7 @@ describe('CliRepl', () => {
191191
} catch (e) {
192192
const [emitted] = await onerror;
193193
expect(emitted).to.be.instanceOf(MongoshInternalError);
194-
expect((await log()).filter(entry => entry.stack?.startsWith('MongoshInternalError:'))).to.have.lengthOf(1);
194+
expect((await log()).filter(entry => entry.attr?.stack?.startsWith('MongoshInternalError:'))).to.have.lengthOf(1);
195195
return;
196196
}
197197
expect.fail('expected error');

0 commit comments

Comments
 (0)