Commit 29bf98cf authored by Vijay Chadachan's avatar Vijay Chadachan Committed by Robert Schmidt

Add wall_clock option to the log subsystem to get absolute time stamps

parent 3bc86d69
......@@ -9,7 +9,7 @@ All logging facility parameters are defined in the log_config section. Some para
|:---:|:---:|:---:|:----|
| `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_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, `wall_clock` adds the system-wide clock time that measures real (i.e., wall-clock) time |
### 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