Skip to content

Commit e3284a7

Browse files
committed
feat: Add Parse.nodeLogging to fully log Parse.Object
1 parent 8f94427 commit e3284a7

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

src/CoreManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ const config: Config & { [key: string]: mixed } = {
201201
ENCRYPTED_USER: false,
202202
IDEMPOTENCY: false,
203203
ALLOW_CUSTOM_OBJECT_ID: false,
204+
NODE_LOGGING: false,
204205
};
205206

206207
function requireMethods(name: string, methods: Array<string>, controller: any) {

src/Parse.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ const Parse = {
209209
get allowCustomObjectId() {
210210
return CoreManager.get('ALLOW_CUSTOM_OBJECT_ID');
211211
},
212+
213+
/**
214+
* @member {boolean} Parse.nodeLogging
215+
* @static
216+
*/
217+
set nodeLogging(value) {
218+
CoreManager.set('NODE_LOGGING', value);
219+
},
220+
get nodeLogging() {
221+
return CoreManager.get('NODE_LOGGING');
222+
},
212223
};
213224

214225
Parse.ACL = require('./ParseACL').default;

src/ParseObject.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ class ParseObject {
143143
if (toSet && !this.set(toSet, options)) {
144144
throw new Error("Can't create an invalid Parse Object");
145145
}
146+
if (CoreManager.get('NODE_LOGGING')) {
147+
this[Symbol.for('nodejs.util.inspect.custom')] = function () {
148+
return `ParseObject: className: ${this.className}, id: ${
149+
this.id
150+
}\nAttributes: ${JSON.stringify(this.attributes, null, 2)}`;
151+
};
152+
}
146153
}
147154

148155
/**

src/__tests__/Parse-test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ describe('Parse module', () => {
195195
Parse.allowCustomObjectId = false;
196196
});
197197

198+
it('can set nodeLogging', () => {
199+
expect(Parse.nodeLogging).toBe(false);
200+
Parse.nodeLogging = true;
201+
expect(CoreManager.get('NODE_LOGGING')).toBe(true);
202+
Parse.nodeLogging = false;
203+
});
204+
198205
it('getServerHealth', () => {
199206
const controller = {
200207
request: jest.fn(),

src/__tests__/ParseObject-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,4 +3836,14 @@ describe('ParseObject pin', () => {
38363836
});
38373837
CoreManager.set('ALLOW_CUSTOM_OBJECT_ID', false);
38383838
});
3839+
3840+
it('can log an object', () => {
3841+
CoreManager.set('NODE_LOGGING', true);
3842+
const o = new ParseObject('Person', { foo: 'bar' });
3843+
const symbol = Symbol.for('nodejs.util.inspect.custom');
3844+
expect(o[symbol]()).toBe(
3845+
`ParseObject: className: Person, id: undefined\nAttributes: {\n \"foo\": \"bar\"\n}`
3846+
);
3847+
CoreManager.set('NODE_LOGGING', false);
3848+
});
38393849
});

0 commit comments

Comments
 (0)