MODULE logging ! see also logging.h ! macro LOGBUF accumulates log output into logging_buffer ! flush_plugin points to a procedure pointer that typically prints all lines in the buffer and prepends tags ! This module provides a default implementation of flush_plugin but the top-level driver is welcome to override it. IMPLICIT NONE SAVE PRIVATE INTERFACE SUBROUTINE plugin(lev, tag, buf) INTEGER, INTENT(IN) :: lev CHARACTER(*), INTENT(IN) :: tag, buf(:) END SUBROUTINE plugin END INTERFACE PROCEDURE(plugin), POINTER :: flush_plugin => default_flush_plugin INTEGER, PARAMETER :: bufsize=10000 CHARACTER(bufsize) :: logging_buf(100) INTEGER :: logging_lineno=0 INTEGER, PARAMETER, PUBLIC :: log_level_dbg=0, log_level_info=1 PUBLIC :: logging_buf, logging_lineno, flush_log, flush_plugin CONTAINS SUBROUTINE flush_log(lev,tag) INTEGER, INTENT(IN) :: lev CHARACTER(*), INTENT(IN) :: tag CALL flush_plugin(lev, TRIM(tag), logging_buf(1:logging_lineno)) logging_lineno=0 END SUBROUTINE flush_log SUBROUTINE default_flush_plugin(lev, tag, buf) INTEGER, INTENT(IN) :: lev CHARACTER(*), INTENT(IN) :: tag, buf(:) INTEGER :: i DO i=1, SIZE(buf) PRINT *, '[INFO ',tag,']', TRIM(buf(i)) END DO END SUBROUTINE default_flush_plugin END MODULE logging