log: Remove libseat prefixes
This commit is contained in:
parent
563a932659
commit
493cc2a97d
5 changed files with 43 additions and 47 deletions
24
common/log.c
24
common/log.c
|
@ -10,22 +10,22 @@
|
|||
|
||||
const long NSEC_PER_SEC = 1000000000;
|
||||
|
||||
static enum libseat_log_level current_log_level;
|
||||
static enum log_level current_log_level;
|
||||
static struct timespec start_time = {-1, -1};
|
||||
static bool colored = false;
|
||||
|
||||
static const char *verbosity_colors[] = {
|
||||
[LIBSEAT_SILENT] = "",
|
||||
[LIBSEAT_ERROR] = "\x1B[1;31m",
|
||||
[LIBSEAT_INFO] = "\x1B[1;34m",
|
||||
[LIBSEAT_DEBUG] = "\x1B[1;90m",
|
||||
[LOGLEVEL_SILENT] = "",
|
||||
[LOGLEVEL_ERROR] = "\x1B[1;31m",
|
||||
[LOGLEVEL_INFO] = "\x1B[1;34m",
|
||||
[LOGLEVEL_DEBUG] = "\x1B[1;90m",
|
||||
};
|
||||
|
||||
static const char *verbosity_headers[] = {
|
||||
[LIBSEAT_SILENT] = "",
|
||||
[LIBSEAT_ERROR] = "[ERROR]",
|
||||
[LIBSEAT_INFO] = "[INFO]",
|
||||
[LIBSEAT_DEBUG] = "[DEBUG]",
|
||||
[LOGLEVEL_SILENT] = "",
|
||||
[LOGLEVEL_ERROR] = "[ERROR]",
|
||||
[LOGLEVEL_INFO] = "[INFO]",
|
||||
[LOGLEVEL_DEBUG] = "[DEBUG]",
|
||||
};
|
||||
|
||||
static void timespec_sub(struct timespec *r, const struct timespec *a, const struct timespec *b) {
|
||||
|
@ -37,7 +37,7 @@ static void timespec_sub(struct timespec *r, const struct timespec *a, const str
|
|||
}
|
||||
}
|
||||
|
||||
void libseat_log_init(enum libseat_log_level level) {
|
||||
void log_init(enum log_level level) {
|
||||
if (start_time.tv_sec >= 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ void libseat_log_init(enum libseat_log_level level) {
|
|||
colored = isatty(STDERR_FILENO);
|
||||
}
|
||||
|
||||
void _libseat_logf(enum libseat_log_level level, const char *fmt, ...) {
|
||||
void _logf(enum log_level level, const char *fmt, ...) {
|
||||
int stored_errno = errno;
|
||||
va_list args;
|
||||
if (level > current_log_level) {
|
||||
|
@ -56,7 +56,7 @@ void _libseat_logf(enum libseat_log_level level, const char *fmt, ...) {
|
|||
struct timespec ts = {0};
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
timespec_sub(&ts, &ts, &start_time);
|
||||
unsigned c = (level < LIBSEAT_LOG_LEVEL_LAST) ? level : LIBSEAT_LOG_LEVEL_LAST - 1;
|
||||
unsigned c = (level < LOGLEVEL_LAST) ? level : LOGLEVEL_LAST - 1;
|
||||
|
||||
const char *prefix, *postfix;
|
||||
|
||||
|
|
|
@ -9,47 +9,43 @@
|
|||
#define ATTRIB_PRINTF(start, end)
|
||||
#endif
|
||||
|
||||
#ifdef LIBSEAT_REL_SRC_DIR
|
||||
#define _LIBSEAT_FILENAME ((const char *)__FILE__ + sizeof(LIBSEAT_REL_SRC_DIR) - 1)
|
||||
#ifdef REL_SRC_DIR
|
||||
#define __FILENAME__ ((const char *)__FILE__ + sizeof(REL_SRC_DIR) - 1)
|
||||
#else
|
||||
#define _LIBSEAT_FILENAME __FILE__
|
||||
#define __FILENAME__ __FILE__
|
||||
#endif
|
||||
|
||||
#define log_infof(fmt, ...) \
|
||||
_libseat_logf(LIBSEAT_INFO, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
|
||||
__VA_ARGS__)
|
||||
_logf(LOGLEVEL_INFO, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
#define log_info(str) \
|
||||
_libseat_logf(LIBSEAT_INFO, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
|
||||
#define log_info(str) _logf(LOGLEVEL_INFO, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str)
|
||||
|
||||
#define log_errorf(fmt, ...) \
|
||||
_libseat_logf(LIBSEAT_ERROR, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
|
||||
__VA_ARGS__)
|
||||
_logf(LOGLEVEL_ERROR, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
#define log_error(str) \
|
||||
_libseat_logf(LIBSEAT_ERROR, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
|
||||
_logf(LOGLEVEL_ERROR, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define log_debugf(fmt, ...) \
|
||||
_libseat_logf(LIBSEAT_DEBUG, "[%s:%d] %s: " fmt, _LIBSEAT_FILENAME, __LINE__, __func__, \
|
||||
__VA_ARGS__)
|
||||
_logf(LOGLEVEL_DEBUG, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
||||
#define log_debug(str) \
|
||||
_libseat_logf(LIBSEAT_DEBUG, "[%s:%d] %s: %s", _LIBSEAT_FILENAME, __LINE__, __func__, str)
|
||||
_logf(LOGLEVEL_DEBUG, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str)
|
||||
#else
|
||||
#define log_debugf(fmt, ...)
|
||||
#define log_debug(str)
|
||||
#endif
|
||||
|
||||
enum libseat_log_level {
|
||||
LIBSEAT_SILENT = 0,
|
||||
LIBSEAT_ERROR = 1,
|
||||
LIBSEAT_INFO = 2,
|
||||
LIBSEAT_DEBUG = 3,
|
||||
LIBSEAT_LOG_LEVEL_LAST,
|
||||
enum log_level {
|
||||
LOGLEVEL_SILENT = 0,
|
||||
LOGLEVEL_ERROR = 1,
|
||||
LOGLEVEL_INFO = 2,
|
||||
LOGLEVEL_DEBUG = 3,
|
||||
LOGLEVEL_LAST,
|
||||
};
|
||||
|
||||
void libseat_log_init(enum libseat_log_level level);
|
||||
void _libseat_logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);
|
||||
void log_init(enum log_level level);
|
||||
void _logf(enum log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,17 +38,17 @@ struct libseat *libseat_open_seat(struct libseat_seat_listener *listener, void *
|
|||
}
|
||||
|
||||
char *loglevel = getenv("LIBSEAT_LOGLEVEL");
|
||||
enum libseat_log_level level = LIBSEAT_SILENT;
|
||||
enum log_level level = LOGLEVEL_SILENT;
|
||||
if (loglevel != NULL) {
|
||||
if (strcmp(loglevel, "silent") == 0) {
|
||||
level = LIBSEAT_SILENT;
|
||||
level = LOGLEVEL_SILENT;
|
||||
} else if (strcmp(loglevel, "info") == 0) {
|
||||
level = LIBSEAT_INFO;
|
||||
level = LOGLEVEL_INFO;
|
||||
} else if (strcmp(loglevel, "debug") == 0) {
|
||||
level = LIBSEAT_DEBUG;
|
||||
level = LOGLEVEL_DEBUG;
|
||||
}
|
||||
}
|
||||
libseat_log_init(level);
|
||||
log_init(level);
|
||||
|
||||
char *backend_type = getenv("LIBSEAT_BACKEND");
|
||||
struct libseat *backend = NULL;
|
||||
|
|
|
@ -64,7 +64,7 @@ endif
|
|||
|
||||
|
||||
add_project_arguments(
|
||||
'-DLIBSEAT_REL_SRC_DIR="@0@"'.format(join_paths(relative_dir_parts) + '/'),
|
||||
'-DREL_SRC_DIR="@0@"'.format(join_paths(relative_dir_parts) + '/'),
|
||||
language: 'c',
|
||||
)
|
||||
|
||||
|
|
|
@ -18,17 +18,17 @@ int main(int argc, char *argv[]) {
|
|||
(void)argv;
|
||||
|
||||
char *loglevel = getenv("SEATD_LOGLEVEL");
|
||||
enum libseat_log_level level = LIBSEAT_ERROR;
|
||||
enum log_level level = LOGLEVEL_ERROR;
|
||||
if (loglevel != NULL) {
|
||||
if (strcmp(loglevel, "silent") == 0) {
|
||||
level = LIBSEAT_SILENT;
|
||||
level = LOGLEVEL_SILENT;
|
||||
} else if (strcmp(loglevel, "info") == 0) {
|
||||
level = LIBSEAT_INFO;
|
||||
level = LOGLEVEL_INFO;
|
||||
} else if (strcmp(loglevel, "debug") == 0) {
|
||||
level = LIBSEAT_DEBUG;
|
||||
level = LOGLEVEL_DEBUG;
|
||||
}
|
||||
}
|
||||
libseat_log_init(level);
|
||||
log_init(level);
|
||||
|
||||
struct server server = {0};
|
||||
if (server_init(&server) == -1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue