Skip to content

Commit 5e68920

Browse files
committed
Fixed up log_error and log_io_error
Changed log_error and log_io_error similarly 1. Added dummy character variable of len 28 and used it to hold stat/iostat string representation or lack thereof. 2. Changed suffix to allocatable len character variable and used it to hold the combined stat/iostat and errmsg/iomsg string representations or lack thereof. 3. Eliminated the trim of suffix as unneeded. 4. Eliminated unit and passed -999 directly to handle_write_failure. 5. For log_io_error changed procedure_name to 'log_io_error'. [ticket: X]
1 parent 0b95dbb commit 5e68920

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/stdlib_logger.f90

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -808,32 +808,38 @@ subroutine log_error( self, message, module, procedure, stat, errmsg )
808808
character(len=*), intent(in), optional :: errmsg
809809
!! The value of the `errmsg` specifier returned by a Fortran statement
810810

811-
integer :: unit
812811
integer :: iostat
812+
character(28) :: dummy
813+
character(256) :: iomsg
813814
character(*), parameter :: procedure_name = 'log_error'
814-
character(256) :: iomsg, suffix
815+
character(:), allocatable :: suffix
815816

816817
if ( present(stat) ) then
817-
write( suffix, '(a, i0)', err=999, iostat=iostat, iomsg=iomsg ) &
818+
write( dummy, '(a, i0)', err=999, iostat=iostat, iomsg=iomsg ) &
818819
new_line('a') // "With stat = ", stat
820+
else
821+
dummy = ' '
819822
end if
820823

821824
if ( present(errmsg) ) then
822825
if ( len_trim(errmsg) > 0 ) then
823-
suffix( len_trim(suffix)+1: ) = &
826+
suffix = trim(dummy) // &
824827
new_line('a') // 'With errmsg = "' // trim(errmsg) // '"'
828+
else
829+
suffix = dummy
825830
end if
831+
else
832+
suffix = dummy
826833
end if
827834

828-
call self % log_message( trim(message) // trim(suffix), &
829-
module = module, &
830-
procedure = procedure, &
835+
call self % log_message( trim(message) // suffix, &
836+
module = module, &
837+
procedure = procedure, &
831838
prefix = 'ERROR')
832839

833840
return
834841

835-
unit = -999
836-
999 call handle_write_failure( unit, procedure_name, iostat, iomsg )
842+
999 call handle_write_failure( -999, procedure_name, iostat, iomsg )
837843

838844
end subroutine log_error
839845

@@ -944,32 +950,38 @@ subroutine log_io_error( self, message, module, procedure, iostat, &
944950
character(len=*), intent(in), optional :: iomsg
945951
!! The value of the IOMSG specifier returned by a Fortran I/O statement
946952

947-
integer :: unit
953+
character(28) :: dummy
954+
character(256) :: iomsg2
948955
integer :: iostat2
949-
character(*), parameter :: procedure_name = 'log_error'
950-
character(256) :: iomsg2, suffix
956+
character(*), parameter :: procedure_name = 'log_io_error'
957+
character(:), allocatable :: suffix
951958

952959
if ( present(iostat) ) then
953-
write( suffix, '(a, i0)', err=999, iostat=iostat2, iomsg=iomsg2 ) &
960+
write( dummy, '(a, i0)', err=999, iostat=iostat2, iomsg=iomsg2 ) &
954961
new_line('a') // "With iostat = ", iostat
962+
else
963+
dummy = ' '
955964
end if
956965

957966
if ( present(iomsg) ) then
958967
if ( len_trim(iomsg) > 0 ) then
959-
suffix( len_trim(suffix)+1: ) = &
968+
suffix = trim(dummy) // &
960969
new_line('a') // 'With iomsg = "' // trim(iomsg) // '"'
970+
else
971+
suffix = trim(dummy)
961972
end if
973+
else
974+
suffix = trim(dummy)
962975
end if
963976

964-
call self % log_message( trim(message) // trim(suffix), &
965-
module = module, &
966-
procedure = procedure, &
977+
call self % log_message( trim(message) // suffix, &
978+
module = module, &
979+
procedure = procedure, &
967980
prefix = 'I/O ERROR' )
968981

969982
return
970983

971-
unit = -999
972-
999 call handle_write_failure( unit, procedure_name, iostat, iomsg )
984+
999 call handle_write_failure( -999, procedure_name, iostat2, iomsg2 )
973985

974986
end subroutine log_io_error
975987

0 commit comments

Comments
 (0)