logger Derived Type

type, public :: logger

An object to handle output of information about the executing program to the terminal and to a log-file.


Source Code


Constructor

public interface logger

  • private function constructor(logfile, stderr_threshold, stdout_threshold, logfile_threshold) result(this)

    Arguments

    Type IntentOptional AttributesName
    character(len=*), intent(in) :: logfile

    Name of the log-file to which output will be written

    integer, intent(in), optional :: stderr_threshold

    Threshold priority, at and above which messages will be written to standard error. Defaults to error.

    integer, intent(in), optional :: stdout_threshold

    Threshold priority, at and above which messages will be written to standard out. Defaults to info.

    integer, intent(in), optional :: logfile_threshold

    Threshold priority, at and above which messages will be written to the log file. Defaults to trivia.

    Return Value type(logger)


Finalization Procedures

final :: logger_finalize

  • private subroutine logger_finalize(this)

    Closes the log-file of this logger object.

    Arguments

    Type IntentOptional AttributesName
    type(logger), intent(inout) :: this

Type-Bound Procedures

procedure, public :: message => logger_message

Write a message of a given priority to the appropriate location(s)

  • private subroutine logger_message(this, source, priority, message)

    Write the provided message to STDERR, STDOUT, and/or a log-file, based on its priority level.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

    integer, intent(in) :: priority

    The importance of the message, determining where it will be written.

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

    The information to be written.

procedure, public :: debug => logger_debug

Write debug information

  • private subroutine logger_debug(this, source, message)

    Writes debug information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: trivia => logger_trivia

Write trivial run-time information

  • private subroutine logger_trivia(this, source, message)

    Writes unimportant run-time information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: info => logger_info

Write run-time information

  • private subroutine logger_info(this, source, message)

    Writes run-time information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: warning => logger_warning

Write warning message

  • private subroutine logger_warning(this, source, message)

    Writes warning information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: error => logger_error

Write error message

  • private subroutine logger_error(this, source, message)

    Writes error information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: fatal => logger_fatal

Write notification of fatal error

  • private subroutine logger_fatal(this, source, message)

    Writes fatal information to STDERR, STDOUT, and/or a log-file.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this
    character(len=*), intent(in) :: source

    The name of the procedure which produced the error

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

    The information to be written.

procedure, public :: destroy => logger_destroy

Closes the log-file

  • private subroutine logger_destroy(this)

    Closes the log-file of this logger object. Destroys only the logger object, not the output.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(inout) :: this

procedure, public :: is_open => logger_is_open

Return .true. if the log-file is open for writing

  • private pure function logger_is_open(this)

    Returns .true. if the log-file is open for writing.

    Arguments

    Type IntentOptional AttributesName
    class(logger), intent(in) :: this

    Return Value logical

Source Code

  type, public :: logger
    !* Author: Chris MacMackinc
    !  Date: December 2016
    !
    ! An object to handle output of information about the executing
    ! program to the terminal and to a log-file.
    ! 
    private
    integer                       :: stdout = output_unit
      !! Unit corresponding to STDOUT
    integer                       :: stderr = error_unit
      !! Unit corresponding to STDERR
    integer                       :: fileunit = closed_unit
      !! Unit corresponding to log-file
    character(len=:), allocatable :: logfile
      !! Name of the log-file
    integer                       :: stderr_threshold = infinity
      !! Cutoff for which messages with greater or equal priority will
      !! be written to STDERR.
    integer                       :: stdout_threshold = infinity
      !! Cutoff for which messages with greater or equal priority will
      !! be written to STDOUT.
    integer                       :: logfile_threshold = infinity
      !! Cutoff for which messages with greater or equal priority will
      !! be written to the log-file.
  contains
    procedure :: message => logger_message
      !! Write a message of a given priority to the appropriate
      !! location(s)
    procedure :: debug => logger_debug
      !! Write debug information
    procedure :: trivia => logger_trivia
      !! Write trivial run-time information
    procedure :: info => logger_info
      !! Write run-time information
    procedure :: warning => logger_warning
      !! Write warning message
    procedure :: error => logger_error
      !! Write error message
    procedure :: fatal => logger_fatal
      !! Write notification of fatal error
    procedure :: destroy => logger_destroy
      !! Closes the log-file
    procedure :: is_open => logger_is_open
      !! Return `.true.` if the log-file is open for writing
    final :: logger_finalize
  end type logger