Skip to content

Commit

Permalink
Merge pull request #12 from Enigmatis/response-in-logs
Browse files Browse the repository at this point in the history
Now cleans the log object
  • Loading branch information
chenshoo authored Feb 26, 2020
2 parents 11b53dc + 74ac3d9 commit 2c8af65
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 27 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/Enigmatis/graphql-logger.git"
"url": "git+https://github.com/Enigmatis/polaris-graphql-logger.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Enigmatis/graphql-logger/issues"
"url": "https://github.com/Enigmatis/polaris-graphql-logger/issues"
},
"homepage": "https://github.com/Enigmatis/graphql-logger#readme",
"homepage": "https://github.com/Enigmatis/polaris-graphql-logger#readme",
"dependencies": {
"@enigmatis/polaris-common": "^1.1.0",
"@enigmatis/polaris-common": "^1.1.1",
"@enigmatis/polaris-logs": "^2.8.1",
"clean-deep": "^3.3.0",
"winston": "^3.2.1"
Expand Down
5 changes: 1 addition & 4 deletions src/logger/graphql-log-properties.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { PolarisLogProperties } from '@enigmatis/polaris-logs';

export type GraphQLLogProperties = Omit<
PolarisLogProperties,
'response' | 'upn' | 'ip' | 'host' | 'reality'
>;
export type GraphQLLogProperties = Omit<PolarisLogProperties, 'upn' | 'ip' | 'host' | 'reality'>;
7 changes: 4 additions & 3 deletions src/logger/polaris-graphql-logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import cleanDeep from 'clean-deep';
import { AbstractPolarisLogger, LoggerConfiguration } from '@enigmatis/polaris-logs';
import { ApplicationProperties, PolarisGraphQLContext } from '@enigmatis/polaris-common';
import { GraphQLLogProperties } from './graphql-log-properties';
Expand Down Expand Up @@ -64,7 +65,7 @@ export class PolarisGraphQLLogger extends AbstractPolarisLogger {
): GraphQLLogProperties {
const basicLogProperties: any = this.buildLog(message, graphQLLogProperties);

const contextLogProperties = {
const contextLogProperties: object = {
messageId: context?.requestHeaders?.requestId,
eventKind: graphQLLogProperties?.eventKind,
reality: {
Expand All @@ -90,9 +91,9 @@ export class PolarisGraphQLLogger extends AbstractPolarisLogger {
},
requestingHost: graphQLLogProperties?.request?.requestingHost,
},
response: context?.response,
};

return { ...basicLogProperties, ...contextLogProperties };
const mergedLogObject: object = { ...basicLogProperties, ...contextLogProperties };
return cleanDeep(mergedLogObject);
}
}
2 changes: 0 additions & 2 deletions test/context-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ export const query = 'foo';
export const operationName = 'foo';
export const variables = new Map<string, string>();
variables.set('hello', 'world');
export const response = jest.fn();
export const getContextWithRequestHeaders = (
requestHeaders: PolarisRequestHeaders,
requestingIp: string,
): PolarisGraphQLContext => {
return {
requestHeaders,
request: { query, operationName, variables },
response,
returnedExtensions: { globalDataVersion: 0 },
responseHeaders: {},
clientIp: requestingIp,
Expand Down
12 changes: 1 addition & 11 deletions test/polaris-graphql-logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ import {
LoggerConfiguration,
PolarisLogProperties,
} from '@enigmatis/polaris-logs';
import {
getContextWithRequestHeaders,
operationName,
query,
response,
variables,
} from './context-util';
import { getContextWithRequestHeaders, operationName, query, variables } from './context-util';

const messageId = '0';
const upn = 'upn';
Expand Down Expand Up @@ -63,7 +57,6 @@ describe('build log properties tests', () => {
requestingIp,
requestingSystem: { id: requestingSystemId, name: requestingSystemName },
},
response,
});
});

Expand Down Expand Up @@ -94,7 +87,6 @@ describe('build log properties tests', () => {
requestingIp,
requestingSystem: { id: requestingSystemId, name: requestingSystemName },
},
response,
});
});

Expand Down Expand Up @@ -125,7 +117,6 @@ describe('build log properties tests', () => {
requestingIp,
requestingSystem: { id: requestingSystemId, name: requestingSystemName },
},
response,
});
});
test('info, graphql log properties exist, with application properties', () => {
Expand Down Expand Up @@ -169,7 +160,6 @@ describe('build log properties tests', () => {
version: appProps.version,
systemName: appProps.name,
systemId: appProps.id,
response,
});
});
});
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"resolveJsonModule": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"typeRoots": [
"src/type-declarations"
],
Expand Down

0 comments on commit 2c8af65

Please sign in to comment.