@@ -68,6 +68,28 @@ module stdlib_logger
68
68
unopened_in_error = 7 , &
69
69
write_failure = 8
70
70
71
+ integer , parameter , public :: &
72
+ debug_level = 10 , &
73
+ information_level = 20 , &
74
+ warning_level = 30 , &
75
+ error_level = 40 , &
76
+ io_error_level = 40 , &
77
+ text_error_level = 50 , &
78
+ all_level = - 10 + min ( &
79
+ debug_level, &
80
+ information_level, &
81
+ warning_level, &
82
+ error_level, &
83
+ io_error_level, &
84
+ text_error_level), &
85
+ none_level = 10 + max ( &
86
+ debug_level, &
87
+ information_level, &
88
+ warning_level, &
89
+ error_level, &
90
+ io_error_level, &
91
+ text_error_level)
92
+
71
93
character (* ), parameter :: module_name = ' stdlib_logger'
72
94
73
95
type :: logger_type
@@ -78,6 +100,7 @@ module stdlib_logger
78
100
79
101
logical :: add_blank_line = .false.
80
102
logical :: indent_lines = .true.
103
+ integer :: level = information_level
81
104
integer , allocatable :: log_units(:)
82
105
integer :: max_width = 0
83
106
logical :: time_stamp = .true.
@@ -379,7 +402,7 @@ end subroutine validate_unit
379
402
end subroutine add_log_unit
380
403
381
404
382
- pure subroutine configuration ( self , add_blank_line , indent , &
405
+ pure subroutine configuration ( self , add_blank_line , indent , level , &
383
406
max_width , time_stamp , log_units )
384
407
! ! version: experimental
385
408
@@ -389,12 +412,13 @@ pure subroutine configuration( self, add_blank_line, indent, &
389
412
! ! starts with a blank line, and `.false.` implying no blank line.
390
413
! ! 2. `indent` is a logical flag with `.true.` implying that subsequent columns
391
414
! ! will be indented 4 spaces and `.false.` implying no indentation.
392
- ! ! 3. `max_width` is the maximum number of columns of output text with
415
+ ! ! 3. `level` is the lowest level for printing a message
416
+ ! ! 4. `max_width` is the maximum number of columns of output text with
393
417
! ! `max_width` == 0 => no bounds on output width.
394
- ! ! 4 . `time_stamp` is a logical flag with `.true.` implying that the output
418
+ ! ! 5 . `time_stamp` is a logical flag with `.true.` implying that the output
395
419
! ! will have a time stamp, and `.false.` implying that there will be no
396
420
! ! time stamp.
397
- ! ! 5 . `log_units` is an array of the I/O unit numbers to which log output
421
+ ! ! 6 . `log_units` is an array of the I/O unit numbers to which log output
398
422
! ! will be written.
399
423
! !([Specification](../page/specs/stdlib_logger.html#configuration-report-a-loggers-configuration))
400
424
@@ -404,6 +428,8 @@ pure subroutine configuration( self, add_blank_line, indent, &
404
428
! ! A logical flag to add a preceding blank line
405
429
logical , intent (out ), optional :: indent
406
430
! ! A logical flag to indent subsequent lines
431
+ integer , intent (out ), optional :: level
432
+ ! ! The minimum level for printing a message
407
433
integer , intent (out ), optional :: max_width
408
434
! ! The maximum number of columns for most outputs
409
435
logical , intent (out ), optional :: time_stamp
@@ -434,6 +460,7 @@ pure subroutine configuration( self, add_blank_line, indent, &
434
460
435
461
if ( present (add_blank_line) ) add_blank_line = self % add_blank_line
436
462
if ( present (indent) ) indent = self % indent_lines
463
+ if ( present (level) ) level = self % level
437
464
if ( present (max_width) ) max_width = self % max_width
438
465
if ( present (time_stamp) ) time_stamp = self % time_stamp
439
466
if ( present (log_units) ) then
@@ -447,7 +474,7 @@ pure subroutine configuration( self, add_blank_line, indent, &
447
474
end subroutine configuration
448
475
449
476
450
- pure subroutine configure ( self , add_blank_line , indent , max_width , &
477
+ pure subroutine configure ( self , add_blank_line , indent , level , max_width , &
451
478
time_stamp )
452
479
! ! version: experimental
453
480
@@ -459,10 +486,11 @@ pure subroutine configure( self, add_blank_line, indent, max_width, &
459
486
! ! 2. `indent` is a logical flag with `.true.` implying that subsequent lines
460
487
! ! will be indented 4 spaces and `.false.` implying no indentation. `indent`
461
488
! ! has a startup value of `.true.`.
462
- ! ! 3. `max_width` is the maximum number of columns of output text with
489
+ ! ! 3. `level` is the lowest level for printing a message
490
+ ! ! 4. `max_width` is the maximum number of columns of output text with
463
491
! ! `max_width == 0` => no bounds on output width. `max_width` has a startup
464
492
! ! value of 0.
465
- ! ! 4 . `time_stamp` is a logical flag with `.true.` implying that the output
493
+ ! ! 5 . `time_stamp` is a logical flag with `.true.` implying that the output
466
494
! ! will have a time stamp, and `.false.` implying that there will be no
467
495
! ! time stamp. `time_stamp` has a startup value of `.true.`.
468
496
! !([Specification](../page/specs/stdlib_logger.html#configure-configure-the-logging-process))
@@ -477,10 +505,12 @@ pure subroutine configure( self, add_blank_line, indent, max_width, &
477
505
class(logger_type), intent (inout ) :: self
478
506
logical , intent (in ), optional :: add_blank_line
479
507
logical , intent (in ), optional :: indent
508
+ integer , intent (in ), optional :: level
480
509
integer , intent (in ), optional :: max_width
481
510
logical , intent (in ), optional :: time_stamp
482
511
483
512
if ( present (add_blank_line) ) self % add_blank_line = add_blank_line
513
+ if ( present (level) ) self % level = level
484
514
if ( present (indent) ) self % indent_lines = indent
485
515
if ( present (max_width) ) then
486
516
if ( max_width <= 4 ) then
@@ -803,11 +833,13 @@ subroutine log_debug( self, message, module, procedure )
803
833
character (len=* ), intent (in ) :: message
804
834
! ! A string to be written to log_unit
805
835
character (len=* ), intent (in ), optional :: module
806
- ! ! The name of the module contining the current invocation of `log_information`
836
+ ! ! The name of the module containing the current invocation of `log_information`
807
837
character (len=* ), intent (in ), optional :: procedure
808
- ! ! The name of the procedure contining the current invocation of
838
+ ! ! The name of the procedure containing the current invocation of
809
839
! ! `log_information`
810
840
841
+ if ( self % level > debug_level ) return
842
+
811
843
call self % log_message( message, &
812
844
module = module , &
813
845
procedure = procedure , &
@@ -865,9 +897,9 @@ subroutine log_error( self, message, module, procedure, stat, errmsg )
865
897
character (len=* ), intent (in ) :: message
866
898
! ! A string to be written to log_unit
867
899
character (len=* ), intent (in ), optional :: module
868
- ! ! The name of the module contining the current invocation of `log_error`
900
+ ! ! The name of the module containing the current invocation of `log_error`
869
901
character (len=* ), intent (in ), optional :: procedure
870
- ! ! The name of the procedure contining the current invocation of `log_error`
902
+ ! ! The name of the procedure containing the current invocation of `log_error`
871
903
integer , intent (in ), optional :: stat
872
904
! ! The value of the `stat` specifier returned by a Fortran statement
873
905
character (len=* ), intent (in ), optional :: errmsg
@@ -879,6 +911,8 @@ subroutine log_error( self, message, module, procedure, stat, errmsg )
879
911
character (* ), parameter :: procedure_name = ' log_error'
880
912
character (:), allocatable :: suffix
881
913
914
+ if ( self % level > error_level ) return
915
+
882
916
if ( present (stat) ) then
883
917
write ( dummy, ' (a, i0)' , err= 999 , iostat= iostat, iomsg= iomsg ) &
884
918
new_line(' a' ) // " With stat = " , stat
@@ -954,11 +988,13 @@ subroutine log_information( self, message, module, procedure )
954
988
character (len=* ), intent (in ) :: message
955
989
! ! A string to be written to log_unit
956
990
character (len=* ), intent (in ), optional :: module
957
- ! ! The name of the module contining the current invocation of `log_information`
991
+ ! ! The name of the module containing the current invocation of `log_information`
958
992
character (len=* ), intent (in ), optional :: procedure
959
- ! ! The name of the procedure contining the current invocation of
993
+ ! ! The name of the procedure containing the current invocation of
960
994
! ! `log_information`
961
995
996
+ if ( self % level > information_level ) return
997
+
962
998
call self % log_message( message, &
963
999
module = module , &
964
1000
procedure = procedure , &
@@ -1007,9 +1043,9 @@ subroutine log_io_error( self, message, module, procedure, iostat, &
1007
1043
character (len=* ), intent (in ) :: message
1008
1044
! ! A string to be written to LOG_UNIT
1009
1045
character (len=* ), intent (in ), optional :: module
1010
- ! ! The name of the module contining the current invocation of REPORT_ERROR
1046
+ ! ! The name of the module containing the current invocation of REPORT_ERROR
1011
1047
character (len=* ), intent (in ), optional :: procedure
1012
- ! ! The name of the procedure contining the current invocation of REPORT_ERROR
1048
+ ! ! The name of the procedure containing the current invocation of REPORT_ERROR
1013
1049
integer , intent (in ), optional :: iostat
1014
1050
! ! The value of the IOSTAT specifier returned by a Fortran I/O statement
1015
1051
character (len=* ), intent (in ), optional :: iomsg
@@ -1021,6 +1057,8 @@ subroutine log_io_error( self, message, module, procedure, iostat, &
1021
1057
character (* ), parameter :: procedure_name = ' log_io_error'
1022
1058
character (:), allocatable :: suffix
1023
1059
1060
+ if ( self % level > io_error_level ) return
1061
+
1024
1062
if ( present (iostat) ) then
1025
1063
write ( dummy, ' (a, i0)' , err= 999 , iostat= iostat2, iomsg= iomsg2 ) &
1026
1064
new_line(' a' ) // " With iostat = " , iostat
@@ -1093,9 +1131,9 @@ subroutine log_message( self, message, module, procedure, prefix )
1093
1131
character (len=* ), intent (in ) :: message
1094
1132
! ! A string to be written to log_unit
1095
1133
character (len=* ), intent (in ), optional :: module
1096
- ! ! The name of the module contining the current invocation of `log_message`
1134
+ ! ! The name of the module containing the current invocation of `log_message`
1097
1135
character (len=* ), intent (in ), optional :: procedure
1098
- ! ! The name of the procedure contining the current invocation of `log_message`
1136
+ ! ! The name of the procedure containing the current invocation of `log_message`
1099
1137
character (len=* ), intent (in ), optional :: prefix
1100
1138
! ! To be prepended to message as `prefix // ': ' // message`.
1101
1139
@@ -1239,6 +1277,8 @@ subroutine log_text_error( self, line, column, summary, filename, &
1239
1277
character (* ), parameter :: procedure_name = ' LOG_TEXT_ERROR'
1240
1278
character (len= :), allocatable :: buffer
1241
1279
1280
+ if ( self % level > text_error_level ) return
1281
+
1242
1282
acaret = optval(caret, ' ^' )
1243
1283
1244
1284
if ( column < 0 .or. column > len ( line ) + 1 ) then
@@ -1428,9 +1468,11 @@ subroutine log_warning( self, message, module, procedure )
1428
1468
character (len=* ), intent (in ) :: message
1429
1469
! ! A string to be written to LOG_UNIT
1430
1470
character (len=* ), intent (in ), optional :: module
1431
- ! ! The name of the module contining the current invocation of `log_warning`
1471
+ ! ! The name of the module containing the current invocation of `log_warning`
1432
1472
character (len=* ), intent (in ), optional :: procedure
1433
- ! ! The name of the procedure contining the current invocation of `log_warning`
1473
+ ! ! The name of the procedure containing the current invocation of `log_warning`
1474
+
1475
+ if ( self % level > warning_level ) return
1434
1476
1435
1477
call self % log_message( message, &
1436
1478
module = module , &
0 commit comments