MONC
logging.F90
Go to the documentation of this file.
1 
2 module logging_mod
3  implicit none
4 
5 #ifndef TEST_MODE
6  private
7 #endif
8 
9  integer, parameter, private :: master_process = 0
10 
11  integer, parameter, public :: log_error = 1
12  integer, parameter, public :: log_warn = 2
13  integer, parameter, public :: log_info = 3
14  integer, parameter, public :: log_debug = 4
15 
16  character(len=*), parameter :: error_preamble = "[ERROR]",& !< Error message preamble
17  warn_preamble = "[WARN]",&
18  info_preamble = "[INFO]",&
19  debug_preamble = "[DEBUG]"
20 
24  logical, parameter :: error_is_fatal=.true.
26  logical, save :: i_am_master=.true.
27 
30 
31 contains
32 
36  subroutine initialise_logging(pid)
37  integer, intent(in) :: pid
38 
40  end subroutine initialise_logging
41 
46  subroutine log_master_log(level, message)
47  integer, intent(in) :: level
48  character(len=*), intent(in) :: message
49 
50  if (i_am_master) then
51  call log_log(level, message)
52  else
53  if (error_is_fatal .and. level .eq. log_error) call abort()
54  end if
55  end subroutine log_master_log
56 
58  subroutine log_master_newline()
59  if (i_am_master) write(*,*) ""
60  end subroutine log_master_newline
61 
65  logical function log_is_master()
67  end function log_is_master
68 
74  subroutine log_log(level, message, str)
75  integer, intent(in) :: level
76  character(len=*), intent(in) :: message
77  character(len=*), intent(out), optional :: str
78 
79  if (level .le. current_log_level) then
80  if (present(str)) then
81  write(str,"(A,A,A)") trim(get_logging_preamble(level)), " ",message
82  else
83  write(*,"(A,A,A)") trim(get_logging_preamble(level)), " ", message
84  end if
85  end if
86  if (error_is_fatal .and. level .eq. log_error) call abort()
87  end subroutine log_log
88 
90  subroutine log_newline()
91  write(*,*) ""
92  end subroutine log_newline
93 
97  character(len=7) function get_logging_preamble(level)
98  integer, intent(in) :: level
99 
100  if (level .eq. log_error) then
102  else if (level .eq. log_warn) then
104  else if (level .eq. log_info) then
106  else
108  end if
109  end function get_logging_preamble
110 
113  subroutine log_set_logging_level(level)
114  integer, intent(in) :: level
115 
116  current_log_level = level
117  end subroutine log_set_logging_level
118 
121  integer function log_get_logging_level()
123  end function log_get_logging_level
124 end module logging_mod
logging_mod::log_error
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
logging_mod::get_logging_preamble
character(len=7) function get_logging_preamble(level)
Returns the string preamble that applies to the specific logging level.
Definition: logging.F90:98
logging_mod::initialise_logging
subroutine, public initialise_logging(pid)
Initialises the logging. This is done to make it easier for master logging only, so that we don't hav...
Definition: logging.F90:37
logging_mod::i_am_master
logical, save i_am_master
Whether or not I am the master process.
Definition: logging.F90:26
logging_mod::log_warn
integer, parameter, public log_warn
Log WARNING and ERROR messages.
Definition: logging.F90:12
logging_mod::log_newline
subroutine, public log_newline()
Will log a new line to the stdout.
Definition: logging.F90:91
logging_mod::log_info
integer, parameter, public log_info
Log INFO, WARNING and ERROR messages.
Definition: logging.F90:13
logging_mod::log_log
subroutine, public log_log(level, message, str)
Logs a message at the specified level. If the level is above the current level then the message is ig...
Definition: logging.F90:75
logging_mod::log_get_logging_level
integer function, public log_get_logging_level()
Retrieves the current logging level.
Definition: logging.F90:122
logging_mod::log_debug
integer, parameter, public log_debug
Log DEBUG, INFO, WARNING and ERROR messages.
Definition: logging.F90:14
logging_mod::error_preamble
character(len= *), parameter error_preamble
Error message preamble.
Definition: logging.F90:16
logging_mod::error_is_fatal
logical, parameter error_is_fatal
Whether an error log message is fatal and stops execution.
Definition: logging.F90:24
logging_mod::master_process
integer, parameter, private master_process
Definition: logging.F90:9
logging_mod::log_set_logging_level
subroutine, public log_set_logging_level(level)
Sets the logging level, messages with less priority will be ignored.
Definition: logging.F90:114
logging_mod::warn_preamble
character(len= *), parameter warn_preamble
Warning message preable.
Definition: logging.F90:16
logging_mod::info_preamble
character(len= *), parameter info_preamble
Info message preamble.
Definition: logging.F90:16
logging_mod::log_is_master
logical function, public log_is_master()
Determines whether the process is the master logging process. This might be preferable rather than ca...
Definition: logging.F90:66
logging_mod
Logging utility.
Definition: logging.F90:2
logging_mod::log_master_newline
subroutine, public log_master_newline()
The master process will log a new line to stdio.
Definition: logging.F90:59
logging_mod::current_log_level
integer current_log_level
Private current logging state, the default is INFO level.
Definition: logging.F90:22
logging_mod::log_master_log
subroutine, public log_master_log(level, message)
Will log just from the master process.
Definition: logging.F90:47
logging_mod::debug_preamble
character(len= *), parameter debug_preamble
Debug message preamble.
Definition: logging.F90:16