Skip to content

Commit bde8ce8

Browse files
committed
level_logger: addition of levels
1 parent e190a7b commit bde8ce8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/stdlib_logger.f90

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ module stdlib_logger
6868
unopened_in_error = 7, &
6969
write_failure = 8
7070

71+
integer, parameter, public :: &
72+
stdlib_debug_level = 10, &
73+
stdlib_information_level = 20, &
74+
stdlib_warning_level = 30, &
75+
stdlib_error_level = 40, &
76+
stdlib_io_error_level = 40, &
77+
stdlib_text_error_level = 40
78+
79+
7180
character(*), parameter :: module_name = 'stdlib_logger'
7281

7382
type :: logger_type
@@ -78,6 +87,7 @@ module stdlib_logger
7887

7988
logical :: add_blank_line = .false.
8089
logical :: indent_lines = .true.
90+
integer :: level = stdlib_information_level
8191
integer, allocatable :: log_units(:)
8292
integer :: max_width = 0
8393
logical :: time_stamp = .true.
@@ -806,6 +816,8 @@ subroutine log_debug( self, message, module, procedure )
806816
!! The name of the procedure contining the current invocation of
807817
!! `log_information`
808818

819+
if ( self % level > stdlib_debug_level) return
820+
809821
call self % log_message( message, &
810822
module = module, &
811823
procedure = procedure, &
@@ -877,6 +889,8 @@ subroutine log_error( self, message, module, procedure, stat, errmsg )
877889
character(*), parameter :: procedure_name = 'log_error'
878890
character(:), allocatable :: suffix
879891

892+
if ( self % level > stdlib_error_level) return
893+
880894
if ( present(stat) ) then
881895
write( dummy, '(a, i0)', err=999, iostat=iostat, iomsg=iomsg ) &
882896
new_line('a') // "With stat = ", stat
@@ -957,6 +971,8 @@ subroutine log_information( self, message, module, procedure )
957971
!! The name of the procedure contining the current invocation of
958972
!! `log_information`
959973

974+
if ( self % level > stdlib_information_level) return
975+
960976
call self % log_message( message, &
961977
module = module, &
962978
procedure = procedure, &
@@ -1019,6 +1035,8 @@ subroutine log_io_error( self, message, module, procedure, iostat, &
10191035
character(*), parameter :: procedure_name = 'log_io_error'
10201036
character(:), allocatable :: suffix
10211037

1038+
if ( self % level > stdlib_io_error_level) return
1039+
10221040
if ( present(iostat) ) then
10231041
write( dummy, '(a, i0)', err=999, iostat=iostat2, iomsg=iomsg2 ) &
10241042
new_line('a') // "With iostat = ", iostat
@@ -1237,6 +1255,8 @@ subroutine log_text_error( self, line, column, summary, filename, &
12371255
character(*), parameter :: procedure_name = 'LOG_TEXT_ERROR'
12381256
character(len=:), allocatable :: buffer
12391257

1258+
if ( self % level > stdlib_text_error_level) return
1259+
12401260
acaret = optval(caret, '^')
12411261

12421262
if ( column < 0 .or. column > len( line ) + 1 ) then

0 commit comments

Comments
 (0)