tem_logging_module Module

Providing a logging infrastructure to easily control the verbosity of output.

The internal log_level can be set at runtime and output will only happen, if the log_level is higher than that of the messages to write.

The numbering of levels is limited to 20, the higher the number the less important the message is:

  • 1 A message that should always appear (except the logger is explicitly turned off)
  • 3 Informational warnings of less importance
  • 6 Detailed information
  • 10 Very detailed debugging information

Messages should be defined with positive integers between 1 and 10 and the list above provides some idea on which levels to use. Log levels beyond 10 should only be used for temporary outputs during development.

There is a primary logging data structure provided by the module, which will provide output by the root rank usually to the standard output.

To write a message to the log, use its funit. The funit is an array of file units, that are either connected to the configured output file or to the null device, depending on the configured log level. All units beyond the log level are connected to the null device, while those up that level are connected to the file. For the primary logger a shorthand is provided by the module variable logUnit. Thus, to write some message on log level 4 to the primary logger you do something like this:

write(logUnit(4),*) 'some real: ', x

This message will only appear, if the log level in the configuration is set to 4 or higher.

Unfortunately debug outputs are costly, even if written to the null device they might heavily affect performance. Thus you should not put log messages into hot code parts, that is mostly into long or deeply nested loops. If there is the need for debug output in such parts, there is the possibility to enclose the calls in CoCo preprocessing commands:

 ?? IF (loglvl >= 3) THEN
   write(logunit(3),*) 'We only write this if compilation includes this.'
 ?? ENDIF

As loglvl needs to be always defined you currently need to include the logMacros.inc file everywhere you want to use that. However, it might be possible to shift the default definition of loglvl=0 to the setfile (needs to be checked). To set a certain loglvl at compile time it is then necessary to set the COCOFLAGS environment variable:

 export COCOFLAGS='-Dloglvl=3'

