# Logging

HOOPS Envision for Desktop provides a logging system used both for the internal logging and also available for logging errors, warnings, info and debug in your own application.

The logged messages can either be saved to a file (`LogDestinationFile`) or written directly to a console (`LogDestinationConsole`). You can also create your own log destination by deriving from `LogDestination` and overriding the `log()` method. This is useful if you already have a logging system in your application and would like to incorporate the logging message from Envision toolkits into your application log.

The `LogManager` controls the logging. You can get the LogManager with the `CoreComponent::logManager()` method. Set the destination (file or console) using `LogManager::setDestination()`.

The log manager provides 4 levels of log messages:

- Errors (Level 1): `LogManager::logError`
- Warnings (Level 2): `LogManager::logWarning`
- Info (Level 3): `LogManager::logInfo`
- Debug (Level 4): `LogManager::logDebug`

Each of these take a logger name and the log message. Log an error message like this:

    m_instance.logManager()->logError("myComp.import", "Could not open file");

The logger names are structured in a hierarchical system with parent/child categories which simplifies the logger level control. You can have different user defined logger names for your different modules or areas, for instance:

- Comp.import
- Comp.export
- Comp.visual

The loggers used by Envision toolkits are all under the “cee.” logger. The logger for each component is called “cee.comp.{COMPONENT_NAME}”, e.g. cee.comp.UnstructGrid. The logger “cee.cvf.*” is used for the internal Envision rendering engine.

You specify the log levels to use for your application with `cee::LogManager::setLevel()` with a logger name and a level (1-4). This log level will apply to the specified logger name and all its children. Consider the following code:

    m_instance.logManager()->setLevel("", 2);                // Only warnings and errors as a general rule
    m_instance.logManager()->setLevel("myComp", 3);          // Also show info from your app (myComp.*) destinations
    m_instance.logManager()->setLevel("myComp.import", 4);   // Also show debug from import (myComp.import.*) destinations

This will log errors and warnings globally, but also show info messages from everything under myComp.*. Debug messages from myComp.import will in addition be logged, but myComp.export will still be at level 3 and just show errors, warnings and info.

Good practice is setting up the logger at the same place as you initialize HOOPS Envision for Desktop. Once the logger is set up, you can send log messages from anywhere using m_instance.logManager()->log*(“logger name”, “logger message”).

Logger example setup from the demo application:

    QString logFile = logDir.absoluteFilePath("HOOPSEnvisionQtDemoLog.txt");
    compInst->logManager()->setDestination(new cee::LogDestinationFile(cee::qt::Utils::toStr(logFile)));
    compInst->logManager()->setLevel(cee::Str(""), 2);          // Only warnings and errors as a general rule
    compInst->logManager()->setLevel(cee::Str("cee.comp"), 3);  // Also show info from components (cee.comp.*) destinations
    compInst->logManager()->setLevel(cee::Str("cee.demo"), 3);  // Also show info from app (cee.demo.*) destinations

    compInst->addVersionToLog();

    QTime time = QTime::currentTime();
    QDate date = QDate::currentDate();
    QString timeString = "Log for HOOPS Envision Qt Demo App. Started: " + date.toString() + " " + time.toString();
    compInst->logManager()->logInfo("cee.demo", cee::qt::Utils::toStr(timeString));

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Envision for Desktop or choose a sample question below to start a conversation:

What is HOOPS Envision for Desktop?
What are the latest release notes for HOOPS Envision for Desktop?
How do I start evaluating HOOPS Envision for Desktop?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...