Logging module for managing verbosity levels and output destinations. This module provides a simple logging system with support for different log levels (ERROR, WARNING, INFO, DEBUG), configurable verbosity, and output units.
Features: - Enable or disable global verbosity - Control the log level threshold (e.g., show only ERROR, or include DEBUG) - Redirect logs to custom output units or reset to defaults (stdout/stderr) - Helper function to determine whether to log and which unit to use - Convenience subroutine to write logs directly
Note
This module is designed for modular use and can be applied to any program. Set the current log level threshold.
Only messages with level <= LOGGER_LEVEL will be printed.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public, | parameter | :: | LOG_ERROR | = | 0 |
Error messages |
integer, | public, | parameter | :: | LOG_WARNING | = | 1 |
Warning messages |
integer, | public, | parameter | :: | LOG_INFO | = | 2 |
Informational messages |
integer, | public, | parameter | :: | LOG_DEBUG | = | 3 |
Debug messages |
logical, | public | :: | LOGGER_OK | = | .true. |
Indicates if the last call to log_unit allowed logging |
Write a log message for the given level using the current logger settings.
This is a convenience routine that calls log_unit() internally and writes
the message if LOGGER_OK is .true.
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
Write a log message for a given level without advancing the line
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
||
logical, | intent(in) | :: | newline |
If |
Write a log message for a given level, appending an integer at the end
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
||
integer(kind=i4), | intent(in) | :: | value |
Integer value to append |
Write a log message for a given level without advancing the line, appending an integer at the end
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
||
integer(kind=i4), | intent(in) | :: | value |
Integer value to append |
||
logical, | intent(in) | :: | newline |
If |
Write a log message for a given level, appending a double at the end
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
||
real(kind=dp), | intent(in) | :: | value |
Double precision value to append |
Write a log message for a given level without advancing the line, appending a double at the end
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
||
character(len=*), | intent(in) | :: | message |
The text message to log |
||
real(kind=dp), | intent(in) | :: | value |
Double precision value to append |
||
logical, | intent(in) | :: | newline |
If |
Determine the output unit for a given log level and update LOGGER_OK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level of the message |
The Fortran output unit (or -1 if logging is disabled)
Enable or disable global verbosity.
If set to .false.
, no log messages will be printed regardless of level.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | flag |
Logical flag to enable ( |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | level |
Log level (use LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG) |
Set the output unit for normal log messages.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | unit |
Fortran unit number for INFO/WARNING/DEBUG logs. |
Set the output unit for error log messages.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i4), | intent(in) | :: | unit |
Fortran unit number for ERROR logs. |
Reset output units to default (stdout for normal logs, stderr for errors).