In addition there are some helping routines defined, that help to convert data to strings. To convert a number or logical to a string use tem_toStr. For example you can write a message to the primary log with the real "ar" like this:

 call tem_log(level=1, msg='some real: '//trim(tem_toStr(ar))//' !')

Uses

  • module~~tem_logging_module~~UsesGraph module~tem_logging_module tem_logging_module module~env_module env_module module~tem_logging_module->module~env_module module~aotus_module aotus_module module~tem_logging_module->module~aotus_module module~aot_table_module aot_table_module module~tem_logging_module->module~aot_table_module module~env_module->module~aotus_module module~flu_binding flu_binding module~env_module->module~flu_binding iso_fortran_env iso_fortran_env module~env_module->iso_fortran_env mpi mpi module~env_module->mpi

Used by


Contents


Variables

TypeVisibilityAttributesNameInitial
integer, public, parameter:: tem_last_lu =21

The last logging unit, defining the length of log unit arrays.

integer, public :: logUnit(0:tem_last_lu)
integer, public, parameter:: llerror =1

A message that should always appear (except the logger is explicitly turned off)

integer, public, parameter:: llwarning =3

Informational warnings of less importance

integer, public, parameter:: llinfo =6

Detailed information

integer, public, parameter:: lldebug =10

Very detailed debugging information

integer, private, parameter:: form_len =10
type(tem_logging_type), private :: primary

Interfaces

public interface tem_logging_isActive

  • private function tem_logging_isActive_for(me, level) result(isActive)

    Check if the given logger is active for the given level.

    Arguments

    TypeIntentOptionalAttributesName
    type(tem_logging_type), intent(in) :: me
    integer, intent(in) :: level

    Return Value logical

  • private function tem_logging_isActive_primary(level) result(isActive)

    Check if the primary logger is active for the given level.

    Arguments

    TypeIntentOptionalAttributesName
    integer, intent(in) :: level

    Return Value logical

public interface tem_logging_unit

  • private function tem_logging_unit_for(me) result(unit)

    Return the unit provided by a given log

    Arguments

    TypeIntentOptionalAttributesName
    type(tem_logging_type), intent(in) :: me

    Return Value integer

  • private function tem_logging_unit_primary() result(unit)

    Return the unit provided by the primary log

    Arguments

    None

    Return Value integer

public interface tem_log_write

  • private subroutine tem_log_write_for(me, msg)

    Write msg unconditionally to the logger given in me.

    Arguments

    TypeIntentOptionalAttributesName
    type(tem_logging_type), intent(in) :: me
    character(len=*), intent(in) :: msg
  • private subroutine tem_log_write_primary(msg)

    Write msg unconditionally to the primary logger.

    Arguments

    TypeIntentOptionalAttributesName
    character(len=*), intent(in) :: msg

public interface tem_log

  • private subroutine tem_log_for(me, level, msg)

    Log a message in the given logger.

    Arguments

    TypeIntentOptionalAttributesName
    type(tem_logging_type), intent(in) :: me
    integer, intent(in) :: level
    character(len=*), intent(in) :: msg
  • private subroutine tem_log_primary(level, msg)

    Log a message in the primary logger.

    Arguments

    TypeIntentOptionalAttributesName
    integer, intent(in) :: level
    character(len=*), intent(in) :: msg

public interface tem_logging_init

  • private subroutine tem_logging_init_logger(me, level, rank, filename, root_only, real_form, int_form)

    Initialize a logging data type.

    Read more…

    Arguments

    TypeIntentOptionalAttributesName
    type(tem_logging_type), intent(out) :: me

    Logger to initialize

    integer, intent(in) :: level

    Level of output to log with this logger

    integer, intent(in) :: rank

    Rank of the process executing the initialization.

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

    File to write output to, default is null device.

    If this is empty or not provided, the output will be to the null device. To send messages to the stdout set this parameter to '/stdout:'.

    logical, intent(in), optional :: root_only

    Indicate if root only should write messages Default is true.

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

    Format to write real numbers. Default is 'EN12.3'

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

    Format to write integer numbers. Default is 'I0'

  • public subroutine tem_logging_init_primary(level, rank, filename, root_only, real_form, int_form)

    Initialize the primary logger (default to stdout instead of null device).

    Arguments

    TypeIntentOptionalAttributesName
    integer, intent(in) :: level

    Level of output to log with this logger

    integer, intent(in) :: rank

    Rank of the process executing the initialization.

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

    File to write output to, default is standard out.

    To send messages to the stdout set this parameter to '/stdout:'.

    logical, intent(in), optional :: root_only

    Indication whether only root should print log messages.

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

    Format to write real numbers. Default is 'EN12.3'

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

    Format to write integer numbers. Default is 'I0'

public interface tem_toStr

  • private function tem_r2str(val, logger) result(str)

    Convert a real to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=single_k), intent(in) :: val
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_d2str(val, logger) result(str)

    Converts a double to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=double_k), intent(in) :: val
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_i2str(val, logger) result(str)

    Converts an integer to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    integer(kind=int_k), intent(in) :: val
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_l2str(val, logger) result(str)

    Converts a long to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    integer(kind=long_k), intent(in) :: val
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_b2str(val) result(str)

    Converts a bool to a string.

    Arguments

    TypeIntentOptionalAttributesName
    logical, intent(in) :: val

    Return Value character(len=SolSpecLen)

  • private function tem_r2str_arr(val, sep, logger) result(str)

    Converts a real "array" to a single string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=single_k), intent(in) :: val(:)

    array to convert

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

    seperator between array elements

    type(tem_logging_type), intent(in), optional :: logger

    logger type which provides output format

    Return Value character(len=SolSpecLen)

    output string

  • private function tem_d2str_arr(val, sep, logger) result(str)

    Converts an array of doubles to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    real(kind=double_k), intent(in) :: val(:)
    character(len=*), intent(in) :: sep
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_i2str_arr(val, sep, logger) result(str)

    Converts an array of integers to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    integer(kind=int_k), intent(in) :: val(:)

    array to convert

    character(len=*), intent(in) :: sep
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_l2str_arr(val, sep, logger) result(str)

    Converts an array of longs to a string according to the format provided in the logger.

    Arguments

    TypeIntentOptionalAttributesName
    integer(kind=long_k), intent(in) :: val(:)
    character(len=*), intent(in) :: sep
    type(tem_logging_type), intent(in), optional :: logger

    Return Value character(len=SolSpecLen)

  • private function tem_b2str_arr(val, sep) result(str)

    Converts an array of booleans to a string.

    Arguments

    TypeIntentOptionalAttributesName
    logical, intent(in) :: val(:)
    character(len=*), intent(in) :: sep

    Return Value character(len=SolSpecLen)


Derived Types

type, public :: tem_logging_type

Components

TypeVisibilityAttributesNameInitial
integer, private :: log_level
integer, private :: funit(0:tem_last_lu)
logical, private :: participating
character(len=form_len), private :: real_form
character(len=form_len), private :: int_form

Functions

private function tem_logging_isActive_for(me, level) result(isActive)

Check if the given logger is active for the given level.

Arguments

TypeIntentOptionalAttributesName
type(tem_logging_type), intent(in) :: me
integer, intent(in) :: level

Return Value logical

private function tem_logging_isActive_primary(level) result(isActive)

Check if the primary logger is active for the given level.

Arguments

TypeIntentOptionalAttributesName
integer, intent(in) :: level

Return Value logical

private function tem_logging_unit_for(me) result(unit)

Return the unit provided by a given log

Arguments

TypeIntentOptionalAttributesName
type(tem_logging_type), intent(in) :: me

Return Value integer

private function tem_logging_unit_primary() result(unit)

