MNELogger
Namespace: UTILSLIB · Library: Utilities Library
#include <utils/mne_logger.h>
class UTILSLIB::MNELogger
The Apllicationlogger provides colorized keywords in terminal outputs for better overview.
Custom Qt message handler that formats and routes qDebug/qWarning/qCritical output to file or console.
qInstallMessageHandler(MNELogger::customLogWriter); // coloured console output
MNELogger::setLogFile(dir.filePath("example.log")); // and a plain-text copy
qInfo() << "logging to" << MNELogger::logFile();
Static Methods
customLogWriter(type, context, msg)
Customized logWriter to colorize type of the message in the terminal.
Parameters:
-
type : QtMsgType Enum to identify the various message types (qDebug, qInfo, qCritical, qWarning and qFatal).
-
context : const QMessageLogContext & Context provides information about the source code location.
-
msg : const QString & The message to print in the terminal.
setLogFile(sFilePath)
Additionally writes every message to a log file.
Console output is unaffected. The file is opened in append mode and each line is prefixed with a timestamp and the message level, without the terminal colour codes. Passing an empty path stops file logging.
Parameters:
- sFilePath : const QString & Path of the log file, or an empty string to disable.
Returns:
- bool — True if the file could be opened for writing.
logFile()
Returns the path of the current log file, empty if file logging is off.
Returns:
- QString — Path of the active log file, or an empty string if file logging is disabled.
Example
- Full source:
src/examples/ex_utils/main.cpp - Build target:
ex_utils(runs under CTest)
Used in examples
ex_utils
Utilities library: buffers, observers, logging, file formats, montages, layouts and reports.
qInstallMessageHandler(MNELogger::customLogWriter); // coloured console output
MNELogger::setLogFile(dir.filePath("example.log")); // and a plain-text copy
qInfo() << "logging to" << MNELogger::logFile();
MNELogger::setLogFile(QString());
QFile log(dir.filePath("example.log"));
ok &= expect(log.open(QIODevice::ReadOnly) && log.readAll().contains("logging to"), "MNELogger wrote the message to the log file");
ex_averaging
Average data from a raw data file.
qInstallMessageHandler(MNELogger::customLogWriter);
QCoreApplication a(argc, argv);
ex_cancel_noise
Example of noise cancellation procedures.
qInstallMessageHandler(MNELogger::customLogWriter);
QCoreApplication app(argc, argv);
Also used in ex_clustered_inverse_mne, ex_clustered_inverse_mne_raw, ex_clustered_inverse_pwl_rap_music_raw, ex_clustered_inverse_rap_music_raw, ex_compute_forward, ex_connectivity, ex_connectivity_comparison, ex_coreg, ex_disp, ex_disp_3D, ex_evoked_grad_amp, ex_filtering, ex_find_evoked, ex_fs_surface, ex_histogram, ex_hpiFit, ex_interpolation, ex_inverse_mne, ex_inverse_mne_raw, ex_inverse_pwl_rap_music, ex_inverse_rap_music, ex_make_inverse_operator, ex_make_layout, ex_read_bem, ex_read_epochs, ex_read_evoked, ex_read_fwd, ex_read_fwd_disp_3D, ex_read_raw, ex_read_write_raw, ex_roi_clustered_inverse_pwl_rap_music, ex_spectral, ex_st_clustered_inverse_pwl_rap_music, ex_tf_plot.
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>