Logging#

By default, all output and logging messages of Fesslix are sent to the file fesslix.log in the current working directory. Additionaly, most logging messages are also sent to the standard output (the screen). However, it is also possible to log exclusively to the standard output (count) or a log file.

Configuration#

Where the logging information should be written to is controlled by the Configuration options described in Control the logging behavior.

Log levels in Fesslix#

flx_logLevel#

Represents the logging level used in the logger of Fesslix.

Type:

int

Possible values:
  • 1: ALERT » alerts and errors are logged

  • 2: WARNING » warnings are logged

  • 3: NOTICE » normal but significant information is logge

  • 4: INFO » information

  • 5: DEBUG » debug-level messages

The default log-level is 4. If the log-level of a message is larger than the log-level set in the application, the message is not logged. The initial log-level is set using the Configuration options log.level described in Control the logging behavior.

Todo

At runtime the log-level can be controlled by means of the object default and the DefSet- Name log::level.

Generate user-defined log messages#

You can also use the logging interface of Fesslix from within Python through the function flx.slog():

flx.slog()#
Syntax:

flx.slog(log_message,log_level=4)

Description:

Send user-defined messages to the logger of Fesslix.

Parameters:
  • log_message (str) – The log message to be logged.

  • log_level (flx_logLevel) – The level to use for logging.

Return type:

None

Example#

import fesslix as flx
flx.load_engine()

## Use flx.slog(LOG_LEVEL,LOG_MESSAGE) to generate a log entry
##    LOG_LEVEL   :: int
##    LOG_MESSAGE :: string
flx.slog("Hello world!", 3)
Random Number Generator: MT19937 - initialized with rand()=235035918;
Random Number Generator: MT19937 - initialized with 1000 initial calls.
Hello world!

Using a logger from Python’s logging module#

However, you can also use Python’s logging module to configure the logging behavior of Fesslix. For information on how to use the logging module, check out the Python logging HowTo or this tutorial.

Python’s logging module uses the following default log levels: DEBUG, INFO, WARNING, ERROR and CRITICAL. The mapping between Python’s log-levels and the log-levels in Fesslix is:

  • 5 » DEBUG

  • 4 » INFO

  • 3 » INFO

  • 2 » WARNING

  • 1 » CRITICAL

The following example demonstrates how to set up a logger in Python that logs to both the command line and into a file:

import logging

## ===========================
## Create and configure logger
## ===========================
logger = logging.getLogger("fesslix")   ## you can assign any name to the logger you want
logger.setLevel(logging.DEBUG)
## If you increase the log-Level, 
## only log messages at least as important as the specified level 
## will be outputted.

## =====================
## Create a file handler
## =====================
## Send log messages to file 'fesslix.log':
file_handler = logging.FileHandler("flx.log", mode="w") 
## mode: 'w' » overwrite existing log-file
##       'a' » append to existing log-file
file_handler.setLevel(logging.DEBUG)

## Define a log format
formatter = logging.Formatter(
       "{asctime} » {levelname} » {message}",
        style="{",
        datefmt="%Y-%m-%d %H:%M",
    )
file_handler.setFormatter(formatter)

## Add handler to the logger
logger.addHandler(file_handler)

## =====================
## Create a console handler
## =====================
## Send log messages to the console:
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
## log only messages with level equal to at least 'INFO' to the console.

## Define a log format
formatter = logging.Formatter("{levelname} - {message}", style="{")
console_handler.setFormatter(formatter)

## Add handler to the logger
logger.addHandler(console_handler)

It is important to set not only the log-level of each handler, but also the log-Level of logger. Log messages will appear on a specific handler if the log-Level of the message is at least as important as the log-Level specified for both the handler and the logger.

In order to link the logger to Fesslix, use set_logger(LOGGER):

## link the 'logger' to fesslix:
flx.set_logger(logger)
flx.load_engine()

## Now Fesslix uses 'logger':
flx.slog("Hello again!", 3)
logger.info("Hi!")
flx.slog("See you!", 2)
flx.slog("Bye!")
INFO - Random Number Generator: MT19937 - initialized with rand()=235035918;
INFO - Random Number Generator: MT19937 - initialized with 1000 initial calls.
INFO - Gauss-points: up to 20 Gauss points inserted.
INFO - Hello again!
INFO - Hi!
WARNING - See you!
INFO - Bye!

The content of the generated log file ‘flx.log’ is:

!cat flx.log
2026-01-28 21:05 » INFO » Random Number Generator: MT19937 - initialized with rand()=235035918;
2026-01-28 21:05 » INFO » Random Number Generator: MT19937 - initialized with 1000 initial calls.
2026-01-28 21:05 » INFO » Gauss-points: up to 20 Gauss points inserted.
2026-01-28 21:05 » INFO » Hello again!
2026-01-28 21:05 » INFO » Hi!
2026-01-28 21:05 » WARNING » See you!
2026-01-28 21:05 » INFO » Bye!

Attention

Usually, you want to register the user-defined Python logger before you Start the Fesslix engine with flx.load_engine().