Browse Source

Introduce libseat_set_log_level

The default level is SILENT. log_init no longer takes an initial log
level (so that calls to libseat_set_log_level prior to log_init work
correctly).
suites/experimental
Simon Ser 3 years ago
committed by Kenny Levinsen
parent
commit
07ceeeebe0
  1. 9
      common/log.c
  2. 8
      include/libseat.h
  3. 2
      include/log.h
  4. 2
      libseat/libseat.c
  5. 3
      seatd/seatd.c

9
common/log.c

@ -12,7 +12,7 @@ const long NSEC_PER_SEC = 1000000000;
static void log_stderr(enum libseat_log_level level, const char *fmt, va_list args);
static enum libseat_log_level current_log_level;
static enum libseat_log_level current_log_level = LIBSEAT_LOG_LEVEL_SILENT;
static libseat_log_func current_log_handler = log_stderr;
static struct timespec start_time = {-1, -1};
static bool colored = false;
@ -64,12 +64,11 @@ static void log_stderr(enum libseat_log_level level, const char *fmt, va_list ar
fprintf(stderr, "%s", postfix);
}
void log_init(enum libseat_log_level level) {
void log_init(void) {
if (start_time.tv_sec >= 0) {
return;
}
clock_gettime(CLOCK_MONOTONIC, &start_time);
current_log_level = level;
colored = isatty(STDERR_FILENO);
}
@ -93,3 +92,7 @@ void libseat_set_log_handler(libseat_log_func handler) {
}
current_log_handler = handler;
}
void libseat_set_log_level(enum libseat_log_level level) {
current_log_level = level;
}

8
include/libseat.h

@ -160,4 +160,12 @@ typedef void (*libseat_log_func)(enum libseat_log_level level, const char *forma
*/
void libseat_set_log_handler(libseat_log_func handler);
/*
* Sets the libseat log level.
*
* Only log messages whose level is lower or equal than the current log level
* will be processed, others will be ignored.
*/
void libseat_set_log_level(enum libseat_log_level level);
#endif

2
include/log.h

@ -43,7 +43,7 @@
#define log_debug(str)
#endif
void log_init(enum libseat_log_level level);
void log_init(void);
void _logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);
#endif

2
libseat/libseat.c

@ -37,7 +37,7 @@ struct libseat *libseat_open_seat(struct libseat_seat_listener *listener, void *
return NULL;
}
log_init(LIBSEAT_LOG_LEVEL_SILENT);
log_init();
char *backend_type = getenv("LIBSEAT_BACKEND");
struct libseat *backend = NULL;

3
seatd/seatd.c

@ -64,7 +64,8 @@ int main(int argc, char *argv[]) {
level = LIBSEAT_LOG_LEVEL_DEBUG;
}
}
log_init(level);
log_init();
libseat_set_log_level(level);
const char *usage = "Usage: seatd [options]\n"
"\n"

Loading…
Cancel
Save