aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--captain/log.f9043
1 files changed, 35 insertions, 8 deletions
diff --git a/captain/log.f90 b/captain/log.f90
index 3757faf..44ba46e 100644
--- a/captain/log.f90
+++ b/captain/log.f90
@@ -1,33 +1,60 @@
module logging
implicit none
+
+ integer, parameter::logunit = 1197
+
+ integer::level_threshold
- integer::logunit
+ character(len=:), pointer::logfile
+ !integer::logunit
contains
- subroutine initialize(filename)
+ subroutine initialize(filename, logging_threshold)
implicit none
character(*), intent(in)::filename
- open(newunit=logunit, file=trim(filename), action="write", status="unknown", position="append")
+ 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
- close(logunit)
+ deallocate(logfile)
+ logfile => null()
end subroutine shutdown
- subroutine write_log(string)
+ 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 flush(logunit)
+ ! GNU Extension... :(
+ write(logunit, *) fdate()//" :: "//string
+ call close(logunit)
+
+ end if
end subroutine write_log