ESMF_LogSet Subroutine

public subroutine ESMF_LogSet(log, keywordEnforcer, flush, logmsgAbort, maxElements, logmsgList, errorMask, trace, highResTimestampFlag, indentCount, noPrefix, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Log), intent(inout), optional :: log
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
logical, intent(in), optional :: flush
type(ESMF_LogMsg_Flag), intent(in), optional :: logmsgAbort(:)
integer, intent(in), optional :: maxElements
type(ESMF_LogMsg_Flag), intent(in), optional :: logmsgList(:)
integer, intent(in), optional :: errorMask(:)
logical, intent(in), optional :: trace
logical, intent(in), optional :: highResTimestampFlag
integer, intent(in), optional :: indentCount
logical, intent(in), optional :: noPrefix
integer, intent(out), optional :: rc

Source Code

    subroutine ESMF_LogSet(log, keywordEnforcer,  &
        flush,  &
        logmsgAbort, maxElements, logmsgList,  &
        errorMask, trace, highResTimestampFlag, indentCount,  &
        noPrefix, rc)
!
! !ARGUMENTS:
!
      type(ESMF_Log),         intent(inout), optional :: log
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      logical,                intent(in),    optional :: flush
      type(ESMF_LogMsg_Flag), intent(in),    optional :: logmsgAbort(:)
      integer,                intent(in),    optional :: maxElements
      type(ESMF_LogMsg_Flag), intent(in),    optional :: logmsgList(:)
      integer,                intent(in),    optional :: errorMask(:)
      logical,                intent(in),    optional :: trace
      logical,                intent(in),    optional :: highResTimestampFlag
      integer,                intent(in),    optional :: indentCount
      logical,                intent(in),    optional :: noPrefix
      integer,                intent(out),   optional :: rc

