Skip to main content

Console

C++: phynexis::utils::console Python: phynexis.utils Header: src/utils/console.hpp

Console logging and output control for phynexis. Supports leveled output (debug/info/warning/error/fatal), colorized terminal output, timestamps, and MPI rank display.

Level

C++: phynexis::utils::console::Level Python: phynexis.utils.Level

Enum controlling the minimum log level for output filtering.

ValueNumericDescription
Level.DEBUG0Debug messages
Level.INFO1Informational messages (default minimum)
Level.WARNING2Warning messages
Level.ERROR3Error messages
Level.FATAL4Fatal error messages

MPIOutputMode

C++: phynexis::utils::console::MPIOutputMode Python: phynexis.utils.MPIOutputMode

Enum controlling MPI output behavior.

ValueDescription
MPIOutputMode.ONLY_MASTEROnly rank 0 outputs (default)
MPIOutputMode.ALL_WITH_RANKAll ranks output with rank prefix

Config

C++: phynexis::utils::console::Config Python: phynexis.utils.Config

Configuration object controlling the appearance and filtering of console output.

Constructor

Config()

Creates a config with default settings (min_level=info, timestamps on, colors on).

Static Methods

Config.debug()

Create a Config with min_level=DEBUG for verbose debugging output.

Config.release()

Create a Config with min_level=WARNING for production/release output (only warnings and above).

Config.verbose()

Create a Config with min_level=DEBUG and show_location=True for detailed debug output.

Properties

PropertyTypeAccessDescription
min_levelLevelread/writeMinimum log level to display
show_timestampboolread/writeShow timestamps in output
show_levelboolread/writeShow level tag (INFO, WARN, etc.)
show_locationboolread/writeShow file/line location
color_outputboolread/writeEnable ANSI color codes
show_rankboolread/writeShow MPI rank prefix

Methods

set_min_level(level)

Set minimum display level. Returns the Config object for chaining.

Parameters:

ParameterTypeDescription
levelLevelMinimum level to display

set_show_timestamp(enabled)

Toggle timestamp display. Returns the Config object for chaining.

set_show_level(enabled)

Toggle level tag display. Returns the Config object for chaining.

set_show_location(enabled)

Toggle source location display. Returns the Config object for chaining.

set_color_output(enabled)

Toggle colorized output. Returns the Config object for chaining.

set_show_rank(enabled)

Toggle MPI rank prefix display. Returns the Config object for chaining.

Example:

import phynexis

cfg = phynexis.utils.custom()
cfg.show_timestamp = False
cfg.color_output = False

phynexis.utils.info("no timestamp, no color")

# Config factory methods
debug_cfg = phynexis.utils.Config.debug()
release_cfg = phynexis.utils.Config.release()
print("debug min_level:", debug_cfg.min_level)
print("release min_level:", release_cfg.min_level)

Output:

[INFO] no timestamp, no color
debug min_level: Level.DEBUG
release min_level: Level.WARNING

Logging Functions

Module-level functions for leveled console output.

debug(msg)

Print a debug-level message. Only visible when min_level ≤ 0.

info(msg)

Print an info-level message.

plain(msg)

Print a plain message without any level prefix or formatting.

warning(msg)

Print a warning-level message.

error(msg)

Print an error-level message.

fatal(msg)

Print a fatal-level message and terminate.

Parameters:

ParameterTypeDescription
msgstrMessage string to print

Broadcast Variants

Each level has an _all variant that broadcasts to all MPI ranks:

  • debug_all(msg)
  • info_all(msg)
  • warning_all(msg)
  • error_all(msg)
  • fatal_all(msg)

Example:

import phynexis

phynexis.utils.info("simulation started")
phynexis.utils.debug("debug info: dt=1e-5")
phynexis.utils.warning("mesh quality low")
phynexis.utils.plain("raw output without prefix")

Output:

[INFO] [12:01:05.232] simulation started
[DEBUG] [12:01:05.233] debug info: dt=1e-5
[WARNING] [12:01:05.233] mesh quality low
raw output without prefix

Control Functions

set_level(level)

Set the global minimum log level.

Parameters:

ParameterTypeDescription
levelLevelMinimum level, e.g. Level.WARNING

set_verbose(enabled)

Enable or disable verbose (debug) output. Equivalent to set_level(0).

set_color(enabled)

Enable or disable colorized output globally.

custom()

Return a reference to the global Config object. Modifications to the returned object take effect immediately.

Returns: Config — global configuration (mutable reference)

Example:

import phynexis

phynexis.utils.set_level(phynexis.utils.Level.WARNING) # Only warning and above
phynexis.utils.info("hidden")
phynexis.utils.warning("visible")

Output:

[WARNING] visible