aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-08 15:54:53 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-08 15:54:53 -0400
commit29ab398f73c791f9591674c813c47267c524e6be (patch)
tree81308e2179837a280498f40edb3d1ce6a608d446 /captain
parentdef9f944e774a6b529916a8d79c9511b56065392 (diff)
downloadlevitating-29ab398f73c791f9591674c813c47267c524e6be.tar.gz
levitating-29ab398f73c791f9591674c813c47267c524e6be.zip
Added concept of logging level. Log file now opened and closed on every write to avoid possible locking issues. Build is broken because of log init call.
Diffstat (limited to 'captain')
-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