MONC
Functions/Subroutines | Variables
logging_mod Module Reference

Logging utility. More...

Functions/Subroutines

subroutine, public initialise_logging (pid)
 Initialises the logging. This is done to make it easier for master logging only, so that we don't have to pass the process ID in each time. More...
 
subroutine, public log_master_log (level, message)
 Will log just from the master process. More...
 
subroutine, public log_master_newline ()
 The master process will log a new line to stdio. More...
 
logical function, public log_is_master ()
 Determines whether the process is the master logging process. This might be preferable rather than calling masterLog due to having to construct the message for masterLog regardless. More...
 
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 ignored. If applicable then the message will be written to stdout or a provided string. More...
 
subroutine, public log_newline ()
 Will log a new line to the stdout. More...
 
character(len=7) function get_logging_preamble (level)
 Returns the string preamble that applies to the specific logging level. More...
 
subroutine, public log_set_logging_level (level)
 Sets the logging level, messages with less priority will be ignored. More...
 
integer function, public log_get_logging_level ()
 Retrieves the current logging level. More...
 

Variables

integer, parameter, private master_process = 0
 
integer, parameter, public log_error = 1
 Only log ERROR messages. More...
 
integer, parameter, public log_warn = 2
 Log WARNING and ERROR messages. More...
 
integer, parameter, public log_info = 3
 Log INFO, WARNING and ERROR messages. More...
 
integer, parameter, public log_debug = 4
 Log DEBUG, INFO, WARNING and ERROR messages. More...
 
character(len= *), parameter error_preamble = "[ERROR]"
 Error message preamble. More...
 
character(len= *), parameter warn_preamble = "[WARN]"
 Warning message preable. More...
 
character(len= *), parameter info_preamble = "[INFO]"
 Info message preamble. More...
 
character(len= *), parameter debug_preamble = "[DEBUG]"
 Debug message preamble. More...
 
integer current_log_level =LOG_INFO
 Private current logging state, the default is INFO level. More...
 
logical, parameter error_is_fatal =.true.
 Whether an error log message is fatal and stops execution. More...
 
logical, save i_am_master =.true.
 Whether or not I am the master process. More...
 

Detailed Description

Logging utility.

Function/Subroutine Documentation

◆ get_logging_preamble()

character(len=7) function logging_mod::get_logging_preamble ( integer, intent(in)  level)
private

Returns the string preamble that applies to the specific logging level.

Parameters
levelThe logging level to translate into a string
Returns
String representation of specific level

Definition at line 98 of file logging.F90.

98  integer, intent(in) :: level
99 
100  if (level .eq. log_error) then
101  get_logging_preamble = error_preamble
102  else if (level .eq. log_warn) then
103  get_logging_preamble = warn_preamble
104  else if (level .eq. log_info) then
105  get_logging_preamble = info_preamble
106  else
107  get_logging_preamble = debug_preamble
108  end if
Here is the caller graph for this function:

◆ initialise_logging()

subroutine, public logging_mod::initialise_logging ( integer, intent(in)  pid)

Initialises the logging. This is done to make it easier for master logging only, so that we don't have to pass the process ID in each time.

Parameters
pidThe process Id

Definition at line 37 of file logging.F90.

37  integer, intent(in) :: pid
38 
39  i_am_master=pid==master_process
Here is the caller graph for this function:

◆ log_get_logging_level()

integer function, public logging_mod::log_get_logging_level ( )

Retrieves the current logging level.

Returns
The current logging level

Definition at line 122 of file logging.F90.

122  log_get_logging_level = current_log_level
Here is the caller graph for this function:

◆ log_is_master()

logical function, public logging_mod::log_is_master ( )

Determines whether the process is the master logging process. This might be preferable rather than calling masterLog due to having to construct the message for masterLog regardless.

Parameters
pidThe process id to test

Definition at line 66 of file logging.F90.

66  log_is_master = i_am_master
Here is the caller graph for this function:

◆ log_log()

