log_message Subroutine

public subroutine log_message(message, level)

Send a log message to the log file

Log levels: DEBUG, INFO, WARNING and ERROR

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: message

Message to log

integer, intent(in) :: level

Log level


Calls

proc~~log_message~~CallsGraph proc~log_message log_message proc~write_log write_log proc~log_message->proc~write_log

Called by

proc~~log_message~~CalledByGraph proc~log_message log_message proc~log_header log_header proc~log_header->proc~log_message

Source Code

    subroutine log_message(message, level)
        !! Send a log message to the log file
        !!
        !! Log levels: DEBUG, INFO, WARNING and ERROR
        character(len=*), intent(in) :: message !! Message to log
        integer, intent(in) :: level !! Log level
        
        ! Local variables
        character(len=18) :: timestamp
        character(len=8) :: datestr
        character(len=10) :: timestr

        ! Get current date and time
        call date_and_time(date=datestr, time=timestr)
        timestamp = '[' // datestr // ' ' // timestr(1:6) // '] '

        if (level >= log_level) then
            select case(level)
            case(DEBUG)
                call write_log(timestamp // '[DEBUG] ' // message)
            case(INFO)
                call write_log(timestamp // '[INFO]  ' // message)
            case(WARNING)
                call write_log(timestamp // '[WARN]  ' // message)
            case(ERROR)
                call write_log(timestamp // '[ERROR] ' // message)
            case default
                print "(a)", "ERROR: Invalid log level: ", level
                stop 1
            end select
        end if
    end subroutine log_message