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:
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))//' !')
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
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 |
Check if the given logger is active for the given level.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
integer, | intent(in) | :: | level |
Check if the primary logger is active for the given level.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | level |
Return the unit provided by a given log
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me |
Return the unit provided by the primary log
Write msg unconditionally to the logger given in me.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
character(len=*), | intent(in) | :: | msg |
Write msg unconditionally to the primary logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | msg |
Log a message in the given logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
integer, | intent(in) | :: | level | |||
character(len=*), | intent(in) | :: | msg |
Log a message in the primary logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | level | |||
character(len=*), | intent(in) | :: | msg |
Initialize a logging data type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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' |
Initialize the primary logger (default to stdout instead of null device).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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' |
Convert a real to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=single_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a double to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=double_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an integer to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a long to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=long_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a bool to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val |
Converts a real "array" to a single string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
output string
Converts an array of doubles to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=double_k), | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of integers to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int_k), | intent(in) | :: | val(:) | array to convert |
||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of longs to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=long_k), | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of booleans to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
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 |
Check if the given logger is active for the given level.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
integer, | intent(in) | :: | level |
Check if the primary logger is active for the given level.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | level |
Return the unit provided by a given log
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me |
Return the unit provided by the primary log
Convert a real to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=single_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a real "array" to a single string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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 |
output string
Converts a double to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=double_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of doubles to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=double_k), | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an integer to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of integers to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=int_k), | intent(in) | :: | val(:) | array to convert |
||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a long to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=long_k), | intent(in) | :: | val | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts an array of longs to a string according to the format provided in the logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=long_k), | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep | |||
type(tem_logging_type), | intent(in), | optional | :: | logger |
Converts a bool to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val |
Converts an array of booleans to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | val(:) | |||
character(len=*), | intent(in) | :: | sep |
Initialize the primary logger (default to stdout instead of null device).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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' |
Load logging configuration from a Lua table and return the initialized logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_State) | :: | conf | ||||
integer, | intent(in) | :: | thandle | |||
integer, | intent(in) | :: | rank | |||
type(tem_logging_type), | intent(out), | optional | :: | me |
Load the primary logger from a Lua script under its default name of logging as global variable.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(flu_state) | :: | conf | ||||
integer | :: | rank |
Initialize a logging data type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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' |
Write msg unconditionally to the logger given in me.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
character(len=*), | intent(in) | :: | msg |
Write msg unconditionally to the primary logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | msg |
Log a message in the given logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_logging_type), | intent(in) | :: | me | |||
integer, | intent(in) | :: | level | |||
character(len=*), | intent(in) | :: | msg |
Log a message in the primary logger.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | level | |||
character(len=*), | intent(in) | :: | msg |