logger_type Derived Type

type, public :: logger_type

custom logger data type


Components

Type Visibility Attributes Name Initial
integer(kind=default_int), public :: log_file_level = verbose_level

set default log file log level to verbose

integer(kind=default_int), public :: log_level = info_level

set default log level to info

logical, private :: log_file_open = .false.
integer(kind=default_int), private :: log_file_unit = -1

Type-Bound Procedures

procedure, public, pass(self) :: close_log_file

Close the log file, needs to be called at the end of the program. Usage: call my_logger%close_log_file()

  • private subroutine close_log_file(self)

    Close the log file, needs to be called at the end of the program

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(inout) :: self

procedure, public, pass(self) :: configuration

Get the current logger verbosity configuration. Usage: call my_logger%configuration(level)

  • private pure subroutine configuration(self, level)

    Get the current logger verbosity configuration

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    integer(kind=default_int), intent(out), optional :: level

procedure, public, pass(self) :: configure

Configure the logger to be a certain verbosity level. Usage: call my_logger%configure(level)

  • private pure subroutine configure(self, level)

    Configure the logger to be a certain verbosity level

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(inout) :: self
    integer(kind=default_int), intent(in), optional :: level

procedure, public, pass(self) :: configure_file_output

Configure the logger to file to be a certain verbosity level. Usage: call my_logger%configure_file_output(filename, level)

  • private subroutine configure_file_output(self, filename, level)

    Configure the logger to file to be a certain verbosity level

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(inout) :: self
    character(len=*), intent(in) :: filename
    integer(kind=default_int), intent(in), optional :: level

procedure, public, pass(self) :: debug

Log a message that will only be printed at the debug level of verbosity. Usage: call my_logger%debug(“MESSAGE”)

  • private subroutine debug(self, message, module, procedure)

    Log a message that will only be printed at the debug level of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, public, pass(self) :: error

Log a message that will only be printed at the error level of verbosity. Usage: call my_logger%error(“MESSAGE”)

  • private subroutine error(self, message, module, procedure)

    Log a message that will only be printed at the error of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, public, pass(self) :: info

Log a message that will only be printed at the info level of verbosity. Usage: call my_logger%info(“MESSAGE”)

  • private subroutine info(self, message, module, procedure)

    Log a message that will only be printed at the info level of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, public, pass(self) :: performance

Log a message that will only be printed at the performance level of verbosity. Usage: call my_logger%performance(“MESSAGE”)

  • private subroutine performance(self, message, module, procedure)

    Log a message that will only be printed at the performance of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, public, pass(self) :: verbose

Log a message that will only be printed at the verbose level of verbosity. Usage: call my_logger%verbose(“MESSAGE”)

  • private subroutine verbose(self, message, module, procedure)

    Log a message that will only be printed at the verbose level of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, public, pass(self) :: warning

Log a message that will only be printed at the warning level of verbosity. Usage: call my_logger%warning(“MESSAGE”)

  • private subroutine warning(self, message, module, procedure)

    Log a message that will only be printed at the warning level of verbosity

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

procedure, private, pass(self) :: log

Processes the message and filters it according to the verbosity level set by the user or the default

  • private subroutine log(self, level, message, module, procedure)

    internal subroutines that processes the message and filters it according to the verbosity level set by the user or the default this is a private subroutine so it is not exposed to the user

    Arguments

    Type IntentOptional Attributes Name
    class(logger_type), intent(in) :: self
    character(len=*), intent(in) :: level
    character(len=*), intent(in) :: message
    character(len=*), intent(in), optional :: module
    character(len=*), intent(in), optional :: procedure

Source Code

   type :: logger_type
    !! custom logger data type

      private

      integer(default_int), public :: log_level = info_level
        !! set default log level to info
      integer(default_int), public :: log_file_level = verbose_level
        !! set default log file log level to verbose
      integer(default_int), private :: log_file_unit = -1
      logical, private :: log_file_open = .false.

   contains

      procedure, public, pass(self) :: configuration
      !! Get the current logger verbosity configuration.
      !! Usage: call my_logger%configuration(level)
      procedure, public, pass(self) :: configure
      !! Configure the logger to be a certain verbosity level.
      !! Usage: call my_logger%configure(level)
      procedure, public, pass(self) :: configure_file_output
      !! Configure the logger to file to be a certain verbosity level.
      !! Usage: call my_logger%configure_file_output(filename, level)
      procedure, public, pass(self) :: close_log_file
      !! Close the log file, needs to be called at the end of the program.
      !! Usage: call my_logger%close_log_file()
      procedure, public, pass(self) :: debug
      !! Log a message that will only be printed at the debug level of verbosity.
      !! Usage: call my_logger%debug("MESSAGE")
      procedure, public, pass(self) :: verbose
      !! Log a message that will only be printed at the verbose level of verbosity.
      !! Usage: call my_logger%verbose("MESSAGE")
      procedure, public, pass(self) :: info
      !! Log a message that will only be printed at the info level of verbosity.
      !! Usage: call my_logger%info("MESSAGE")
      procedure, public, pass(self) :: performance
      !! Log a message that will only be printed at the performance level of verbosity.
      !! Usage: call my_logger%performance("MESSAGE")
      procedure, public, pass(self) :: warning
      !! Log a message that will only be printed at the warning level of verbosity.
      !! Usage: call my_logger%warning("MESSAGE")
      procedure, public, pass(self) :: error
      !! Log a message that will only be printed at the error level of verbosity.
      !! Usage: call my_logger%error("MESSAGE")
      procedure, private, pass(self) :: log
      !! Processes the message and filters it according to the verbosity level set by the user or the default

   end type logger_type