subroutine, public logging_mod::log_log ( integer, intent(in)  level,
character(len=*), intent(in)  message,
character(len=*), intent(out), optional  str 
)

Logs a message at the specified level. If the level is above the current level then the message is ignored. If applicable then the message will be written to stdout or a provided string.

Parameters
levelThe logging level
messageThe message to log
strOptional string to write the message into (rather than stdout)

Definition at line 75 of file logging.F90.

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()
Here is the call graph for this function:

◆ log_master_log()

subroutine, public logging_mod::log_master_log ( integer, intent(in)  level,
character(len=*), intent(in)  message 
)

Will log just from the master process.

Parameters
levelThe logging level
messageThe logging message
myIdMy process id

Definition at line 47 of file logging.F90.

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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_master_newline()

subroutine, public logging_mod::log_master_newline ( )

The master process will log a new line to stdio.

Definition at line 59 of file logging.F90.

59  if (i_am_master) write(*,*) ""

◆ log_newline()

subroutine, public logging_mod::log_newline ( )

Will log a new line to the stdout.

Definition at line 91 of file logging.F90.

91  write(*,*) ""

◆ log_set_logging_level()

subroutine, public logging_mod::log_set_logging_level ( integer, intent(in)  level)

Sets the logging level, messages with less priority will be ignored.

Parameters
levelThe logging level to adopt

Definition at line 114 of file logging.F90.

114  integer, intent(in) :: level
115 
116  current_log_level = level
Here is the caller graph for this function:

Variable Documentation

◆ current_log_level

integer logging_mod::current_log_level =LOG_INFO
private

Private current logging state, the default is INFO level.

Definition at line 22 of file logging.F90.

22  integer :: current_log_level=log_info

◆ debug_preamble

character(len=*), parameter logging_mod::debug_preamble = "[DEBUG]"
private

Debug message preamble.

Definition at line 16 of file logging.F90.

◆ error_is_fatal

logical, parameter logging_mod::error_is_fatal =.true.
private

Whether an error log message is fatal and stops execution.

Definition at line 24 of file logging.F90.

24  logical, parameter :: error_is_fatal=.true.

◆ error_preamble

character(len=*), parameter logging_mod::error_preamble = "[ERROR]"
private

Error message preamble.

Definition at line 16 of file logging.F90.

16  character(len=*), parameter :: error_preamble = "[ERROR]",& !< Error message preamble
17  warn_preamble = "[WARN]",&
18  info_preamble = "[INFO]",&
19  debug_preamble = "[DEBUG]"

◆ i_am_master

logical, save logging_mod::i_am_master =.true.
private

Whether or not I am the master process.

Definition at line 26 of file logging.F90.

26  logical, save :: i_am_master=.true.

◆ info_preamble

character(len=*), parameter logging_mod::info_preamble = "[INFO]"
private

Info message preamble.

Definition at line 16 of file logging.F90.

◆ log_debug

integer, parameter, public logging_mod::log_debug = 4

Log DEBUG, INFO, WARNING and ERROR messages.

Definition at line 14 of file logging.F90.

14  integer, parameter, public :: log_debug = 4

◆ log_error

integer, parameter, public logging_mod::log_error = 1

Only log ERROR messages.

Definition at line 11 of file logging.F90.

11  integer, parameter, public :: log_error = 1

◆ log_info

integer, parameter, public logging_mod::log_info = 3

Log INFO, WARNING and ERROR messages.

Definition at line 13 of file logging.F90.

13  integer, parameter, public :: log_info = 3

◆ log_warn

integer, parameter, public logging_mod::log_warn = 2

Log WARNING and ERROR messages.

Definition at line 12 of file logging.F90.

12  integer, parameter, public :: log_warn = 2

◆ master_process

integer, parameter, private logging_mod::master_process = 0
private

Definition at line 9 of file logging.F90.

9  integer, parameter, private :: master_process = 0

◆ warn_preamble

character(len=*), parameter logging_mod::warn_preamble = "[WARN]"
private

Warning message preable.

Definition at line 16 of file logging.F90.