0.6.2-dev0
FORCES
FORtran lib for Comp. Env. Sys.
Loading...
Searching...
No Matches
mo_logging Module Reference

Module providing a logging framework. More...

Functions/Subroutines

subroutine tput (lu, code)
 write format string to given unit
 
subroutine, public stput (str, code)
 generate format string
 
subroutine, public log_set_output_hostname (bool)
 Set the default for hostname output.
 
subroutine, public log_set_output_severity (bool)
 Set the default for severity output.
 
subroutine, public log_set_output_date (bool)
 Set the default for date output.
 
subroutine, public log_set_output_time (bool)
 Set time-only date format.
 
subroutine, public log_set_output_fileline (bool)
 Set the default for file/line output.
 
subroutine, public log_set_skip_terminal_check (bool)
 Whether or not to skip the terminal check.
 
subroutine, public log_set_disable_colors (bool)
 Disable colors altogether.
 
subroutine, public log_set_disable_format (bool)
 Disable formatting altogether.
 
integer function, public logu (level)
 Output unit to log.
 
logical function, public logp (level, only_n)
 Output this log statement or not.
 
character(len=300) function, public logl (level, filename, linenum)
 Write a log lead containing level and optional info.
 
subroutine strip_path (filepath, basename)
 Get base name of a file path.
 
character(len=50) function log_hostname ()
 Return the hostname in a 50 character string.
 
character(len=n) function spaces (n)
 Return n spaces.
 
character(len=50) function log_severity (level, show_colors)
 Return the severity level with colors etc in a 50 char string.
 
character(50) function log_datetime ()
 Return the current date, formatted nicely.
 
subroutine, public log_set_config (verbose, quiet, log_output_hostname, log_force_colors, log_no_colors, log_output_date, log_output_time, log_no_format)
 Set logging configuration.
 

Variables

integer, parameter, public num_log_levels = 7
 1 through 7 (fatal through trace)
 
integer, parameter, public log_fatal = LOG_LEVEL_FATAL_DEF
 = 1, Runtime error causing termination
 
integer, parameter, public log_error = LOG_LEVEL_ERROR_DEF
 = 2, Runtime error
 
integer, parameter, public log_warn = LOG_LEVEL_WARN_DEF
 = 3, Warning, but we can continue
 
integer, parameter, public log_info = LOG_LEVEL_INFO_DEF
 = 4, Interesting events
 
integer, parameter, public log_debug = LOG_LEVEL_DEBUG_DEF
 = 5, Detailed debug output, disable by compiling your program with -DDISABLE_LOG_DEBUG
 
integer, parameter, public log_trace = LOG_LEVEL_TRACE_DEF
 = 6, Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable
 
integer, parameter, public log_subtrace = LOG_LEVEL_SUBTRACE_DEF
 = 7, More Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable
 
integer, save, public log_unit = stdout
 By default, log to stdout for level > 2.
 
integer, save, public log_unit_error = stderr
 By default, log to stderr for level <= 2.
 
integer, save, public minimum_log_level = LOG_INFO
 Note that more critical means a lower number.
 
logical, save, public show_file_and_line = .true.
 show file name and line number in log output
 
character(len= *), parameter start = achar(27)
 Control start character.
 
character(len= *), parameter reset = "0"
 Control reset character.
 
character(len= *), parameter bold = "1"
 Styles.
 
character(len= *), parameter dimmed = "2"
 
character(len= *), parameter underline = "4"
 
character(len= *), parameter blink = "5"
 
character(len= *), parameter invert = "7"
 
character(len= *), parameter hidden = "8"
 
logical, save output_hostname = .false.
 
logical, save output_severity = .true.
 
logical, save output_date = .false.
 
logical, save output_time = .false.
 
logical, save output_fileline = .true.
 
logical, save skip_terminal_check = .false.
 
logical, save disable_colors = .false.
 
logical, save disable_format = .false.
 
character(len= *), dimension(num_log_levels), parameter color_codes = ["31", "31", "33", "32", "35", "36", "36"]
 These are the color codes corresponding to the loglevels above.
 
character(len= *), dimension(num_log_levels), parameter style_codes = [bold, reset, reset, reset, reset, reset, reset]
 These are the styles corresponding to the loglevels above.
 
character(len= *), parameter level_color = "20"
 Colors for other output.
 

Detailed Description

Module providing a logging framework.

Version
0.1
Authors
Daan van Vugt, Sebastian Mueller, Robert Schweppe
Date
Sep 2022

