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

Module providing a logging framework. More...

#include "logging.h"
Include dependency graph for mo_logging.F90:

Go to the source code of this file.

Modules

module  mo_logging
 Module providing a logging framework.
 

Functions/Subroutines

subroutine mo_logging::tput (lu, code)
 write format string to given unit
 
subroutine, public mo_logging::stput (str, code)
 generate format string
 
subroutine, public mo_logging::log_set_output_hostname (bool)
 Set the default for hostname output.
 
subroutine, public mo_logging::log_set_output_severity (bool)
 Set the default for severity output.
 
subroutine, public mo_logging::log_set_output_date (bool)
 Set the default for date output.
 
subroutine, public mo_logging::log_set_output_time (bool)
 Set time-only date format.
 
subroutine, public mo_logging::log_set_output_fileline (bool)
 Set the default for file/line output.
 
subroutine, public mo_logging::log_set_skip_terminal_check (bool)
 Whether or not to skip the terminal check.
 
subroutine, public mo_logging::log_set_disable_colors (bool)
 Disable colors altogether.
 
subroutine, public mo_logging::log_set_disable_format (bool)
 Disable formatting altogether.
 
integer function, public mo_logging::logu (level)
 Output unit to log.
 
logical function, public mo_logging::logp (level, only_n)
 Output this log statement or not.
 
character(len=300) function, public mo_logging::logl (level, filename, linenum)
 Write a log lead containing level and optional info.
 
subroutine mo_logging::strip_path (filepath, basename)
 Get base name of a file path.
 
character(len=50) function mo_logging::log_hostname ()
 Return the hostname in a 50 character string.
 
character(len=n) function mo_logging::spaces (n)
 Return n spaces.
 
character(len=50) function mo_logging::log_severity (level, show_colors)
 Return the severity level with colors etc in a 50 char string.
 
character(50) function mo_logging::log_datetime ()
 Return the current date, formatted nicely.
 
subroutine, public mo_logging::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 mo_logging::num_log_levels = 7
 1 through 7 (fatal through trace)
 
integer, parameter, public mo_logging::log_fatal = LOG_LEVEL_FATAL_DEF
 = 1, Runtime error causing termination
 
integer, parameter, public mo_logging::log_error = LOG_LEVEL_ERROR_DEF
 = 2, Runtime error
 
integer, parameter, public mo_logging::log_warn = LOG_LEVEL_WARN_DEF
 = 3, Warning, but we can continue
 
integer, parameter, public mo_logging::log_info = LOG_LEVEL_INFO_DEF
 = 4, Interesting events
 
integer, parameter, public mo_logging::log_debug = LOG_LEVEL_DEBUG_DEF
 = 5, Detailed debug output, disable by compiling your program with -DDISABLE_LOG_DEBUG
 
integer, parameter, public mo_logging::log_trace = LOG_LEVEL_TRACE_DEF
 = 6, Extremely detailed output, compile your program with -DENABLE_LOG_TRACE to enable
 
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
 
integer, save, public mo_logging::log_unit = stdout
 By default, log to stdout for level > 2.
 
integer, save, public mo_logging::log_unit_error = stderr
 By default, log to stderr for level <= 2.
 
integer, save, public mo_logging::minimum_log_level = LOG_INFO
 Note that more critical means a lower number.
 
logical, save, public mo_logging::show_file_and_line = .true.
 show file name and line number in log output
 
character(len= *), parameter mo_logging::start = achar(27)
 Control start character.
 
character(len= *), parameter mo_logging::reset = "0"
 Control reset character.
 
character(len= *), parameter mo_logging::bold = "1"
 Styles.
 
character(len= *), parameter mo_logging::dimmed = "2"
 
character(len= *), parameter mo_logging::underline = "4"
 
character(len= *), parameter mo_logging::blink = "5"
 
character(len= *), parameter mo_logging::invert = "7"
 
character(len= *), parameter mo_logging::hidden = "8"
 
logical, save mo_logging::output_hostname = .false.
 
logical, save mo_logging::output_severity = .true.
 
logical, save mo_logging::output_date = .false.
 
logical, save mo_logging::output_time = .false.
 
logical, save mo_logging::output_fileline = .true.
 
logical, save mo_logging::skip_terminal_check = .false.
 
logical, save mo_logging::disable_colors = .false.
 
logical, save mo_logging::disable_format = .false.
 
character(len= *), dimension(num_log_levels), parameter mo_logging::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 mo_logging::style_codes = [bold, reset, reset, reset, reset, reset, reset]
 These are the styles corresponding to the loglevels above.
 
character(len= *), parameter mo_logging::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:

  • log_fatal(format): level 1
  • log_error(format): level 2
  • log_warn(format): level 3
  • log_info(format): level 4
  • log_debug(format): level 5
  • log_trace(format): level 6
  • log_subtrace(format): level 7 as required.

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

Definition in file mo_logging.F90.