Skip to content
Merged
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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ const config: Config & Record<string, any> = {
IDEMPOTENCY: false,
ALLOW_CUSTOM_OBJECT_ID: false,
PARSE_ERRORS: [],
NODE_LOGGING: false,
};

function requireMethods(name: string, methods: string[], controller: any) {
Expand Down
22 changes: 22 additions & 0 deletions src/Parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,28 @@ const Parse = {
return CoreManager.get('ALLOW_CUSTOM_OBJECT_ID');
},

/**
* Setting this property to `true` enables enhanced logging for `Parse.Object`
* in Node.js environments. Specifically, it will log:
*
* ```
* ParseObject: className: <CLASS_NAME>, id: <OBJECT_ID>
* Attributes: <OBJECT_ATTRIBUTES>
* ```
*
* @warning This should not be enabled in production environments as this may
* expose sensitive information in server logs.
*
* @property {boolean} Parse.nodeLogging
* @static
*/
set nodeLogging(value) {
CoreManager.set('NODE_LOGGING', value);
},
get nodeLogging() {
return CoreManager.get('NODE_LOGGING');
},

_request(...args) {
return CoreManager.getRESTController().request.apply(null, args);
},
Expand Down
7 changes: 7 additions & 0 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ class ParseObject<T extends Attributes = Attributes> {
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 @@ -206,6 +206,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 @@ -3532,4 +3532,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);
});
});
16 changes: 16 additions & 0 deletions types/Parse.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@ declare const Parse: {
* @static
*/
allowCustomObjectId: any;
/**
* Setting this property to `true` enables enhanced logging for `Parse.Object`
* in Node.js environments. Specifically, it will log:
*
* ```
* ParseObject: className: <CLASS_NAME>, id: <OBJECT_ID>
* Attributes: <OBJECT_ATTRIBUTES>
* ```
*
* @warning This should not be enabled in production environments as this may
* expose sensitive information in server logs.
*
* @property {boolean} Parse.nodeLogging
* @static
*/
nodeLogging: any;
_request(...args: any[]): any;
_ajax(...args: any[]): any;
_decode(_: any, value: any): any;
Expand Down