A simple logging framework derived from flogging (https://github.com/DaanVanVugt/flogging). To use logging you need to include logging.h at the top of your fortran file.

Note
The file needs to processed by the pre-processor.

Afterwards you have a list of logging routines that could be used instead of write:

The following example demonstrates the functionality. The mo_cli module incorporates logger settings:

#include "logging.h"
program test_log
use mo_cli, only : cli_parser
implicit none
type(cli_parser) :: parser
parser = cli_parser( &
description="Program with cli and logger.", &
add_help_option=.true., &
add_logger_options=.true.)
call parser%parse()
log_fatal(*) "fatal"
log_error(*) "error"
log_warn(*) "warn"
log_info(*) "info"
log_debug(*) "debug"
log_trace(*) "trace"
log_subtrace(*) "subtrace"
end program test_log
Module to parse command line arguments.
Definition mo_cli.f90:60
Module providing a logging framework.
integer, parameter, public log_trace
= 6, Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable
integer, parameter, public log_error
= 2, Runtime error
integer, parameter, public log_subtrace
= 7, More Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable
integer, parameter, public log_debug
= 5, Detailed debug output, disable by compiling your program with -DDISABLE_LOG_DEBUG
integer, parameter, public log_fatal
= 1, Runtime error causing termination
integer, parameter, public log_warn
= 3, Warning, but we can continue
integer, parameter, public log_info
= 4, Interesting events
This is a parser for command line arguments.
Definition mo_cli.f90:100

You can call the program with:

$ ./prog --quiet
test.F90:12 FATAL fatal
test.F90:13 ERROR error
test.F90:14 WARN warn

You can see all cli logger options with:

$ ./prog -h

Function/Subroutine Documentation

◆ log_datetime()

character(50) function mo_logging::log_datetime
private

Return the current date, formatted nicely.

Returns
date.
Output the date here

Definition at line 448 of file mo_logging.F90.

References log_datetime().

Referenced by log_datetime(), and logl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_hostname()

character(len=50) function mo_logging::log_hostname
private

Return the hostname in a 50 character string.

Returns
hostname.

Definition at line 368 of file mo_logging.F90.

References log_hostname().

Referenced by log_hostname(), and logl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_set_config()

subroutine, public mo_logging::log_set_config ( integer(i4), intent(in), optional  verbose,
integer(i4), intent(in), optional  quiet,
logical, intent(in), optional  log_output_hostname,
logical, intent(in), optional  log_force_colors,
logical, intent(in), optional  log_no_colors,
logical, intent(in), optional  log_output_date,
logical, intent(in), optional  log_output_time,
logical, intent(in), optional  log_no_format 
)

Set logging configuration.

Parameters
[in]verboseincrease verbosity level
[in]quietdecrease verbosity level
[in]log_output_hostnameshow hostname
[in]log_force_colorsforce colors in output
[in]log_no_colorsdisable colors
[in]log_output_dateadd date to output
[in]log_output_timeadd time to output
[in]log_no_formatdisable formatting

Definition at line 470 of file mo_logging.F90.

References mo_kind::i4, minimum_log_level, and num_log_levels.

Referenced by mo_cli::parse().

Here is the caller graph for this function:

◆ log_set_disable_colors()

subroutine, public mo_logging::log_set_disable_colors ( logical, intent(in)  bool)

Disable colors altogether.

Definition at line 206 of file mo_logging.F90.

◆ log_set_disable_format()

subroutine, public mo_logging::log_set_disable_format ( logical, intent(in)  bool)

Disable formatting altogether.

Definition at line 212 of file mo_logging.F90.

◆ log_set_output_date()

subroutine, public mo_logging::log_set_output_date ( logical, intent(in)  bool)

Set the default for date output.

Definition at line 182 of file mo_logging.F90.

◆ log_set_output_fileline()

subroutine, public mo_logging::log_set_output_fileline ( logical, intent(in)  bool)

Set the default for file/line output.

Definition at line 194 of file mo_logging.F90.

◆ log_set_output_hostname()

subroutine, public mo_logging::log_set_output_hostname ( logical, intent(in)  bool)

Set the default for hostname output.

Definition at line 170 of file mo_logging.F90.

◆ log_set_output_severity()

subroutine, public mo_logging::log_set_output_severity ( logical, intent(in)  bool)

Set the default for severity output.

Definition at line 176 of file mo_logging.F90.

◆ log_set_output_time()

subroutine, public mo_logging::log_set_output_time ( logical, intent(in)  bool)

Set time-only date format.

Definition at line 188 of file mo_logging.F90.

◆ log_set_skip_terminal_check()

subroutine, public mo_logging::log_set_skip_terminal_check ( logical, intent(in)  bool)

Whether or not to skip the terminal check.

Definition at line 200 of file mo_logging.F90.

◆ log_severity()

character(len=50) function mo_logging::log_severity ( integer, intent(in)  level,
logical, intent(in)  show_colors 
)
private

Return the severity level with colors etc in a 50 char string.

Returns
severity level.

Definition at line 394 of file mo_logging.F90.

References bold, color_codes, level_color, log_debug, log_error, log_fatal, log_info, log_severity(), log_subtrace, log_trace, log_warn, reset, and stput().

Referenced by log_severity(), and logl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logl()

character(len=300) function, public mo_logging::logl ( integer  level,
character(len=*), optional  filename,
integer, optional  linenum 
)

Write a log lead containing level and optional info.

The name is shortened to allow for longer log messages without needing continuations.

Returns
The output log leader.
Parameters
levelThe log level
filenameAn optional filename to add to the log lead
linenumWith line number
Returns
The output log leader

Definition at line 259 of file mo_logging.F90.

References color_codes, log_datetime(), log_hostname(), log_severity(), logl(), minimum_log_level, num_log_levels, reset, show_file_and_line, spaces(), stput(), strip_path(), and style_codes.

Referenced by logl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logp()

logical function, public mo_logging::logp ( integer, intent(in)  level,
integer, intent(in), optional  only_n 
)

Output this log statement or not.

Returns
true if this log message can be printed.
Parameters
[in]levelThe log level of the current message
[in]only_nShow only if the current mpi rank equals only_n
Returns
Output: true if this log message can be printed

Definition at line 232 of file mo_logging.F90.

References logp(), and minimum_log_level.

Referenced by logp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logu()

integer function, public mo_logging::logu ( integer, intent(in)  level)

Output unit to log.

Returns
unit number.
Parameters
[in]levelThe log level of the current message
Returns
unit to log to (stderr for level <=2 else stdout by default)

Definition at line 219 of file mo_logging.F90.

References log_error, log_unit, log_unit_error, and logu().

Referenced by logu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spaces()

character(len=n) function mo_logging::spaces ( integer, intent(in)  n)
private

Return n spaces.

Returns
n spaces.
Parameters
[in]nMaximum is 30

Definition at line 386 of file mo_logging.F90.

References spaces().

Referenced by logl(), and spaces().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stput()

subroutine, public mo_logging::stput ( character(len=*), intent(inout)  str,
character(len=*), intent(in)  code 
)

generate format string

Parameters
[in,out]strpre string
[in]codeformat code

Definition at line 162 of file mo_logging.F90.

References start.

Referenced by log_severity(), logl(), and mo_message::message().

Here is the caller graph for this function:

◆ strip_path()

subroutine mo_logging::strip_path ( character(len=*), intent(in)  filepath,
character(len=*), intent(out)  basename 
)
private

Get base name of a file path.

Parameters
[in]filepathThe path to be stripped
[out]basenameThe basename of the filepath

Definition at line 357 of file mo_logging.F90.

Referenced by logl().

Here is the caller graph for this function:

◆ tput()

subroutine mo_logging::tput ( integer, intent(in)  lu,
character(len=*), intent(in)  code 
)
private

write format string to given unit

Parameters
[in]luunit
[in]codeformat code

Definition at line 154 of file mo_logging.F90.

References start.

Variable Documentation

◆ blink

character(len=*), parameter mo_logging::blink = "5"
private

Definition at line 129 of file mo_logging.F90.

◆ bold

character(len=*), parameter mo_logging::bold = "1"
private

Styles.

Definition at line 129 of file mo_logging.F90.

Referenced by log_severity().

◆ color_codes

character(len=*), dimension(num_log_levels), parameter mo_logging::color_codes = ["31", "31", "33", "32", "35", "36", "36"]
private

These are the color codes corresponding to the loglevels above.

Definition at line 143 of file mo_logging.F90.

Referenced by log_severity(), and logl().

◆ dimmed

character(len=*), parameter mo_logging::dimmed = "2"
private

Definition at line 129 of file mo_logging.F90.

◆ disable_colors

logical, save mo_logging::disable_colors = .false.
private

Definition at line 139 of file mo_logging.F90.

◆ disable_format

logical, save mo_logging::disable_format = .false.
private

Definition at line 140 of file mo_logging.F90.

◆ hidden

character(len=*), parameter mo_logging::hidden = "8"
private

Definition at line 129 of file mo_logging.F90.

◆ invert

character(len=*), parameter mo_logging::invert = "7"
private

Definition at line 129 of file mo_logging.F90.

◆ level_color

character(len=*), parameter mo_logging::level_color = "20"
private

Colors for other output.

Definition at line 150 of file mo_logging.F90.

Referenced by log_severity().

◆ log_debug

integer, parameter, public mo_logging::log_debug = LOG_LEVEL_DEBUG_DEF

= 5, Detailed debug output, disable by compiling your program with -DDISABLE_LOG_DEBUG

Definition at line 102 of file mo_logging.F90.

Referenced by log_severity().

◆ log_error

integer, parameter, public mo_logging::log_error = LOG_LEVEL_ERROR_DEF

= 2, Runtime error

Definition at line 99 of file mo_logging.F90.

Referenced by log_severity(), and logu().

◆ log_fatal

integer, parameter, public mo_logging::log_fatal = LOG_LEVEL_FATAL_DEF

= 1, Runtime error causing termination

Definition at line 98 of file mo_logging.F90.

Referenced by log_severity().

◆ log_info

integer, parameter, public mo_logging::log_info = LOG_LEVEL_INFO_DEF

= 4, Interesting events

Definition at line 101 of file mo_logging.F90.

Referenced by log_severity().

◆ log_subtrace

integer, parameter, public mo_logging::log_subtrace = LOG_LEVEL_SUBTRACE_DEF

= 7, More Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable

Definition at line 104 of file mo_logging.F90.

Referenced by log_severity().

◆ log_trace

integer, parameter, public mo_logging::log_trace = LOG_LEVEL_TRACE_DEF

= 6, Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable

Definition at line 103 of file mo_logging.F90.

Referenced by log_severity().

◆ log_unit

integer, save, public mo_logging::log_unit = stdout

By default, log to stdout for level > 2.

Definition at line 106 of file mo_logging.F90.

Referenced by logu().

◆ log_unit_error

integer, save, public mo_logging::log_unit_error = stderr

By default, log to stderr for level <= 2.

Definition at line 107 of file mo_logging.F90.

Referenced by logu().

◆ log_warn

integer, parameter, public mo_logging::log_warn = LOG_LEVEL_WARN_DEF

= 3, Warning, but we can continue

Definition at line 100 of file mo_logging.F90.

Referenced by log_severity().

◆ minimum_log_level

integer, save, public mo_logging::minimum_log_level = LOG_INFO

Note that more critical means a lower number.

Definition at line 108 of file mo_logging.F90.

Referenced by log_set_config(), logl(), and logp().

◆ num_log_levels

integer, parameter, public mo_logging::num_log_levels = 7

1 through 7 (fatal through trace)

Definition at line 97 of file mo_logging.F90.

Referenced by log_set_config(), and logl().

◆ output_date

logical, save mo_logging::output_date = .false.
private

Definition at line 135 of file mo_logging.F90.

◆ output_fileline

logical, save mo_logging::output_fileline = .true.
private

Definition at line 137 of file mo_logging.F90.

◆ output_hostname

logical, save mo_logging::output_hostname = .false.
private

Definition at line 133 of file mo_logging.F90.

◆ output_severity

logical, save mo_logging::output_severity = .true.
private

Definition at line 134 of file mo_logging.F90.

◆ output_time

logical, save mo_logging::output_time = .false.
private

Definition at line 136 of file mo_logging.F90.

◆ reset

character(len=*), parameter mo_logging::reset = "0"
private

Control reset character.

Definition at line 127 of file mo_logging.F90.

Referenced by log_severity(), and logl().

◆ show_file_and_line

logical, save, public mo_logging::show_file_and_line = .true.

show file name and line number in log output

Definition at line 109 of file mo_logging.F90.

Referenced by logl().

◆ skip_terminal_check

logical, save mo_logging::skip_terminal_check = .false.
private

Definition at line 138 of file mo_logging.F90.

◆ start

character(len=*), parameter mo_logging::start = achar(27)
private

Control start character.

Definition at line 125 of file mo_logging.F90.

Referenced by stput(), and tput().

◆ style_codes

character(len=*), dimension(num_log_levels), parameter mo_logging::style_codes = [bold, reset, reset, reset, reset, reset, reset]
private

These are the styles corresponding to the loglevels above.

Definition at line 146 of file mo_logging.F90.

Referenced by logl().

◆ underline

character(len=*), parameter mo_logging::underline = "4"
private

Definition at line 129 of file mo_logging.F90.