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: Add Parse.nodeLogging to fully log Parse.Object #1594

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/CoreManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const config: Config & { [key: string]: mixed } = {
ENCRYPTED_USER: false,
IDEMPOTENCY: false,
ALLOW_CUSTOM_OBJECT_ID: false,
NODE_LOGGING: false,
};

function requireMethods(name: string, methods: Array<string>, controller: any) {
Expand Down
11 changes: 11 additions & 0 deletions src/Parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ const Parse = {
get allowCustomObjectId() {
return CoreManager.get('ALLOW_CUSTOM_OBJECT_ID');
},

/**
* @member {boolean} Parse.nodeLogging
* @static
*/
set nodeLogging(value) {
CoreManager.set('NODE_LOGGING', value);
},
get nodeLogging() {
return CoreManager.get('NODE_LOGGING');
},
};

Parse.ACL = require('./ParseACL').default;
Expand Down
7 changes: 7 additions & 0 deletions src/ParseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ class ParseObject {
if (toSet && !this.set(toSet, options)) {
throw new Error("Can't create an invalid Parse Object");
}
if (CoreManager.get('NODE_LOGGING')) {
this[Symbol.for('nodejs.util.inspect.custom')] = function () {
return `ParseObject: className: ${this.className}, id: ${
this.id
}\nAttributes: ${JSON.stringify(this.attributes, null, 2)}`;
};
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/Parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ describe('Parse module', () => {
Parse.allowCustomObjectId = false;
});

it('can set nodeLogging', () => {
expect(Parse.nodeLogging).toBe(false);
Parse.nodeLogging = true;
expect(CoreManager.get('NODE_LOGGING')).toBe(true);
Parse.nodeLogging = false;
});

it('getServerHealth', () => {
const controller = {
request: jest.fn(),
Expand Down
10 changes: 10 additions & 0 deletions src/__tests__/ParseObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3836,4 +3836,14 @@ describe('ParseObject pin', () => {
});
CoreManager.set('ALLOW_CUSTOM_OBJECT_ID', false);
});

it('can log an object', () => {
CoreManager.set('NODE_LOGGING', true);
const o = new ParseObject('Person', { foo: 'bar' });
const symbol = Symbol.for('nodejs.util.inspect.custom');
expect(o[symbol]()).toBe(
`ParseObject: className: Person, id: undefined\nAttributes: {\n \"foo\": \"bar\"\n}`
);
CoreManager.set('NODE_LOGGING', false);
});
});