!
! !DESCRIPTION:
!      This subroutine sets the properties for the Log object.
!
!      The arguments are:
!      \begin{description}
!
!      \item [{[log]}]
!            An optional {\tt ESMF\_Log} object.  The default is to use the
!            default log that was opened at {\tt ESMF\_Initialize} time.
!      \item [{[flush]}]
!            If set to {\tt .true.}, flush log messages immediately, rather
!            than buffering them.  Default is to flush after {\tt maxElements}
!            messages.
!      \item [{[logmsgAbort]}]
!            Sets the condition on which ESMF aborts.  The array
!            can contain any combination of {\tt ESMF\_LOGMSG} named constants.  These
!            named constants are described in section \ref{const:logmsgflag}.
!            Default is to always continue processing.
!      \item [{[maxElements]}]
!            Maximum number of elements in the Log buffer before flushing occurs.
!            Default is to flush when 10 messages have been accumulated.
!      \item [{[logmsgList]}]
!            An array of message types that will be logged.  Log write requests
!            not matching the list will be ignored.  If an empty array is
!            provided, no messages will be logged.
!            See section \ref{const:logmsgflag} for a list of
!            valid message types.  By default, all non-trace messages will be
!            logged.
!      \item [{[errorMask]}]
!            List of error codes that will {\em not} be logged as errors.
!            Default is to log all error codes.
!      \item [{[trace]}]
!            \begin{sloppypar}
!            If set to {\tt .true.}, calls such as {\tt ESMF\_LogFoundError()},
!            {\tt ESMF\_LogFoundAllocError()}, and
!            {\tt ESMF\_LogFoundDeallocError()}
!            will be logged in the default log files.  This option is intended
!            to be used as a tool for debugging and program flow tracing
!            within the ESMF library. Voluminous output may appear in the log,
!            with a consequent slowdown in performance.  Therefore, it is
!            recommended that this option only be enabled before a problematic
!            call to a ESMF method, and disabled afterwards. Default is to
!            not trace these calls.
!           \end{sloppypar}
!      \item [{[highResTimestampFlag]}]
!            Sets the extended elapsed timestamp flag.  If set to {\tt .true.}, a timestamp
!            from {\tt ESMF\_VMWtime} will be included in each log message.  Default is
!            to not add the additional timestamps.
!      \item [{[indentCount]}]
!            Number of leading white spaces.
!      \item [{[noPrefix]}]
!            If set to {\tt .false.}, log messages are prefixed with time stamps,
!            message type and PET number.  If set to {\tt .true.} the messages will be
!            written without the prefixes.
!      \item [{[rc]}]
!            Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!      \end{description}
!
!EOP
    integer :: i, status, status2
    logical :: isDefault
    type(ESMF_LogPrivate), pointer          :: alog
    type(ESMF_LogEntry), dimension(:), pointer :: localbuf
    type(ESMF_Logical) :: traceFlag_c

    ESMF_INIT_CHECK_SET_SHALLOW(ESMF_LogGetInit,ESMF_LogInit,log)

    nullify(alog) ! ensure that the association status is well defined

    isDefault = .false.
    if (present(log)) then
      if (log%logTableIndex > 0) then
         alog => ESMF_LogTable(log%logTableIndex)
      endif
    else
      if (ESMF_LogDefault%logTableIndex > 0) then
        alog => ESMF_LogTable(ESMF_LogDefault%logTableIndex)
        isDefault = .true.
      end if
    endif

    ! Initialize return code; assume routine not implemented
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

    if (associated(alog)) then

      ESMF_INIT_CHECK_SET_SHALLOW(ESMF_LogPrivateGetInit,ESMF_LogPrivateInit,alog)

      if (alog%FileIsOpen /= ESMF_TRUE .and. .not. isDefault) then
        write (ESMF_UtilIOStderr,*) ESMF_METHOD,  &
            ": ESMF_Log not open -- cannot ESMF_LogSet()."
        call ESMF_UtilIOUnitFlush(ESMF_UtilIOStderr, rc=rc)
        if (present (rc)) rc = ESMF_RC_CANNOT_SET
        return
      endif

      if (present(flush)) then
        alog%flushImmediately=flush
      endif
      if (present(logmsgAbort)) then
        if (associated (alog%logmsgAbort)) deallocate (alog%logmsgAbort)
        allocate (alog%logmsgAbort(size (logmsgAbort)))
        alog%logmsgAbort = logmsgAbort
      endif
      if (present(maxElements)) then
        if (maxElements>0 .AND. alog%maxElements/=maxElements) then
          allocate(localbuf(maxElements), stat=status)

          ! if the current number of log entries is greater than the new
          ! maxElements, then call flush.  Otherwise copy old contents over.
          if (alog%fIndex.ge.maxElements) then
            call ESMF_LogFlush(log,rc=status)
          else
            do i = 1,alog%fIndex
              call ESMF_LogEntryCopy(alog%LOG_ENTRY(i), localbuf(i), rc=status)
            enddo
          endif
          deallocate(alog%LOG_ENTRY,stat=status)
          alog%LOG_ENTRY => localbuf
          alog%maxElements=maxElements
        endif
      endif
      if (present(errorMask)) then
        if (alog%errorMaskCount > 0) then
          deallocate(alog%errorMask)
        endif
        alog%errorMaskCount = size(errorMask)
        allocate(alog%errorMask(alog%errorMaskCount))
        alog%errorMask = errorMask  ! copy the content of the errorMask argument
      endif

      ! currently the connection between F90 and C++ side of LogErr is only well
      ! defined for the default Log, so only then call the C++ side LogSet().
      if (isDefault) then
        !TODO: I am only implementing this to get the errorMask into the C++ side
        !TODO: LogErr needs major help anyway, so someday this may get sorted out
        !TODO: to work for more general cases. *gjt*
        if (present(errorMask)) then
          call c_ESMC_LogSet(alog%errorMask(1),alog%errorMaskCount,status2)
        endif
      endif

      if (present (logmsgList)) then
        if (associated (alog%logmsgList))  &
          deallocate (alog%logmsgList)
          allocate (alog%logmsgList(size (logmsgList)))
          alog%logmsgList = logmsgList
      end if

      if (present (trace)) then
        alog%traceFlag = trace
        if (isDefault) then
          !TODO: Should work with user logs as well.  wws...
          traceFlag_c = trace
          call c_ESMC_LogSetTrace (traceFlag_c, status2)
        end if
        if (trace) then
          call ESMF_LogWrite ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
          call ESMF_LogWrite ('!!!        TRACING IS ENABLED         !!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
          call ESMF_LogWrite ('!!! MAY CAUSE SLOWDOWN IN PERFORMANCE !!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
          call ESMF_LogWrite ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
        else
          call ESMF_LogWrite ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
          call ESMF_LogWrite ('!!!       TRACING is disabled         !!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
          call ESMF_LogWrite ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!',  &
              ESMF_LOGMSG_TRACE, method=ESMF_METHOD, log=log)
        end if
      end if

      if (present (highResTimestampFlag)) then
        alog%highResTimestampFlag = highResTimestampFlag
      end if

      if (present (indentCount)) then
        alog%indentCount = indentCount
      end if

      if (present (noPrefix)) then
        if (noPrefix .and. .not. isDefault) then
          alog%noPrefix = noPrefix
        else
          call ESMF_LogWrite ('Can not set noPrefix on default Log', method=ESMF_METHOD, log=log)
          if (present (rc)) rc = ESMF_RC_CANNOT_SET
          return
        end if
      end if

      if (present(rc)) then
        rc=ESMF_SUCCESS
      endif
    endif

end subroutine ESMF_LogSet