LogLib Module

History

current version 1.2 - 3rd April 2010

version date comment
1.0 01/Feb/2007 Original code
1.1 25/Sep/2008 Code revised
1.2 03/Apr/2010 separate log on file and screen

License

license: GNU GPL http://www.gnu.org/licenses/

This file is part of

MOSAICO -- MOdular library for raSter bAsed hydrologIcal appliCatiOn.

Copyright (C) 2011 Giovanni Ravazzani

Module Description

Basic set of routines to handle errors and manage log file. Three severity of log are defined: error (logLevel = 1): report only error messages warning (logLevel = 2): report error and warning messages info (logLevel = 3): report error, warning and informative messages The default logLevel is 3 (write all) and log messages are written on default output unit (screen).If necessary, the user can override default parameters by passing command line options. example of option passed from command line:

executable -loglevel error

The user can choose to write messages also on a file:

executable -loglevel warning -logfile log.csv

The module is initialized before the rest of the program takes place so it is better that this module is kept self containing and not to use utilities contained in other complicated modules that may want to use log facilities.



Variables

Type Visibility Attributes Name Initial
logical, public :: logToFile = .FALSE.
logical, public :: logToScreen = .TRUE.
integer(kind=short), public :: logUnit

file unit for log reporting

integer(kind=short), public, parameter :: stdIn = 5

standard input

integer(kind=short), public, parameter :: stdOut = 6

standar output

logical, public :: verbose = .TRUE.

display messages on the screen default value = TRUE

integer(kind=short), private :: ios
character(len=stringLen), private :: logFile

file for log reporting

integer(kind=short), private :: logLevel = 3

log level; default=3

character(len=1), private, parameter :: logsep = ","

log separator

integer(kind=short), private, parameter :: stringLen = 500

Functions

private function GetUnit() result(iunit)

returns a free FORTRAN unit number Discussion: A "free" FORTRAN unit number is an integer between 1 and 99 which is not currently associated with an I/O device. A free FORTRAN unit number is needed in order to open a file with the OPEN command. If IUNIT = 0, then no free FORTRAN unit could be found, although all 99 units were checked (except for units 5 and 6). Otherwise, IUNIT is an integer between 1 and 99, representing a free FORTRAN unit. Note that GetUnit assumes that units 5 and 6 are special, and will never return those values. Adapted from John Burkardt

Arguments

None

Return Value integer(kind=short)


Subroutines

public subroutine Catch(level, process, comment, code, argument)

exception handler

Arguments

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

log level: info | warning | error

character(len=*), intent(in) :: process

process which threw esception

character(len=*), intent(in) :: comment

comment on exception

integer(kind=short), intent(in), optional :: code

error code to return

character(len=*), intent(in), optional :: argument

optional argument

public subroutine LogInit()

initialize global parameters

Arguments

None

public subroutine LogMsg(unit, level, process, comment, argument)

write a formatted string on specified unit- It is called by Catch routine

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: unit
character(len=*), intent(in) :: level

log level: info, warning, error

character(len=*), intent(in) :: process

process which puts log

character(len=*), intent(in) :: comment

comment on log

character(len=*), intent(in), optional :: argument

optional argument

public subroutine LogStop()

stop logging. If open, close the log file

Arguments

None

private subroutine TimeStamp(unit)

prints the current YMDHMS date as a time stamp. Example: 2008-09-29T21:00:25.624+0200 Adapted from John Burkardt

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: unit