module logging implicit none integer, parameter::logunit = 1197 integer::level_threshold character(len=:), pointer::logfile !integer::logunit contains subroutine initialize(filename, logging_threshold) implicit none character(*), intent(in)::filename integer, intent(in)::logging_threshold allocate(character(len=len_trim(filename)) :: logfile) logfile = filename level_threshold = logging_threshold end subroutine initialize subroutine shutdown() implicit none deallocate(logfile) logfile => null() end subroutine shutdown subroutine write_log(string, level) implicit none character(*), intent(in)::string integer, intent(in), optional::level integer::ierr if(present(level)) then if(level > level_threshold) then return end if end if open(unit=logunit, file=logfile, action="write", & status="unknown", position="append", iostat=ierr) ! Silently move on if we failed to open the file if(ierr == 0) then ! GNU Extension... :( write(logunit, *) fdate()//" :: "//string call close(logunit) end if end subroutine write_log end module logging