Logging Messages

Antares uses the logging module of python to print messages. For more information on this module, you may consider the following two urls:

As a reminder, the rank of logging messages is: NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL.

Starting from version 1.14.0, antares does not produce any output messages by default, except the header when importing the module. The progress bar is also disabled. If you want to get the old behaviour back, then you can use the following instructions:

import logging
import antares
antares.add_stderr_logger(logging.INFO)
antares.set_progress_bar(value=True)

The standard output is set to INFO, so the console logger will show warnings, errors, and criticals as well. If you also want available debugging information, then use:

antares.add_stderr_logger(logging.DEBUG)

The function add_stderr_logger() is really a helper function. You may consider to customize your application with what follows in the next section.

antares.add_stderr_logger(level=10)

Add a StreamHandler to the antares logger.

Useful for debugging.

Returns the handler after adding it.

How to customize your outputs

When creating your application, you can ask the module antares to output messages available in its component. First, create your own logger with a specific handler (or more) with custom formats such as:

import logging
logger = logging.getLogger("antares") # get the logger of antares
handler = logging.StreamHandler()     # messages will go to the console
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)       # format of the messages
logger.addHandler(handler)            # put the handler to the logger
logger.setLevel(logging.INFO)         # set the logging level of verbosity

All informative elements will be output to the console as

2019-07-02 14:06:41,672 antares.treatment.TreatmentCut INFO     Cut
2019-07-02 14:06:41,693 antares.treatment.TreatmentMerge INFO     Merge
2019-07-02 14:06:41,715 antares.treatment.TreatmentUnwrapLine INFO     Unwrap

If you want to output messages in a file, then use a FileHandler as:

import logging
logger = logging.getLogger("antares")     # get the logger of antares
handler = logging.FileHandler('logg.txt') # messages will go to the file 'logg.txt'
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)           # format of the messages
logger.addHandler(handler)                # put the handler to the logger
logger.setLevel(logging.DEBUG)            # set the logging level of verbosity

The file ‘logg.txt’ will contain all messages above DEBUG.

When creating your application, you can ask for only a submodule of antares to output messages available in its component. For example, if you only want messages from the merge treatment, then get the logger of this module as

logger = logging.getLogger("antares.treatment.TreatmentMerge")

and use your favorite handler.