@@ -19,6 +19,11 @@ describe('Logger', () => {
1919 expect ( winLogger . level ) . to . equal ( 'error' ) ;
2020 } ) ;
2121
22+ fancy . it ( 'should create hidden logger as error level' , ( ) => {
23+ const hiddenLogger = logger . getLoggerInstance ( 'hidden' ) ;
24+ expect ( hiddenLogger . level ) . to . equal ( 'error' ) ;
25+ } ) ;
26+
2227 fancy . it ( 'should redact sensitive keys' , ( ) => {
2328 const testMeta = {
2429 password : 'secret123' ,
@@ -34,6 +39,14 @@ describe('Logger', () => {
3439 expect ( redacted . other ) . to . equal ( 'safe' ) ;
3540 } ) ;
3641
42+ fancy . it ( 'should detect valid LogEntry object' , ( ) => {
43+ const validEntry = { level : 'info' , message : 'Test message' } ;
44+ expect ( logger [ 'isLogEntry' ] ( validEntry ) ) . to . equal ( true ) ;
45+
46+ const invalidEntry = { msg : 'nope' } ;
47+ expect ( logger [ 'isLogEntry' ] ( invalidEntry ) ) . to . equal ( false ) ;
48+ } ) ;
49+
3750 fancy . it ( 'should log error messages using error method' , ( ) => {
3851 const errorLogger = logger [ 'loggers' ] . error ;
3952 const spy = sinon . spy ( ) ;
@@ -76,13 +89,17 @@ describe('Logger', () => {
7689 expect ( spy . args [ 0 ] [ 1 ] . type ) . to . equal ( 'success' ) ;
7790 } ) ;
7891
79- fancy
80- . it ( 'logError with hidden true logs to debug logger' , ( ) => {
81- const debugLogger = logger [ 'loggers' ] . debug ;
92+ fancy . it ( 'logError with hidden true logs to debug logger' , ( ) => {
93+ const debugLogger = new Logger ( {
94+ basePath : './logs' ,
95+ consoleLogLevel : 'debug' ,
96+ logLevel : 'debug' ,
97+ } ) ;
98+
8299 const spy = sinon . spy ( ) ;
83- debugLogger . error = spy ;
100+ debugLogger [ 'loggers' ] . debug . error = spy ;
84101
85- logger . logError ( {
102+ debugLogger . logError ( {
86103 type : 'hiddenType' ,
87104 message : 'Something secret' ,
88105 error : new Error ( 'oops' ) ,
@@ -94,7 +111,6 @@ describe('Logger', () => {
94111 expect ( logPayload . meta . type ) . to . equal ( 'hiddenType' ) ;
95112 } ) ;
96113
97-
98114 fancy . it ( 'redact handles splat symbol' , ( ) => {
99115 const obj = {
100116 token : 'abc' ,
@@ -104,4 +120,82 @@ describe('Logger', () => {
104120 expect ( result . token ) . to . equal ( '[REDACTED]' ) ;
105121 expect ( result [ Symbol . for ( 'splat' ) ] [ 0 ] . password ) . to . equal ( '[REDACTED]' ) ;
106122 } ) ;
123+
124+ fancy . it ( 'redact should return original if klona fails' , ( ) => {
125+ const faultyLogger = new Logger ( {
126+ basePath : './logs' ,
127+ consoleLogLevel : 'info' ,
128+ logLevel : 'info' ,
129+ } ) ;
130+
131+ const obj = {
132+ toJSON : ( ) => {
133+ throw new Error ( 'klona fails' ) ;
134+ }
135+ } ;
136+
137+ const result = faultyLogger [ 'redact' ] ( obj ) ;
138+ expect ( result ) . to . deep . equal ( obj ) ;
139+ } ) ;
140+
141+ fancy . it ( 'should call logWarn with correct meta' , ( ) => {
142+ const warnSpy = sinon . spy ( ) ;
143+ logger [ 'loggers' ] . warn . warn = warnSpy ;
144+
145+ logger . logWarn ( {
146+ type : 'testType' ,
147+ message : 'Warn occurred' ,
148+ context : 'warnContext' ,
149+ meta : { custom : 'value' }
150+ } ) ;
151+
152+ expect ( warnSpy . calledOnce ) . to . be . true ;
153+ expect ( warnSpy . args [ 0 ] [ 0 ] . meta . type ) . to . equal ( 'testType' ) ;
154+ expect ( warnSpy . args [ 0 ] [ 0 ] . meta . custom ) . to . equal ( 'value' ) ;
155+ } ) ;
156+
157+ fancy . it ( 'should call logInfo with correct meta' , ( ) => {
158+ const infoSpy = sinon . spy ( ) ;
159+ logger [ 'loggers' ] . info . info = infoSpy ;
160+
161+ logger . logInfo ( {
162+ type : 'infoType' ,
163+ message : 'This is info' ,
164+ meta : { foo : 'bar' } ,
165+ } ) ;
166+
167+ expect ( infoSpy . calledOnce ) . to . be . true ;
168+ expect ( infoSpy . args [ 0 ] [ 0 ] . meta . foo ) . to . equal ( 'bar' ) ;
169+ } ) ;
170+
171+ fancy . it ( 'should call logDebug with correct meta' , ( ) => {
172+ const debugLogger = new Logger ( {
173+ basePath : './logs' ,
174+ consoleLogLevel : 'debug' ,
175+ logLevel : 'debug' ,
176+ } ) ;
177+
178+ const debugSpy = sinon . spy ( ) ;
179+ debugLogger [ 'loggers' ] . debug . debug = debugSpy ;
180+
181+ debugLogger . logDebug ( {
182+ type : 'debugType' ,
183+ message : 'Debug data' ,
184+ meta : { extra : 'info' } ,
185+ } ) ;
186+
187+ expect ( debugSpy . calledOnce ) . to . be . true ;
188+ expect ( debugSpy . args [ 0 ] [ 0 ] . meta . extra ) . to . equal ( 'info' ) ;
189+ } ) ;
190+
191+ fancy . it ( 'shouldLog should default to info when config not defined' , ( ) => {
192+ const defaultLogger = new Logger ( {
193+ basePath : './logs' ,
194+ consoleLogLevel : undefined as any ,
195+ logLevel : undefined as any ,
196+ } ) ;
197+
198+ expect ( defaultLogger [ 'shouldLog' ] ( 'info' , 'console' ) ) . to . equal ( true ) ;
199+ expect ( defaultLogger [ 'shouldLog' ] ( 'debug' , 'console' ) ) . to . equal ( false ) ;
200+ } ) ;
107201} ) ;
0 commit comments