@@ -302,39 +302,39 @@ var _ = Describe("Zap logger setup", func() {
302
302
303
303
var _ = Describe ("Zap log level flag options setup" , func () {
304
304
var (
305
- fromFlags Options
306
- fs flag.FlagSet
307
- info = "info text"
308
- debug1 = "debug 1 text"
309
- debug2 = "debug 2 text"
310
- debug3 = "debug 3 text"
305
+ fromFlags Options
306
+ fs flag.FlagSet
307
+ logInfoLevel0 = "info text"
308
+ logDebugLevel1 = "debug 1 text"
309
+ logDebugLevel2 = "debug 2 text"
310
+ logDebugLevel3 = "debug 3 text"
311
311
)
312
312
313
313
BeforeEach (func () {
314
314
fromFlags = Options {}
315
- fs = * flag .NewFlagSet (os .Args [0 ], flag .ExitOnError ) //flags are now reset
315
+ fs = * flag .NewFlagSet (os .Args [0 ], flag .ExitOnError )
316
316
})
317
317
318
318
Context ("with zap-log-level options provided" , func () {
319
- It ("Should set info/ debug zap-log-level flags ." , func () {
319
+ It ("Should output logs for info and debug zap-log-level." , func () {
320
320
args := []string {"--zap-log-level=debug" }
321
321
fromFlags .BindFlags (& fs )
322
322
err := fs .Parse (args )
323
323
Expect (err ).ToNot (HaveOccurred ())
324
324
logOut := new (bytes.Buffer )
325
325
326
326
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
327
- logger .V (0 ).Info (info )
328
- logger .V (1 ).Info (debug1 )
327
+ logger .V (0 ).Info (logInfoLevel0 )
328
+ logger .V (1 ).Info (logDebugLevel1 )
329
329
330
330
outRaw := logOut .Bytes ()
331
331
332
- Expect (string (outRaw )).Should (ContainSubstring (info ))
333
- Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
332
+ Expect (string (outRaw )).Should (ContainSubstring (logInfoLevel0 ))
333
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel1 ))
334
334
335
335
})
336
336
337
- It ("Should set error zap-log-level flags. " , func () {
337
+ It ("Should output only error logs, otherwise empty logs " , func () {
338
338
args := []string {"--zap-log-level=error" }
339
339
fromFlags .BindFlags (& fs )
340
340
err := fs .Parse (args )
@@ -343,8 +343,8 @@ var _ = Describe("Zap log level flag options setup", func() {
343
343
logOut := new (bytes.Buffer )
344
344
345
345
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
346
- logger .V (0 ).Info (info )
347
- logger .V (1 ).Info (debug1 )
346
+ logger .V (0 ).Info (logInfoLevel0 )
347
+ logger .V (1 ).Info (logDebugLevel1 )
348
348
349
349
outRaw := logOut .Bytes ()
350
350
@@ -354,84 +354,84 @@ var _ = Describe("Zap log level flag options setup", func() {
354
354
})
355
355
356
356
Context ("with zap-log-level with increased verbosity." , func () {
357
- It ("Should set integer debug level 1 for zap- log-level flag ." , func () {
357
+ It ("Should output debug and info log, with default production mode ." , func () {
358
358
args := []string {"--zap-log-level=1" }
359
359
fromFlags .BindFlags (& fs )
360
360
err := fs .Parse (args )
361
361
Expect (err ).ToNot (HaveOccurred ())
362
362
logOut := new (bytes.Buffer )
363
363
364
364
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
365
- logger .V (0 ).Info (info )
366
- logger .V (1 ).Info (debug1 )
365
+ logger .V (0 ).Info (logInfoLevel0 )
366
+ logger .V (1 ).Info (logDebugLevel1 )
367
367
368
368
outRaw := logOut .Bytes ()
369
369
370
- Expect (string (outRaw )).Should (ContainSubstring (info ))
371
- Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
370
+ Expect (string (outRaw )).Should (ContainSubstring (logInfoLevel0 ))
371
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel1 ))
372
372
})
373
373
374
- It ("Should set integer debug level 1 for zap-log-level flag ." , func () {
374
+ It ("Should output info and debug logs, with development mode ." , func () {
375
375
args := []string {"--zap-log-level=1" , "--zap-devel=true" }
376
376
fromFlags .BindFlags (& fs )
377
377
err := fs .Parse (args )
378
378
Expect (err ).ToNot (HaveOccurred ())
379
379
logOut := new (bytes.Buffer )
380
380
381
381
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
382
- logger .V (0 ).Info (info )
383
- logger .V (1 ).Info (debug1 )
382
+ logger .V (0 ).Info (logInfoLevel0 )
383
+ logger .V (1 ).Info (logDebugLevel1 )
384
384
385
385
outRaw := logOut .Bytes ()
386
386
387
- Expect (string (outRaw )).Should (ContainSubstring (info ))
388
- Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
387
+ Expect (string (outRaw )).Should (ContainSubstring (logInfoLevel0 ))
388
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel1 ))
389
389
})
390
390
391
- It ("Should set integer debug level 2 for zap-log-level flag ." , func () {
391
+ It ("Should output info, and debug logs with increased verbosity, and with development mode set to true ." , func () {
392
392
args := []string {"--zap-log-level=2" , "--zap-devel=true" }
393
393
fromFlags .BindFlags (& fs )
394
394
err := fs .Parse (args )
395
395
Expect (err ).ToNot (HaveOccurred ())
396
396
logOut := new (bytes.Buffer )
397
397
398
398
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
399
- logger .V (0 ).Info (info )
400
- logger .V (1 ).Info (debug1 )
401
- logger .V (2 ).Info (debug2 )
399
+ logger .V (0 ).Info (logInfoLevel0 )
400
+ logger .V (1 ).Info (logDebugLevel1 )
401
+ logger .V (2 ).Info (logDebugLevel2 )
402
402
403
403
outRaw := logOut .Bytes ()
404
404
405
- Expect (string (outRaw )).Should (ContainSubstring (info ))
406
- Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
407
- Expect (string (outRaw )).Should (ContainSubstring (debug2 ))
405
+ Expect (string (outRaw )).Should (ContainSubstring (logInfoLevel0 ))
406
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel1 ))
407
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel2 ))
408
408
409
409
})
410
- It ("Should set integer debug level 3 for zap-log-level flag ." , func () {
410
+ It ("Should output info, and debug logs with increased verbosity, and with production mode set to true ." , func () {
411
411
args := []string {"--zap-log-level=3" , "--zap-devel=false" }
412
412
fromFlags .BindFlags (& fs )
413
413
err := fs .Parse (args )
414
414
Expect (err ).ToNot (HaveOccurred ())
415
415
logOut := new (bytes.Buffer )
416
416
417
417
logger := New (UseFlagOptions (& fromFlags ), WriteTo (logOut ))
418
- logger .V (0 ).Info (info )
419
- logger .V (1 ).Info (debug1 )
420
- logger .V (3 ).Info (debug3 )
418
+ logger .V (0 ).Info (logInfoLevel0 )
419
+ logger .V (1 ).Info (logDebugLevel1 )
420
+ logger .V (3 ).Info (logDebugLevel3 )
421
421
422
422
outRaw := logOut .Bytes ()
423
423
424
- Expect (string (outRaw )).Should (ContainSubstring (info ))
425
- Expect (string (outRaw )).Should (ContainSubstring (debug1 ))
426
- Expect (string (outRaw )).Should (ContainSubstring (debug3 ))
424
+ Expect (string (outRaw )).Should (ContainSubstring (logInfoLevel0 ))
425
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel1 ))
426
+ Expect (string (outRaw )).Should (ContainSubstring (logDebugLevel3 ))
427
427
428
428
})
429
429
430
430
})
431
431
432
432
Context ("with zap-stacktrace-level options provided" , func () {
433
433
434
- It ("Should set info stacktrace for zap-stacktrace- level flags ." , func () {
434
+ It ("Should output stacktrace at info level, with development mode set to true ." , func () {
435
435
args := []string {"--zap-stacktrace-level=info" , "--zap-devel=true" }
436
436
fromFlags .BindFlags (& fs )
437
437
err := fs .Parse (args )
@@ -442,7 +442,7 @@ var _ = Describe("Zap log level flag options setup", func() {
442
442
Expect (out .StacktraceLevel .Enabled (zapcore .InfoLevel )).To (BeTrue ())
443
443
})
444
444
445
- It ("Should set error stacktrace for zap-stacktrace- level flags ." , func () {
445
+ It ("Should output stacktrace at error level, with development mode set to true ." , func () {
446
446
args := []string {"--zap-stacktrace-level=error" , "--zap-devel=true" }
447
447
fromFlags .BindFlags (& fs )
448
448
err := fs .Parse (args )
@@ -453,16 +453,6 @@ var _ = Describe("Zap log level flag options setup", func() {
453
453
Expect (out .StacktraceLevel .Enabled (zapcore .ErrorLevel )).To (BeTrue ())
454
454
})
455
455
456
- It ("Should disable stacktrace for zap-stacktrace-level flags." , func () {
457
- args := []string {"--zap-stacktrace-level=disabled" , "--zap-devel=true" }
458
- fromFlags .BindFlags (& fs )
459
- err := fs .Parse (args )
460
- Expect (err ).ToNot (HaveOccurred ())
461
- out := Options {}
462
- UseFlagOptions (& fromFlags )(& out )
463
-
464
- Expect (out .StacktraceLevel .Enabled (zapcore .FatalLevel )).To (BeTrue ())
465
- })
466
456
})
467
457
468
458
})
0 commit comments