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

feat(logging): custom log entries MONGOSH-1989 #2322

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

alenakhineika
Copy link
Contributor

Allow users to add custom entries to mongosh logs in their scripts.

log.info('This is an info message');
log.warn('Warning!');

The custom log message will sequentially appear alongside internal mongosh messages, and will look similar to this:

{"t":{"$date":"2025-01-06T16:14:23.023Z"},"s":"I","c":"MONGOSH","id":1000000012,"ctx":"shell-api","msg":"Loading file via load()","attr":{"nested":false,"filename":"/Users/alena.khineika/custom-logging.js"}}
{"t":{"$date":"2025-01-06T16:14:23.041Z"},"s":"I","c":"MONGOSH-SCRIPTS","id":1000000054,"ctx":"custom-log","msg":"This is an info message"}
{"t":{"$date":"2025-01-06T16:14:23.041Z"},"s":"W","c":"MONGOSH-SCRIPTS","id":1000000054,"ctx":"custom-log","msg":"Warning!"}

@mongodb-js mongodb-js deleted a comment from evergreen-ci-prod bot Jan 17, 2025
packages/shell-api/src/shell-instance-state.ts Outdated Show resolved Hide resolved
packages/shell-api/src/shell-instance-state.ts Outdated Show resolved Hide resolved
packages/e2e-tests/test/e2e.spec.ts Show resolved Hide resolved
packages/e2e-tests/test/e2e.spec.ts Outdated Show resolved Hide resolved
packages/e2e-tests/test/e2e.spec.ts Outdated Show resolved Hide resolved
@alenakhineika alenakhineika marked this pull request as ready for review January 22, 2025 16:21
packages/shell-api/src/shell-log.ts Outdated Show resolved Hide resolved
Comment on lines +840 to +846
bus.emit('mongosh:connect', {
uri: 'mongodb://localhost/',
is_localhost: true,
is_atlas: false,
resolved_hostname: 'localhost',
node_version: 'v12.19.0',
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry if this is silly, but as someone who's not super proficient with the mongosh testing harness, it's not clear to me why we need this as part of this test. Is it used to test that non-custom logs are still emitted or for some other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is exactly the reason to check that all of those records are located in the same log file and the custom log is not being saved separately to keep the ordered log entries in one place to provide a clear picture for debugging.

packages/e2e-tests/test/e2e.spec.ts Outdated Show resolved Hide resolved
packages/e2e-tests/test/e2e.spec.ts Outdated Show resolved Hide resolved
packages/e2e-tests/test/e2e.spec.ts Outdated Show resolved Hide resolved
packages/shell-api/src/shell-log.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants