Commit 9771036e authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/logImp' into integration_2022_wk42b

parents 627b8d92 b416d26a
......@@ -7,9 +7,20 @@ All logging facility parameters are defined in the log_config section. Some para
| 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`,`analysis`,`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` | | 5 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,A,W,E for trace, debug, info, analysis, warning, error),`thread`, add the thread name in the message header, `thread_id`, adds the thread ID in the message header, `function`, adds the function name, `line_num`, adds the line number, `time` adds the time since process starts|
| `global_log_level` | `string` | `info` | Allows printing of messages up to the specified level. Available levels, from lower to higher are `error`, `warn`, `analysis`, `info`, `debug`, `trace` |
| `global_log_online` | `bool` | 1 (=`true`) | If `false`, all console messages are discarded, whatever their level |
| `global_log_options` | `string` | _empty_ | _see following list_ |
The following options can be specified to trigger the information added in the header of the message (`global_log_options`):
- `nocolor`: disable color usage in log messages, useful 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`,`A`,`W`,`E` for trace, debug, info, analysis, warning, error)
- `thread`: add the thread name
- `thread_id`: add the thread ID
- `function`: add the function name
- `line_num`: adds the (source code) line number
- `time`: add the time since process started
- `wall_clock`: add the system-wide clock time that measures real (i.e., wall-clock) time (`time` and `wall_clock` are mutually exclusive)
### Component specific parameters
| name | type | default | description |
......
......@@ -84,10 +84,10 @@ mapping log_options[] = {
{"function", FLAG_FUNCT},
{"time", FLAG_TIME},
{"thread_id", FLAG_THREAD_ID},
{"wall_clock", FLAG_REAL_TIME},
{NULL,-1}
};
mapping log_maskmap[] = LOG_MASKMAP_INIT;
char *log_level_highlight_start[] = {LOG_RED, LOG_ORANGE, LOG_GREEN, "", LOG_BLUE, LOG_CYBL}; /*!< \brief Optional start-format strings for highlighting */
......@@ -512,6 +512,9 @@ int logInit (void)
memset(&(g_log->log_component[i]),0,sizeof(log_component_t));
}
AssertFatal(!((g_log->flag & FLAG_TIME) && (g_log->flag & FLAG_REAL_TIME)),
"Invalid log options: time and wall_clock both set but are mutually exclusive\n");
g_log->flag = g_log->flag | FLAG_INITIALIZED;
printf("log init done\n");
return 0;
......@@ -554,10 +557,12 @@ static inline int log_header(log_component_t *c,
else
l[0] = 0;
// output time information
char timeString[32];
if ( flag & FLAG_TIME ) {
if ((flag & FLAG_TIME) || (flag & FLAG_REAL_TIME)) {
struct timespec t;
if (clock_gettime(CLOCK_MONOTONIC, &t) == -1)
const clockid_t clock = flag & FLAG_TIME ? CLOCK_MONOTONIC : CLOCK_REALTIME;
if (clock_gettime(clock, &t) == -1)
abort();
snprintf(timeString, sizeof(timeString), "%lu.%06lu ",
t.tv_sec,
......
......@@ -129,6 +129,7 @@ extern "C" {
#define FLAG_FILE_LINE 0x0040
#define FLAG_TIME 0x0100
#define FLAG_THREAD_ID 0x0200
#define FLAG_REAL_TIME 0x0400
#define FLAG_INITIALIZED 0x8000
#define SET_LOG_OPTION(O) g_log->flag = (g_log->flag | O)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment