datastructs_logger_mod Module

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.


Uses

  • module~~datastructs_logger_mod~~UsesGraph module~datastructs_logger_mod datastructs_logger_mod iso_fortran_env iso_fortran_env module~datastructs_logger_mod->iso_fortran_env module~datastructs_kinds_mod datastructs_kinds_mod module~datastructs_logger_mod->module~datastructs_kinds_mod module~datastructs_kinds_mod->iso_fortran_env

Used by

  • module~~datastructs_logger_mod~~UsedByGraph module~datastructs_logger_mod datastructs_logger_mod module~datastructs_mod datastructs_mod module~datastructs_mod->module~datastructs_logger_mod

Variables

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


Interfaces

public interface log_write

  • private subroutine log_write_message(level, message)

    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..

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=i4), intent(in) :: level

    Log level of the message

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

    The text message to log

  • private subroutine log_write_message_no_advance(level, message, newline)

    Write a log message for a given level without advancing the line

    Arguments

    Type IntentOptional 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 .false., do not append a newline

  • private subroutine log_write_message_i4(level, message, value)

    Write a log message for a given level, appending an integer at the end

    Arguments

    Type IntentOptional 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

  • private subroutine log_write_message_i4_no_advance(level, message, value, newline)

    Write a log message for a given level without advancing the line, appending an integer at the end

    Arguments

    Type IntentOptional 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 .false., do not append a newline

  • private subroutine log_write_message_dp(level, message, value)

    Write a log message for a given level, appending a double at the end

    Arguments

    Type IntentOptional 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

  • private subroutine log_write_message_dp_no_advance(level, message, value, newline)

    Write a log message for a given level without advancing the line, appending a double at the end

    Arguments

    Type IntentOptional 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 .false., do not append a newline


Functions

public function log_unit(level) result(unit)

Determine the output unit for a given log level and update LOGGER_OK.

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=i4), intent(in) :: level

Log level of the message

Return Value integer(kind=i4)

The Fortran output unit (or -1 if logging is disabled)


Subroutines

public subroutine set_verbose(flag)

Enable or disable global verbosity. If set to .false., no log messages will be printed regardless of level.

Arguments

Type IntentOptional Attributes Name
logical, intent(in) :: flag

Logical flag to enable (.true.) or disable (.false.) verbosity.

public subroutine set_level(level)

Arguments

Type IntentOptional Attributes Name
integer(kind=i4), intent(in) :: level

Log level (use LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG)

public subroutine set_output_unit(unit)

Set the output unit for normal log messages.

Arguments

Type IntentOptional Attributes Name
integer(kind=i4), intent(in) :: unit

Fortran unit number for INFO/WARNING/DEBUG logs.

public subroutine set_error_unit(unit)

Set the output unit for error log messages.

Arguments

Type IntentOptional Attributes Name
integer(kind=i4), intent(in) :: unit

Fortran unit number for ERROR logs.

public subroutine set_unit_defaults()

Reset output units to default (stdout for normal logs, stderr for errors).

Arguments

None