stdlib_logger Module

Module stdlib_logger

This module defines a derived type, procedures, a variable, and constants to be used for logging information and reporting errors in Fortran applications. (Specification)

The derived type, logger_type, is to be used to define variables to serve as both local and global loggers. A logger directs its messages to selected I/O units so the user has a record (a log) of major events. For each entity of logger_type the reports go to a list of I/O units represented by the private internal array, log_units. If log_units is empty then output by default goes to output_unit. Otherwise reports go to output_unit only if it has been explicitly added to log_units. Each entity of type logger_type also maintains an internal state controlling the formatting of output.

The procedures are as follows. The logical function log_units_assigned returns the number of I/O units in log_units. The subroutines add_log_file and add_log_unit include the specified file in log_units. remove_log_units removes the specified logical unit from the log_units array and optionally closes the file. configure configures the details of the logging process. configuration reports the details of that configuration. The subroutines log_error, log_information, log_io_error, log_message, log_text_error, and log_warning send messages to the log units.

The variable global_logger of type logger_type can be used as a default global logger anywhere in the source code.

The constants are used to report errors by some of the subroutines in their optional stat arguments. The constants are as follows. success indicates that no error has occurred. close_failure indicates that a close statement for an I/O unit failed. index_invalid_error indicates that column was invalid for the given line. open_failure indicates that an open statement failed. read_only_error indicates that an output unit did not have a "write" or "readwrite" action. non_sequential_error indicates that the unit did not have sequential access. unformatted_in_error indicates that the unit did not have a form of "formatted". unopened_in_error indicates that the unit was not opened. write_failure indicates that at least one of the writes to log_units failed.

public constants used as error flags Variable of type logger_type to be used as a global logger



Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: all_level = -10+min(debug_level, information_level, warning_level, error_level, io_error_level, text_error_level)
integer, public, parameter :: close_failure = 1
integer, public, parameter :: debug_level = 10
integer, public, parameter :: error_level = 40
type(logger_type), public :: global_logger
integer, public, parameter :: index_invalid_error = 2
integer, public, parameter :: information_level = 20
integer, public, parameter :: io_error_level = 40
integer, public, parameter :: non_sequential_error = 3
integer, public, parameter :: none_level = 10+max(debug_level, information_level, warning_level, error_level, io_error_level, text_error_level)
integer, public, parameter :: open_failure = 4
integer, public, parameter :: read_only_error = 5
integer, public, parameter :: success = 0
integer, public, parameter :: text_error_level = 50
integer, public, parameter :: unformatted_in_error = 6
integer, public, parameter :: unopened_in_error = 7
integer, public, parameter :: warning_level = 30
integer, public, parameter :: write_failure = 8

Derived Types

type, public ::  logger_type

Public derived type (Specification)

Finalizations Procedures

final :: final_logger

Type-Bound Procedures

procedure, public, pass(self) :: add_log_file
procedure, public, pass(self) :: add_log_unit
procedure, public, pass(self) :: configuration
procedure, public, pass(self) :: configure
procedure, public, pass(self) :: log_debug
procedure, public, pass(self) :: log_error
procedure, public, pass(self) :: log_information
procedure, public, pass(self) :: log_io_error
procedure, public, pass(self) :: log_message
procedure, public, pass(self) :: log_text_error
procedure, public, pass(self) :: log_units_assigned
procedure, public, pass(self) :: log_warning
procedure, public, pass(self) :: remove_log_unit