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 error message
    print '(A)', render(diagnostic_report( &
    level_error, &
    message='unexpected token', &
    label=label_type('expected expression', 8, 3)), &
    'a = +')
  2. 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:122
    Generic renderer for diagnostics and source excerpts.
    Definition logging.f90:208
  3. 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
    Structured compiler diagnostic.
    Definition logging.f90:337
    Diagnostic label identifying a region of source text.
    Definition logging.f90:304

    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. The visual presentation is inspired by modern compiler diagnostics such as rustc and clang, while being adapted for Fortran workflows.

Data Types

interface  render
 Generic renderer for diagnostics and source excerpts. More...
interface  label_type
 Diagnostic label identifying a region of source text. More...
interface  diagnostic_report
 Structured compiler diagnostic. 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 128 of file logging.f90.

◆ verbose

logical, public verbose = .false.

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 122 of file logging.f90.