Loading...
Searching...
No Matches
Logging

Definition

Global logging, ANSI-colored diagnostics, and pretty error/warning reporting for fpx.

This module is the central place for all human-readable output in the fpx preprocessor. It provides:

  • Full ANSI color and style support (bold, underline, colors, etc.)
  • Structured diagnostic messages with source context, line numbers, and caret markers
  • Pretty-printed multi-line error/warning/help/note/info reports
  • Label-based highlighting of specific code ranges (like rustc-style diagnostics)
  • Recursive sub-diagnostic support for nested explanations

Designed to produce modern, readable, IDE-friendly output similar to rustc, clang, or cargo. When nocolor = .true. (or terminal does not support ANSI), falls back to plain text.

Examples

  1. Simple colored message (used internally for verbose logging):
    use fpx_logging
    verbose = .true.
    print '(A)', render('Macro expanded: PI = 3.14159')
    logical, public verbose
    Master switch for verbose diagnostic output Default value is .false. (quiet mode)....
    Definition logging.f90:108
    Interface to render diagnostic messages and labels.
    Definition logging.f90:185
  2. Full diagnostic report (like a compiler error):

    character(*), parameter :: input = &
    '# This is a TOML document.' // nl // &
    'title = ' // nl // &
    '[owner]' // nl // &
    'name = ' // nl // &
    'dob = 1979-05-27T07:32:00-08:00 # First class dates' // nl // &
    '[database]' // nl // &
    'server = ' // nl // &
    'ports = [ 8001, 8001, 8002 ]' // nl // &
    'connection_max = 5000' // nl // &
    'enabled = true' // nl // &
    '[servers]' // nl // &
    ' # Indentation (tabs and/or spaces) is allowed but not required' // nl // &
    ' [servers.alpha]' // nl // &
    ' ip = ' // nl // &
    ' dc = ' // nl // &
    ' [servers.beta]' // nl // &
    ' ip = ' // nl // &
    ' dc = ' // nl // &
    '[title]' // nl // &
    'data = [ [, ], [1, 2] ]' // nl // &
    '# Line breaks are OK when inside arrays' // nl // &
    'hosts = [' // nl // &
    ' ,' // nl // &
    ' ' // nl // &
    '](A)', render(diagnostic_report(level_error, &
    message=, &
    source=, &
    label=[label_type(, 19, 2, 5, .true.), &
    label_type(, 2, 1, 5)]), &
    input)
    end
    Definition of diagnostic message.
    Definition logging.f90:269
    Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character ar...
    Definition logging.f90:246

    Output might look like (colored in terminal):

    error: duplicated key 'title' found
    --> example.toml:19:2-6
    |
    1 | # This is a TOML document.
    2 | title =
    | ----- first defined here
    3 | [owner]
    :
    18 | dc =
    19 | [title]
    | ^^^^^ table 'title' redefined here
    20 | data = [ [, ], [1, 2] ]
    |
ANSI style & color reference (used internally)
  • Styles: BOLD_ON, UNDERLINE_ON, INVERSE_ON, STRIKETHROUGH_ON, ...
  • Foreground: RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, ...
  • Background: same as foreground but prefixed with BG_
Note
This code is adapted from pretty-diagnostics.

Data Types

interface  render
 Interface to render diagnostic messages and labels. More...
interface  label_type
 Represents text as a sequence of ASCII code units. The derived type wraps an allocatable character array. More...

Variables

◆ nocolor

logical, public nocolor = .false.

Switch for controling the ANSI color output Default value is .true. (color mode on). Set to .false. to get raw string output.

Definition at line 114 of file logging.f90.

◆ verbose

logical, public verbose

Master switch for verbose diagnostic output Default value is .false. (quiet mode). Set to .true. to get detailed step-by-step information about preprocessing actions. Safe to modify at any time � the change takes effect immediately for all subsequent operations.

Definition at line 108 of file logging.f90.