1. Allow easy parameters management in oai, helping the development of a flexible, modularized and fully configurable softmodem.
1. provides a common mechanism to prevent an executable to include code that is only used under specific configurations, without rebuilding the code
1. Use a common configuration API in all oai modules
1. Provide a common mechanism to allow to choose between different implementations of a given set of functions, without rebuilding the code
1. Allow development of alternative configuration sources without modifying the oai code. Today the only delivered configuration source is the libconfig format configuration file.
As a developer you may need to look at these sections:
As a developer you may need to look at these sections:
The oai logging facility is implemented in two source files, located in [common/utils](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils)
1.[log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/log.h) is the logging facility include file containing both private and public data type definitions. It also contain API prototypes.
1. Allow a flexible activation of console traces, by configuration or dynamically at any time while code is running.
Once the logging facility has been initialized and configured developpers use C preprocessor macros to include console messages in their code. At execution time, these traces will be printed or not to the console depending on the configuration, as described [here](rtusage.md). The logging facility also defines preprocessor macros to include condtional code, to dump memory blocks (buffers, messages...).
All macros are defined in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) include file, which must be included in any source file using the logging facility macros.
[log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) also includes the prototypes of the functions that have to be called to initialize, configure or get the status of console logs.
#### console messages macros
```C
LOG_E(<component>,<format>,<argument>,...)
LOG_W(<component>,<format>,<argument>,...)
LOG_I(<component>,<format>,<argument>,...)
LOG_D(<component>,<format>,<argument>,...)
LOG_T(<component>,<format>,<argument>,...)
)
```
these macros are used in place of the printf C function. The additionnal ***component*** parameter identifies the functionnal module which generates the message. At run time, the message will only be printed if the configured log level for the component is greater or equal than the macro level used in the code.
| macro | level letter | level value | level name |
component list is defined as an `enum` in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h). A new component can be defined by adding an item in this type, it must also be defined in the T tracer [T_messages.txt ](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/T/T_messages.txt).
Most oai sources are including LOG macros.
#### conditional code macros
```C
LOG_DEBUGFLAG(<flag>)
```
this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md)
```C
if ( LOG_DEBUGFLAG(<flag>) {
/*
the code below is only executed if the corresponding
<flag>_debug option is set.
*/
......................
......................
}
```
[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c#L396)
#### memory dump macros
```C
LOG_DUMPFLAG(<flag>)
```
this macro is to be used in if statements. The condition is true if the flag has been set, as described in the [run time usage page](rtusage.md). It is mainly provided to surround LOG_M macros or direct calls to `log_dump`which otherwise would be unconditionals.
```C
if ( LOG_DUMPFLAG(<flag>) {
/*
the code below is only executed if the corresponding
<flag>_dump option is set.
*/
LOG_M(.............
LOG_M(.............
log_dump(...
}
[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205)
#### matlab format dump
```C
LOG_M(file, vector, data, len, dec, format)
```
|argument| type| description |
|:-----------|:-------|-----------------:|
| file | char* |path to the fle which will contain the dump |
|vector |char * |name of the dump, printed at the top of the dump file |
|data| void *| pointer to the memory to be dumpped |
|len | int | length of the data to be dumpped, in `dec` unit|
| dec| int | length of each data item.Interpretation depends on format|
|format| int | defines the type of data to be dumped|
This macro can be used to dump a buffer in a format that can be used for analyze via tools like matlab or octave. **It must be surrounded by LOG_DEBUGFLAG or LOG_DUMPFLAG macros, to prevent the dump to be built unconditionally.** The LOG_M macro points to the `write_file_matlab` function implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). **This function should be revisited for more understandable implementation and ease of use (format parameter ???)**
[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/PHY/LTE_TRANSPORT/prach.c#L205)
#### hexadecimal format dump
```C
LOG_DUMPMSG(c, f, b, s, x...)
```
dumps a memory region if the corresponding debug flag `f` is set as explained here [run time usage page](rtusage.md)
|argument| type| description |
|:-----------|:-------|-----------------:|
| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments |
|f |int |flag used to filter the dump depending on the logs configuration. flag list is defined by the LOG_MASKMAP_INIT macro in [log.h](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.h) |
|b| void *| pointer to the memory to be dumpped |
|s | int | length of the data to be dumpped in char|
| x...| printf format and arguments| text string to be printed at the top of the dump|
This macro can be used to conditionaly dump a buffer, bytes by bytes, giving the integer value of each byte in hexadecimal form.
[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair2/RRC/LTE/rrc_eNB.c#L1181)
This macro points to the `log_dump` function, implemented in [log.c](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/LOG/log.c). This function can also dump buffers containing `double` data via the LOG_UDUMPMSG macro
```C
LOG_UDUMPMSG(c, b, s, f, x...)
```
|argument| type| description |
|:-----------|:-------|-----------------:|
| c | int, component id (in `comp_name_t` enum)| used to print the message, as specified by the s and x arguments |
|b| void *| pointer to the memory to be dumpped |
|s | int | length of the data to be dumpped in char|
|f| int | format of dumped data LOG_DUMP_CHAR or LOG_DUMP_DOUBLE|
| x...| printf format and arguments| text string to be printed at the top of the dump|
[example in oai code](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/openair1/SIMULATION/LTE_PHY/dlsim.c#L1974)
oai includes a console logging facility that any component should use when writting informational or debugging messages to the softmodem or uesoftmodem stdout stream.
By default, this facility is included at build-time and activated at run-time. The T Tracer and the Logging facility share common options for activation:
- To disable the logging facility (and T Tracer) at build-time use the *--disable-T-Tracer* switch:
```bash
/build_oai --disable-T-Tracer
```
- To use the the T-Tracer instead of the console logging facility, use the command line option *T_stdout*. *T_stdout* is a boolean option, which, when set to 0 (false) disable the console logging facility. All stdout messages are then sent to the T-Tracer.
The logging facility is fully configurable and it uses the [config module](../../../config/config.md) to get its parameters at init time. The [telnet server](../../telnetsrv/DOC/telnetsrv.md) includes a set of commands which can be used to dynamically modify the logging facility behavior
All logging facility parameters are defined in the log_config section. Some parameters are global to the logging facility, they modify the way messages are printed to stdout. Conversely, some parameters are specific to a component and only modify the behavior for messages issued by a given component. A third type of parameters can be used to activate conditional debug code or dump messages or buffers.
### global parameters
| name | type | default | description |
|:---:|:---:|:---:|:----|
| `global_log_level` | `pre-defined string of char` | `info` | Allows printing of messages up to the specified level. Available levels, from lower to higher are `error`,`warn`,`info`,`debug`,`trace` |
| `global_log_online` | `boolean` | 1 (=true) | If false, all console messages are discarded, whatever their level |
| `global_log_options` | `list of pre-defined string of char` | | 3 options can be specified to trigger the information added in the header of the message: `nocolor`, disable color usage in log messages, usefull when redirecting logs to a file, where escape sequences used for color selection can be annoying, `level`, add a one letter level id in the message header (T,D,I,W,E for trace, debug, info, warning, error),`thread`, add the thread name in the message header|
### Component specific parameters
| name | type | default | description |
|:---:|:---:|:---:|:----|
| `<component>_log_level` | `boolean` | global log level, as defined by the `global_log_level ` parameter) |
| `<component>_log_infile` | `boolean` | 0 = false| Triggers the redirection of log messages printed by the specified component in a file. The file path and name is /tmp/<componemt>.[extension] the extension is optional and component dependant, it can be `log `, `dat `, `txt `|
The list of components defined within oai can be retrieved from the [config module](../../../config/config.md) traces, when asking for config module debugging info on the command line:
```bash
./lte-softmodem -O libconfig:<path to config file>:dbgl5
[LIBCONFIG] log_config.global_log_level: "info"
[CONFIG] global_log_online: 1
[CONFIG] log_config.global_log_online set to default value
[LIBCONFIG] log_config: 3/3 parameters successfully set, (1 to default value)
[LIBCONFIG] global_log_options[0]: nocolor
[LIBCONFIG] global_log_options[1]: level
[LIBCONFIG] global_log_options[2]: thread
[CONFIG] log_config 1 options set from command line
[LIBCONFIG] log_config.phy_log_level: "info"
[LIBCONFIG] log_config.mac_log_level: "info"
[CONFIG] log_config.sim_log_level set to default value "info"
[CONFIG] log_config.ocg_log_level set to default value "info"
[CONFIG] log_config.omg_log_level set to default value "info"
[CONFIG] log_config.opt_log_level set to default value "info"
[CONFIG] log_config.otg_log_level set to default value "info"
[CONFIG] log_config.otg_latency_log_level set to default value "info"
[CONFIG] log_config.otg_latency_bg_log_level set to default value "info"
[CONFIG] log_config.otg_gp_log_level set to default value "info"
[CONFIG] log_config.otg_gp_bg_log_level set to default value "info"
[CONFIG] log_config.otg_jitter_log_level set to default value "info"
[LIBCONFIG] log_config.rlc_log_level: "info"
[LIBCONFIG] log_config.pdcp_log_level: "info"
[LIBCONFIG] log_config.rrc_log_level: "info"
[CONFIG] log_config.nas_log_level set to default value "info"
[CONFIG] log_config.perf_log_level set to default value "info"
[CONFIG] log_config.oip_log_level set to default value "info"
[CONFIG] log_config.cli_log_level set to default value "info"
[CONFIG] log_config.msc_log_level set to default value "info"
[CONFIG] log_config.ocm_log_level set to default value "info"
[CONFIG] log_config.udp_log_level set to default value "info"
[CONFIG] log_config.gtpv1u_log_level set to default value "info"
[CONFIG] log_config.comp23?_log_level set to default value "info"
[CONFIG] log_config.s1ap_log_level set to default value "info"
[CONFIG] log_config.sctp_log_level set to default value "info"
[LIBCONFIG] log_config.hw_log_level: "info"
[CONFIG] log_config.osa_log_level set to default value "info"
[CONFIG] log_config.eral_log_level set to default value "info"
[CONFIG] log_config.mral_log_level set to default value "info"
[CONFIG] log_config.enb_app_log_level set to default value "info"
[CONFIG] log_config.flexran_agent_log_level set to default value "info"
[CONFIG] log_config.tmr_log_level set to default value "info"
[CONFIG] log_config.usim_log_level set to default value "info"
[CONFIG] log_config.localize_log_level set to default value "info"
[CONFIG] log_config.x2ap_log_level set to default value "info"
[CONFIG] log_config.loader_log_level set to default value "info"
[CONFIG] log_config.asn_log_level set to default value "info"
[LIBCONFIG] log_config: 38/38 parameters successfully set, (32 to default value)
[CONFIG] log_config 0 options set from command line
[CONFIG] phy_log_infile: 0
[CONFIG] log_config.phy_log_infile set to default value
[CONFIG] mac_log_infile: 0
[CONFIG] log_config.mac_log_infile set to default value
[CONFIG] sim_log_infile: 0
[CONFIG] log_config.sim_log_infile set to default value
[CONFIG] ocg_log_infile: 0
[CONFIG] log_config.ocg_log_infile set to default value
[CONFIG] omg_log_infile: 0
[CONFIG] log_config.omg_log_infile set to default value
[CONFIG] opt_log_infile: 0
[CONFIG] log_config.opt_log_infile set to default value
[CONFIG] otg_log_infile: 0
[CONFIG] log_config.otg_log_infile set to default value
[CONFIG] otg_latency_log_infile: 0
[CONFIG] log_config.otg_latency_log_infile set to default value
[CONFIG] otg_latency_bg_log_infile: 0
[CONFIG] log_config.otg_latency_bg_log_infile set to default value
[CONFIG] otg_gp_log_infile: 0
[CONFIG] log_config.otg_gp_log_infile set to default value
[CONFIG] otg_gp_bg_log_infile: 0
[CONFIG] log_config.otg_gp_bg_log_infile set to default value
[CONFIG] otg_jitter_log_infile: 0
[CONFIG] log_config.otg_jitter_log_infile set to default value
[CONFIG] rlc_log_infile: 0
[CONFIG] log_config.rlc_log_infile set to default value
[CONFIG] pdcp_log_infile: 0
[CONFIG] log_config.pdcp_log_infile set to default value
[CONFIG] rrc_log_infile: 0
[CONFIG] log_config.rrc_log_infile set to default value
[CONFIG] nas_log_infile: 0
[CONFIG] log_config.nas_log_infile set to default value
[CONFIG] perf_log_infile: 0
[CONFIG] log_config.perf_log_infile set to default value
[CONFIG] oip_log_infile: 0
[CONFIG] log_config.oip_log_infile set to default value
[CONFIG] cli_log_infile: 0
[CONFIG] log_config.cli_log_infile set to default value
[CONFIG] msc_log_infile: 0
[CONFIG] log_config.msc_log_infile set to default value
[CONFIG] ocm_log_infile: 0
[CONFIG] log_config.ocm_log_infile set to default value
[CONFIG] udp_log_infile: 0
[CONFIG] log_config.udp_log_infile set to default value
[CONFIG] gtpv1u_log_infile: 0
[CONFIG] log_config.gtpv1u_log_infile set to default value
[CONFIG] comp23?_log_infile: 0
[CONFIG] log_config.comp23?_log_infile set to default value
[CONFIG] s1ap_log_infile: 0
[CONFIG] log_config.s1ap_log_infile set to default value
[CONFIG] sctp_log_infile: 0
[CONFIG] log_config.sctp_log_infile set to default value
[CONFIG] hw_log_infile: 0
[CONFIG] log_config.hw_log_infile set to default value
[CONFIG] osa_log_infile: 0
[CONFIG] log_config.osa_log_infile set to default value
[CONFIG] eral_log_infile: 0
[CONFIG] log_config.eral_log_infile set to default value
[CONFIG] mral_log_infile: 0
[CONFIG] log_config.mral_log_infile set to default value
[CONFIG] enb_app_log_infile: 0
[CONFIG] log_config.enb_app_log_infile set to default value
[CONFIG] flexran_agent_log_infile: 0
[CONFIG] log_config.flexran_agent_log_infile set to default value
[CONFIG] tmr_log_infile: 0
[CONFIG] log_config.tmr_log_infile set to default value
[CONFIG] usim_log_infile: 0
[CONFIG] log_config.usim_log_infile set to default value
[CONFIG] localize_log_infile: 0
[CONFIG] log_config.localize_log_infile set to default value
[CONFIG] x2ap_log_infile: 0
[CONFIG] log_config.x2ap_log_infile set to default value
[CONFIG] loader_log_infile: 0
[CONFIG] log_config.loader_log_infile set to default value
[CONFIG] asn_log_infile: 0
[CONFIG] log_config.asn_log_infile set to default value
[LIBCONFIG] log_config: 38/38 parameters successfully set, (38 to default value)
[CONFIG] log_config 0 options set from command line
[CONFIG] PRACH_debug: 0
[CONFIG] log_config.PRACH_debug set to default value
[CONFIG] RU_debug: 0
[CONFIG] log_config.RU_debug set to default value
[CONFIG] UE_PHYPROC_debug: 0
[CONFIG] log_config.UE_PHYPROC_debug set to default value
[CONFIG] LTEESTIM_debug: 0
[CONFIG] log_config.LTEESTIM_debug set to default value
[CONFIG] DLCELLSPEC_debug: 0
[CONFIG] log_config.DLCELLSPEC_debug set to default value
[CONFIG] ULSCH_debug: 0
[CONFIG] log_config.ULSCH_debug set to default value
[CONFIG] RRC_debug: 0
[CONFIG] log_config.RRC_debug set to default value
[CONFIG] PDCP_debug: 0
[CONFIG] log_config.PDCP_debug set to default value
[CONFIG] DFT_debug: 0
[CONFIG] log_config.DFT_debug set to default value
[CONFIG] ASN1_debug: 0
[CONFIG] log_config.ASN1_debug set to default value
[CONFIG] CTRLSOCKET_debug: 0
[CONFIG] log_config.CTRLSOCKET_debug set to default value
[CONFIG] SECURITY_debug: 0
[CONFIG] log_config.SECURITY_debug set to default value
[CONFIG] NAS_debug: 0
[CONFIG] log_config.NAS_debug set to default value
[CONFIG] RLC_debug: 0
[CONFIG] log_config.RLC_debug set to default value
[CONFIG] UE_TIMING_debug: 0
[CONFIG] log_config.UE_TIMING_debug set to default value
[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value)
[CONFIG] log_config 0 options set from command line
[CONFIG] PRACH_dump: 0
[CONFIG] log_config.PRACH_dump set to default value
[CONFIG] RU_dump: 0
[CONFIG] log_config.RU_dump set to default value
[CONFIG] UE_PHYPROC_dump: 0
[CONFIG] log_config.UE_PHYPROC_dump set to default value
[CONFIG] LTEESTIM_dump: 0
[CONFIG] log_config.LTEESTIM_dump set to default value
[CONFIG] DLCELLSPEC_dump: 0
[CONFIG] log_config.DLCELLSPEC_dump set to default value
[CONFIG] ULSCH_dump: 0
[CONFIG] log_config.ULSCH_dump set to default value
[CONFIG] RRC_dump: 0
[CONFIG] log_config.RRC_dump set to default value
[CONFIG] PDCP_dump: 0
[CONFIG] log_config.PDCP_dump set to default value
[CONFIG] DFT_dump: 0
[CONFIG] log_config.DFT_dump set to default value
[CONFIG] ASN1_dump: 0
[CONFIG] log_config.ASN1_dump set to default value
[CONFIG] CTRLSOCKET_dump: 0
[CONFIG] log_config.CTRLSOCKET_dump set to default value
[CONFIG] SECURITY_dump: 0
[CONFIG] log_config.SECURITY_dump set to default value
[CONFIG] NAS_dump: 0
[CONFIG] log_config.NAS_dump set to default value
[CONFIG] RLC_dump: 0
[CONFIG] log_config.RLC_dump set to default value
[CONFIG] UE_TIMING_dump: 0
[CONFIG] log_config.UE_TIMING_dump set to default value
[LIBCONFIG] log_config: 15/15 parameters successfully set, (15 to default value)
[CONFIG] log_config 0 options set from command line
log init done
```
It can also be retrieved when using the telnet server, as explained [below](### Using the telnet server to configure the logging facility)
### parameters to activate conditional code
| name | type | default | description |
|:---:|:---:|:---:|:----|
| `<flag>_debug` | `boolean` | 0 = false | Triggers the activation of conditional code identified by the specified flag.
| `<flag>_dump` | `boolean` | 0 = false| Triggers buffer dump, on the console in text form or in a file in matlab format, depending on the developper choice and forcasted usage|
### Using the configuration file to configure the logging facility
The following example sets all components log level to info, exept for hw,phy,mac,rlc,pdcp,rrc which log levels are set to error or warning.
```bash
log_config :
{
global_log_level ="info";
hw_log_level ="error";
phy_log_level ="error";
mac_log_level ="warn";
rlc_log_level ="error"
pdcp_log_level ="error";
rrc_log_level ="error";
};
```
### Using the command line to configure the logging facility
Command line parameter values supersedes values specified in the configuration file.