diff --git a/src/stdlib_logger.f90 b/src/stdlib_logger.f90 index 0cdaa4f36..e9f238924 100644 --- a/src/stdlib_logger.f90 +++ b/src/stdlib_logger.f90 @@ -435,10 +435,12 @@ pure subroutine configuration( self, add_blank_line, indent, & if ( present(indent) ) indent = self % indent_lines if ( present(max_width) ) max_width = self % max_width if ( present(time_stamp) ) time_stamp = self % time_stamp - if ( present(log_units) .and. self % units .gt. 0 ) then - log_units = self % log_units(1:self % units) - else - allocate(log_units(0)) + if ( present(log_units) ) then + if ( self % units .gt. 0 ) then + log_units = self % log_units(1:self % units) + else + allocate(log_units(0)) + end if end if end subroutine configuration diff --git a/src/tests/logger/test_stdlib_logger.f90 b/src/tests/logger/test_stdlib_logger.f90 index 9c7c9944e..1f55499e8 100644 --- a/src/tests/logger/test_stdlib_logger.f90 +++ b/src/tests/logger/test_stdlib_logger.f90 @@ -126,6 +126,62 @@ subroutine test_logging_configuration() end if + !testing all calls independently + call global % configuration( add_blank_line=add_blank_line ) + + if ( .not. add_blank_line ) then + write(*,*) 'ADD_BLANK_LINE starts off as .FALSE. as expected.' + + else + error stop 'ADD_BLANK_LINE starts off as .TRUE. contrary to ' // & + 'expectations.' + + end if + + call global % configuration( indent=indent ) + + if ( indent ) then + write(*,*) 'INDENT starts off as .TRUE. as expected.' + + else + error stop 'INDENT starts off as .FALSE. contrary to expectations.' + + end if + + call global % configuration( max_width=max_width ) + + if ( max_width == 0 ) then + write(*,*) 'MAX_WIDTH starts off as 0 as expected.' + + else + error stop 'MAX_WIDTH starts off as not equal to 0 contrary ' // & + 'to expectations.' + + end if + + call global % configuration( time_stamp=time_stamp ) + + if ( time_stamp ) then + write(*,*) 'TIME_STAMP starts off as .TRUE. as expected.' + + else + error stop 'TIME_STAMP starts off as .FALSE. contrary to ' // & + 'expectations.' + + end if + + call global % configuration( log_units=log_units ) + + if ( size(log_units) == 0 ) then + write(*,*) 'SIZE(LOG_UNITS) starts off as 0 as expected.' + + else + error stop 'SIZE(LOG_UNITS) starts off as non-zero contrary ' // & + 'to expectations.' + + end if + + call global % log_information( 'This message should be output ' // & 'to OUTPUT_UNIT, unlimited in width, not preceded by ' // & 'a blank line, then by a time stamp, then by MODULE % ' // &