diff --git a/src/CoreManager.js b/src/CoreManager.js index 188970e5c..41e783bbd 100644 --- a/src/CoreManager.js +++ b/src/CoreManager.js @@ -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, controller: any) { diff --git a/src/Parse.js b/src/Parse.js index 548fbfd6e..4c2261fe0 100644 --- a/src/Parse.js +++ b/src/Parse.js @@ -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; diff --git a/src/ParseObject.js b/src/ParseObject.js index 6e838b72a..06dd29522 100644 --- a/src/ParseObject.js +++ b/src/ParseObject.js @@ -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)}`; + }; + } } /** diff --git a/src/__tests__/Parse-test.js b/src/__tests__/Parse-test.js index c33502842..71d786ac2 100644 --- a/src/__tests__/Parse-test.js +++ b/src/__tests__/Parse-test.js @@ -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(), diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js index 0e35f56be..94e9d3689 100644 --- a/src/__tests__/ParseObject-test.js +++ b/src/__tests__/ParseObject-test.js @@ -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); + }); });