Send a log message to the log file
Log levels: DEBUG, INFO, WARNING and ERROR
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | message |
Message to log |
||
integer, | intent(in) | :: | level |
Log level |
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