@@ -3,7 +3,6 @@ import type { Context, Handler } from 'aws-lambda';
33import { Utility } from '@aws-lambda-powertools/commons' ;
44import { LogFormatterInterface , PowertoolLogFormatter } from './formatter' ;
55import { LogItem } from './log' ;
6- import cloneDeep from 'lodash.clonedeep' ;
76import merge from 'lodash.merge' ;
87import { ConfigServiceInterface , EnvironmentVariablesService } from './config' ;
98import { LogJsonIndent } from './types' ;
@@ -151,7 +150,6 @@ class Logger extends Utility implements ClassThatLogs {
151150 */
152151 public constructor ( options : ConstructorOptions = { } ) {
153152 super ( ) ;
154-
155153 this . setOptions ( options ) ;
156154 }
157155
@@ -205,7 +203,17 @@ class Logger extends Utility implements ClassThatLogs {
205203 * @returns {Logger }
206204 */
207205 public createChild ( options : ConstructorOptions = { } ) : Logger {
208- return cloneDeep ( this ) . setOptions ( options ) ;
206+ const parentsPowertoolsLogData = this . getPowertoolLogData ( ) ;
207+ const childLogger = new Logger ( merge ( { } , parentsPowertoolsLogData , options ) ) ;
208+
209+ const parentsPersistentLogAttributes = this . getPersistentLogAttributes ( ) ;
210+ childLogger . addPersistentLogAttributes ( parentsPersistentLogAttributes ) ;
211+
212+ if ( parentsPowertoolsLogData . lambdaContext ) {
213+ childLogger . addContext ( parentsPowertoolsLogData . lambdaContext as Context ) ;
214+ }
215+
216+ return childLogger ;
209217 }
210218
211219 /**
0 commit comments