Return the unit provided by the primary log

Arguments

None

Return Value integer

private function tem_r2str(val, logger) result(str)

Convert a real to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
real(kind=single_k), intent(in) :: val
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_r2str_arr(val, sep, logger) result(str)

Converts a real "array" to a single string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
real(kind=single_k), intent(in) :: val(:)

array to convert

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

seperator between array elements

type(tem_logging_type), intent(in), optional :: logger

logger type which provides output format

Return Value character(len=SolSpecLen)

output string

private function tem_d2str(val, logger) result(str)

Converts a double to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
real(kind=double_k), intent(in) :: val
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_d2str_arr(val, sep, logger) result(str)

Converts an array of doubles to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
real(kind=double_k), intent(in) :: val(:)
character(len=*), intent(in) :: sep
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_i2str(val, logger) result(str)

Converts an integer to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
integer(kind=int_k), intent(in) :: val
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_i2str_arr(val, sep, logger) result(str)

Converts an array of integers to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
integer(kind=int_k), intent(in) :: val(:)

array to convert

character(len=*), intent(in) :: sep
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_l2str(val, logger) result(str)

Converts a long to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
integer(kind=long_k), intent(in) :: val
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_l2str_arr(val, sep, logger) result(str)

Converts an array of longs to a string according to the format provided in the logger.

Arguments

TypeIntentOptionalAttributesName
integer(kind=long_k), intent(in) :: val(:)
character(len=*), intent(in) :: sep
type(tem_logging_type), intent(in), optional :: logger

Return Value character(len=SolSpecLen)

private function tem_b2str(val) result(str)

Converts a bool to a string.

Arguments

TypeIntentOptionalAttributesName
logical, intent(in) :: val

Return Value character(len=SolSpecLen)

private function tem_b2str_arr(val, sep) result(str)

Converts an array of booleans to a string.

Arguments

TypeIntentOptionalAttributesName
logical, intent(in) :: val(:)
character(len=*), intent(in) :: sep

Return Value character(len=SolSpecLen)


Subroutines

public subroutine tem_logging_init_primary(level, rank, filename, root_only, real_form, int_form)

Initialize the primary logger (default to stdout instead of null device).

Arguments

TypeIntentOptionalAttributesName
integer, intent(in) :: level

Level of output to log with this logger

integer, intent(in) :: rank

Rank of the process executing the initialization.

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

File to write output to, default is standard out.

To send messages to the stdout set this parameter to '/stdout:'.

logical, intent(in), optional :: root_only

Indication whether only root should print log messages.

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

Format to write real numbers. Default is 'EN12.3'

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

Format to write integer numbers. Default is 'I0'

public subroutine tem_logging_load(conf, thandle, rank, me)

Load logging configuration from a Lua table and return the initialized logger.

Read more…

Arguments

TypeIntentOptionalAttributesName
type(flu_State) :: conf
integer, intent(in) :: thandle
integer, intent(in) :: rank
type(tem_logging_type), intent(out), optional :: me

public subroutine tem_logging_load_primary(conf, rank)

Load the primary logger from a Lua script under its default name of logging as global variable.

Read more…

Arguments

TypeIntentOptionalAttributesName
type(flu_state) :: conf
integer :: rank

private subroutine tem_logging_init_logger(me, level, rank, filename, root_only, real_form, int_form)

Initialize a logging data type.

Read more…

Arguments

TypeIntentOptionalAttributesName
type(tem_logging_type), intent(out) :: me

Logger to initialize

integer, intent(in) :: level

Level of output to log with this logger

integer, intent(in) :: rank

Rank of the process executing the initialization.

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

File to write output to, default is null device.

If this is empty or not provided, the output will be to the null device. To send messages to the stdout set this parameter to '/stdout:'.

logical, intent(in), optional :: root_only

Indicate if root only should write messages Default is true.

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

Format to write real numbers. Default is 'EN12.3'

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

Format to write integer numbers. Default is 'I0'

private subroutine tem_log_write_for(me, msg)

Write msg unconditionally to the logger given in me.

Arguments

TypeIntentOptionalAttributesName
type(tem_logging_type), intent(in) :: me
character(len=*), intent(in) :: msg

private subroutine tem_log_write_primary(msg)

Write msg unconditionally to the primary logger.

Arguments

TypeIntentOptionalAttributesName
character(len=*), intent(in) :: msg

private subroutine tem_log_for(me, level, msg)

Log a message in the given logger.

Arguments

TypeIntentOptionalAttributesName
type(tem_logging_type), intent(in) :: me
integer, intent(in) :: level
character(len=*), intent(in) :: msg

private subroutine tem_log_primary(level, msg)

Log a message in the primary logger.

Arguments

TypeIntentOptionalAttributesName
integer, intent(in) :: level
character(len=*), intent(in) :: msg