Skip to content

build(logger): reduce node_modules size #427

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

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
862 changes: 638 additions & 224 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"devDependencies": {
"@types/aws-lambda": "^8.10.72",
"@types/jest": "^27.0.0",
"@types/lodash": "^4.14.168",
"@types/node": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
Expand Down
3,042 changes: 1,530 additions & 1,512 deletions packages/logger/npm-shrinkwrap.json → packages/logger/package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"typedocMain": "src/index.ts",
"devDependencies": {
"@types/jest": "^27.0.0",
"@types/lodash": "^4.14.168",
"@types/lodash.clonedeep": "^4.5.6",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.pickby": "^4.6.6",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
Expand All @@ -69,8 +71,8 @@
"@aws-lambda-powertools/commons": "0.2.0",
"@middy/core": "^2.5.3",
"@types/aws-lambda": "^8.10.72",
"lodash": "^4.17.21",
"lodash.clonedeep": "^4.5.0",
"lodash.merge": "^4.6.2"
"lodash.merge": "^4.6.2",
"lodash.pickby": "^4.6.0"
}
}
}
11 changes: 6 additions & 5 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Context } from 'aws-lambda';
import { LogFormatterInterface, PowertoolLogFormatter } from './formatter';
import { LogItem } from './log';
import { cloneDeep, merge } from 'lodash/fp';
import cloneDeep from 'lodash.clonedeep';
import merge from 'lodash.merge';
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
import type {
Environment,
Expand Down Expand Up @@ -69,7 +70,7 @@ class Logger implements ClassThatLogs {
}

public addPersistentLogAttributes(attributes?: LogAttributes): void {
this.persistentLogAttributes = merge(this.getPersistentLogAttributes(), attributes);
this.persistentLogAttributes = merge(attributes, this.getPersistentLogAttributes());
}

public appendKeys(attributes?: LogAttributes): void {
Expand Down Expand Up @@ -148,16 +149,16 @@ class Logger implements ClassThatLogs {

private addToPowertoolLogData(...attributesArray: Array<Partial<PowertoolLogData>>): void {
attributesArray.forEach((attributes: Partial<PowertoolLogData>) => {
this.powertoolLogData = merge(this.getPowertoolLogData(), attributes);
this.powertoolLogData = merge(attributes, this.getPowertoolLogData());
});
}

private createAndPopulateLogItem(logLevel: LogLevel, input: LogItemMessage, extraInput: LogItemExtraInput): LogItem {
const unformattedBaseAttributes = merge(this.getPowertoolLogData(), {
const unformattedBaseAttributes = merge({
logLevel,
timestamp: new Date(),
message: typeof input === 'string' ? input : input.message,
});
}, this.getPowertoolLogData());

const logItem = new LogItem({
baseAttributes: this.getLogFormatter().formatAttributes(unformattedBaseAttributes),
Expand Down
3 changes: 2 additions & 1 deletion packages/logger/src/log/LogItem.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pickBy, merge } from 'lodash';
import pickBy from 'lodash.pickby';
import merge from 'lodash.merge';
import { LogItemInterface } from '.';
import { LogAttributes } from '../types';

Expand Down
2 changes: 2 additions & 0 deletions packages/logger/tests/unit/Logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ describe('Class: Logger', () => {
class LambdaFunction implements LambdaInterface {

@logger.injectLambdaContext()
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
public async handler<TEvent>(_event: TEvent, _context: Context): Promise<string> {
logger.info('This is an INFO log with some context');

Expand Down