FORCES
FORtran lib for Comp. Env. Sys.
|
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. | |
Module providing a logging framework.
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.
Afterwards you have a list of logging routines that could be used instead of write
:
log_fatal(format)
: level 1log_error(format)
: level 2log_warn(format)
: level 3log_info(format)
: level 4log_debug(format)
: level 5log_trace(format)
: level 6log_subtrace(format)
: level 7 as required.The following example demonstrates the functionality. The mo_cli
module incorporates logger settings:
You can call the program with:
You can see all cli logger options with:
COPYING
and COPYING.LESSER
provided with this software. The complete GNU license text can also be found at http://www.gnu.org/licenses/.
|
private |
Return the current date, formatted nicely.
Definition at line 448 of file mo_logging.F90.
References log_datetime().
Referenced by log_datetime(), and logl().
|
private |
Return the hostname in a 50 character string.
Definition at line 368 of file mo_logging.F90.
References log_hostname().
Referenced by log_hostname(), and logl().
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.
[in] | verbose | increase verbosity level |
[in] | quiet | decrease verbosity level |
[in] | log_output_hostname | show hostname |
[in] | log_force_colors | force colors in output |
[in] | log_no_colors | disable colors |
[in] | log_output_date | add date to output |
[in] | log_output_time | add time to output |
[in] | log_no_format | disable 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().
subroutine, public mo_logging::log_set_disable_colors | ( | logical, intent(in) | bool | ) |
Disable colors altogether.
Definition at line 206 of file mo_logging.F90.
subroutine, public mo_logging::log_set_disable_format | ( | logical, intent(in) | bool | ) |
Disable formatting altogether.
Definition at line 212 of file mo_logging.F90.
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.
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.
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.
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.
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.
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.
|
private |
Return the severity level with colors etc in a 50 char string.
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().
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.
level | The log level |
filename | An optional filename to add to the log lead |
linenum | With line number |
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().
logical function, public mo_logging::logp | ( | integer, intent(in) | level, |
integer, intent(in), optional | only_n | ||
) |
Output this log statement or not.
[in] | level | The log level of the current message |
[in] | only_n | Show only if the current mpi rank equals only_n |
Definition at line 232 of file mo_logging.F90.
References logp(), and minimum_log_level.
Referenced by logp().
integer function, public mo_logging::logu | ( | integer, intent(in) | level | ) |
Output unit to log.
[in] | level | The log level of the current message |
Definition at line 219 of file mo_logging.F90.
References log_error, log_unit, log_unit_error, and logu().
Referenced by logu().
|
private |
Return n spaces.
[in] | n | Maximum is 30 |
Definition at line 386 of file mo_logging.F90.
References spaces().
Referenced by logl(), and spaces().
subroutine, public mo_logging::stput | ( | character(len=*), intent(inout) | str, |
character(len=*), intent(in) | code | ||
) |
generate format string
[in,out] | str | pre string |
[in] | code | format code |
Definition at line 162 of file mo_logging.F90.
References start.
Referenced by log_severity(), logl(), and mo_message::message().
|
private |
Get base name of a file path.
[in] | filepath | The path to be stripped |
[out] | basename | The basename of the filepath |
Definition at line 357 of file mo_logging.F90.
Referenced by logl().
|
private |
write format string to given unit
[in] | lu | unit |
[in] | code | format code |
Definition at line 154 of file mo_logging.F90.
References start.
|
private |
Definition at line 129 of file mo_logging.F90.
|
private |
|
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().
|
private |
Definition at line 129 of file mo_logging.F90.
|
private |
Definition at line 139 of file mo_logging.F90.
|
private |
Definition at line 140 of file mo_logging.F90.
|
private |
Definition at line 129 of file mo_logging.F90.
|
private |
Definition at line 129 of file mo_logging.F90.
|
private |
Colors for other output.
Definition at line 150 of file mo_logging.F90.
Referenced by log_severity().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
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().
|
private |
Definition at line 135 of file mo_logging.F90.
|
private |
Definition at line 137 of file mo_logging.F90.
|
private |
Definition at line 133 of file mo_logging.F90.
|
private |
Definition at line 134 of file mo_logging.F90.
|
private |
Definition at line 136 of file mo_logging.F90.
|
private |
Control reset character.
Definition at line 127 of file mo_logging.F90.
Referenced by log_severity(), and logl().
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().
|
private |
Definition at line 138 of file mo_logging.F90.
|
private |
Control start character.
Definition at line 125 of file mo_logging.F90.
|
private |
These are the styles corresponding to the loglevels above.
Definition at line 146 of file mo_logging.F90.
Referenced by logl().
|
private |
Definition at line 129 of file mo_logging.F90.