87 lines
4.6 KiB
Plaintext
87 lines
4.6 KiB
Plaintext
---
|
|
~~Title: Error Logging~~
|
|
---
|
|
|
|
# Error Logging #
|
|
|
|
EFL uses a common method to log error messages, called ``Eina_Log``, which allows you to adjust the verbosity of the logs using environment variables.
|
|
|
|
The ``Eina_Log`` module provides logging facilities for libraries and applications. It provides colored logging, basic logging levels (error, warning, debug, info, critical) and *logging domains*, or *loggers*. For those unfamiliar with this term, it offers a way to separate a set of log messages into a specific context (e.g. a module) and provides a way of controlling this set as a whole.
|
|
|
|
## Available Log Levels ##
|
|
|
|
| Level | Number | Macro |
|
|
|---------|--------|---------------------|
|
|
|Critical | 0 | ``EINA_LOG_CRIT()`` |
|
|
|Error | 1 | ``EINA_LOG_ERR()`` |
|
|
|Warning | 2 | ``EINA_LOG_WARN()`` |
|
|
|Info | 3 | ``EINA_LOG_INFO()`` |
|
|
|Debug | 4 | ``EINA_LOG_DBG()`` |
|
|
|
|
## Logging Domains ##
|
|
|
|
Logging domains are a way to separate a set of log messages into a context (e.g. a module) and provide a way of controlling this set as a whole.
|
|
|
|
Suppose you have three different modules in your application and you want to get logging only from one of them (i.e. to create some sort of filter). To achieve that all you need to do is create a logging domain for each module so that all logging inside a module can be considered as a whole.
|
|
|
|
Logging domains are specified by a name, color applied to the name and the level. The first two (log name and log color) are set through code inside your application, module or library.
|
|
|
|
The log level is used to control which messages should appear. It specifies the lowest level that should be displayed, i.e. a message with level 2 being logged on a domain with level set to 3 would be displayed while a message with level 4 wouldn't.
|
|
|
|
## Setting the Log Level ##
|
|
|
|
Logging of domain and global messages can be controlled at runtime using the following environment variables.
|
|
|
|
### Domain Logging ###
|
|
|
|
Domain level logging is set during runtime, in contrast with the name and color, through the environment variable ``EINA_LOG_LEVELS``.
|
|
|
|
```bash
|
|
EINA_LOG_LEVELS=module1:4,module2:2,module3:0 ./{application}
|
|
```
|
|
|
|
In this example the command would set the log level of ``module1`` to 4, ``module2`` to 2, and ``module3`` to 0.
|
|
|
|
### General Logging ###
|
|
|
|
The global logger to which ``EINA_LOG_{ERR, DBG, INFO, CRIT, WARN}`` macros log is created internally by ``Eina_Log`` with an empty name and can be used for general logging, where logging domains do not apply.
|
|
|
|
Since this global logger doesn't have a name, you can't set its level through the ``EINA_LOG_LEVELS`` variable. Instead, it is controlled via the ``EINA_LOG_LEVEL`` variable.
|
|
|
|
To set the general log level use the ``EINA_LOG_LEVEL`` environment variable:
|
|
|
|
```bash
|
|
EINA_LOG_LEVEL={N} ./{application}
|
|
```
|
|
|
|
Where ``{N}`` is the log level number and ``{application}`` the binary you are currently debugging.
|
|
|
|
> **NOTE:**
|
|
> The global ``EINA_LOG_LEVEL`` can also be set within your code using the ``eina_log_level_set()`` function.
|
|
|
|
#### Disabling Internal Eina Logging ####
|
|
|
|
While developing your libraries or applications, you may notice that the ``EINA_LOG_DOM_{ERR, DBG, INFO, CRIT, WARN}`` macros also print out messages from ``Eina`` itself. To tidy up the logging output use the following command to disable the logging of intenal ``Eina`` code:
|
|
|
|
```bash
|
|
EINA_LOG_LEVEL={N} EINA_LOG_LEVELS_GLOB=eina_*:0 ./{application}
|
|
```
|
|
|
|
Where ``{N}`` is the log level number and ``{application}`` the binary you are currently debugging. Removing these internal logs from the output makes it easier for you to see your own domain messages.
|
|
|
|
### Aborting on Selected Log Level ##
|
|
|
|
As well as controlling the logs themselves, the respective log levels can be used to close a program - calling ``abort()`` - once a message of a given level is logged, allowing you to automatically terminate execution. This is toggled through the environment variable ``EINA_LOG_ABORT``, while the level to be considered critical - and thus terminate execution - through the environment variable ``EINA_LOG_ABORT_LEVEL``.
|
|
|
|
> **NOTE:**
|
|
> Aborting at a particular log level can also be controlled from within the application itself using the ``eina_log_abort_on_critical_set()`` and ``eina_log_abort_on_critical_level_set()`` functions.
|
|
|
|
```bash
|
|
EINA_LOG_ABORT=1 EINA_LOG_ABORT_LEVEL={N} ./{application}
|
|
```
|
|
Where ``{N}`` is the log level number and ``{application}`` the binary you are currently debugging.
|
|
|
|
## Further Reading ##
|
|
|
|
[Eina Programming Guide: Logging](/develop/guides/c/eina/logging.md)
|
|
: A reference, including example, for the Eina_Log module. |