The ROme OpTimistic Simulator  3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
log.c
Go to the documentation of this file.
1 
11 #include <log/log.h>
12 
13 #include <arch/io.h>
14 
15 #include <stdarg.h>
16 #include <stdio.h>
17 
22 
24 static const struct {
25  const char *name;
26  const char *color;
27 } levels[] = {
28  [LOG_TRACE] = {.name = "TRACE", .color = "\x1b[94m"},
29  [LOG_DEBUG] = {.name = "DEBUG", .color = "\x1b[36m"},
30  [LOG_INFO] = {.name = "INFO", .color = "\x1b[32m"},
31  [LOG_WARN] = {.name = "WARN", .color = "\x1b[33m"},
32  [LOG_ERROR] = {.name = "ERROR", .color = "\x1b[31m"},
33  [LOG_FATAL] = {.name = "FATAL", .color = "\x1b[35m"}
34 };
35 
44 void _log_log(int level, const char *file, unsigned line, const char *fmt, ...)
45 {
46  va_list args;
47 
48  char time_string[IO_TIME_BUFFER_LEN];
49  io_local_time_get(time_string);
50 
51  if(log_colored) {
52  fprintf(
53  stderr,
54  "%s %s%-5s\x1b[0m \x1b[90m%s:%u:\x1b[0m ",
55  time_string,
56  levels[level].color,
57  levels[level].name,
58  file,
59  line
60  );
61  } else {
62  fprintf(
63  stderr,
64  "%s %-5s %s:%u: ",
65  time_string,
66  levels[level].name,
67  file,
68  line
69  );
70  }
71 
72  va_start(args, fmt);
73  vfprintf(stderr, fmt, args);
74  va_end(args);
75  fprintf(stderr, "\n");
76  fflush(stderr);
77 }
78 
82 void log_logo_print(void)
83 {
84  if(log_colored) {
85  fprintf(stderr, "\x1b[94m __ \x1b[90m __ _______ \x1b[94m _ \x1b[90m \n");
86  fprintf(stderr, "\x1b[94m /__)\x1b[90m/ ) / ) / __ \x1b[94m ( `\x1b[90m . ___ \n");
87  fprintf(stderr, "\x1b[94m / \\ \x1b[90m(__/ (__/ ( \x1b[94m._)\x1b[90m / / / )\n");
88  fprintf(stderr, "\x1b[0m\n");
89  } else {
90  fprintf(stderr, " __ __ _______ _ \n");
91  fprintf(stderr, " /__) / ) / ) / __ ( ` . ___ \n");
92  fprintf(stderr, "/ \\ (__/ (__/ ( ._) / / / )\n");
93  fprintf(stderr, "\n");
94  }
95 }
LOG_DEBUG
#define LOG_DEBUG
The logging level reserved to useful debug messages.
Definition: log.h:27
log_level
int log_level
The minimum log level of the messages to display.
Definition: log.c:19
LOG_ERROR
#define LOG_ERROR
The logging level reserved to unexpected, problematic conditions.
Definition: log.h:33
LOG_LEVEL
#define LOG_LEVEL
The minimum logging level supported at compile time.
Definition: log.h:18
LOG_TRACE
#define LOG_TRACE
The logging level reserved to very low priority messages.
Definition: log.h:25
_log_log
void _log_log(int level, const char *file, unsigned line, const char *fmt,...)
Logs a message. For internal use: log_log() should be used instead.
Definition: log.c:44
log_logo_print
void log_logo_print(void)
Prints a fancy ROOT-Sim logo on the terminal.
Definition: log.c:82
log_colored
bool log_colored
If set, uses color codes to color the log outputs.
Definition: log.c:21
LOG_FATAL
#define LOG_FATAL
The logging level reserved to unexpected, fatal conditions.
Definition: log.h:35
LOG_INFO
#define LOG_INFO
The logging level reserved to useful runtime messages.
Definition: log.h:29
log.h
Logging library.
levels
static const struct @3 levels[]
The textual representations and the color codes of the logging levels.
LOG_WARN
#define LOG_WARN
The logging level reserved to unexpected, non deal breaking conditions.
Definition: log.h:31
io.h
Generic input-output facilities.