diff options
| -rw-r--r-- | common/log.c | 24 | ||||
| -rw-r--r-- | include/log.h | 38 | ||||
| -rw-r--r-- | libseat/libseat.c | 8 | ||||
| -rw-r--r-- | seatd/seatd.c | 8 | 
4 files changed, 41 insertions, 37 deletions
| diff --git a/common/log.c b/common/log.c index 902e870..7e5e8d4 100644 --- a/common/log.c +++ b/common/log.c @@ -10,22 +10,22 @@  const long NSEC_PER_SEC = 1000000000; -static enum log_level current_log_level; +static enum libseat_log_level current_log_level;  static struct timespec start_time = {-1, -1};  static bool colored = false;  static const char *verbosity_colors[] = { -	[LOGLEVEL_SILENT] = "", -	[LOGLEVEL_ERROR] = "\x1B[1;31m", -	[LOGLEVEL_INFO] = "\x1B[1;34m", -	[LOGLEVEL_DEBUG] = "\x1B[1;90m", +	[LIBSEAT_LOG_LEVEL_SILENT] = "", +	[LIBSEAT_LOG_LEVEL_ERROR] = "\x1B[1;31m", +	[LIBSEAT_LOG_LEVEL_INFO] = "\x1B[1;34m", +	[LIBSEAT_LOG_LEVEL_DEBUG] = "\x1B[1;90m",  };  static const char *verbosity_headers[] = { -	[LOGLEVEL_SILENT] = "", -	[LOGLEVEL_ERROR] = "[ERROR]", -	[LOGLEVEL_INFO] = "[INFO]", -	[LOGLEVEL_DEBUG] = "[DEBUG]", +	[LIBSEAT_LOG_LEVEL_SILENT] = "", +	[LIBSEAT_LOG_LEVEL_ERROR] = "[ERROR]", +	[LIBSEAT_LOG_LEVEL_INFO] = "[INFO]", +	[LIBSEAT_LOG_LEVEL_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 log_init(enum log_level level) { +void log_init(enum libseat_log_level level) {  	if (start_time.tv_sec >= 0) {  		return;  	} @@ -46,7 +46,7 @@ void log_init(enum log_level level) {  	colored = isatty(STDERR_FILENO);  } -void _logf(enum log_level level, const char *fmt, ...) { +void _logf(enum libseat_log_level level, const char *fmt, ...) {  	int stored_errno = errno;  	va_list args;  	if (level > current_log_level) { @@ -56,7 +56,7 @@ void _logf(enum log_level level, const char *fmt, ...) {  	struct timespec ts = {0};  	clock_gettime(CLOCK_MONOTONIC, &ts);  	timespec_sub(&ts, &ts, &start_time); -	unsigned c = (level < LOGLEVEL_LAST) ? level : LOGLEVEL_LAST - 1; +	unsigned c = (level < LIBSEAT_LOG_LEVEL_LAST) ? level : LIBSEAT_LOG_LEVEL_LAST - 1;  	const char *prefix, *postfix; diff --git a/include/log.h b/include/log.h index 80b9864..ff354f8 100644 --- a/include/log.h +++ b/include/log.h @@ -15,37 +15,41 @@  #define __FILENAME__ __FILE__  #endif -#define log_infof(fmt, ...) \ -	_logf(LOGLEVEL_INFO, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__) +#define log_infof(fmt, ...)                                                                 \ +	_logf(LIBSEAT_LOG_LEVEL_INFO, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, \ +	      __VA_ARGS__) -#define log_info(str) _logf(LOGLEVEL_INFO, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str) +#define log_info(str) \ +	_logf(LIBSEAT_LOG_LEVEL_INFO, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str) -#define log_errorf(fmt, ...) \ -	_logf(LOGLEVEL_ERROR, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__) +#define log_errorf(fmt, ...)                                                                 \ +	_logf(LIBSEAT_LOG_LEVEL_ERROR, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, \ +	      __VA_ARGS__)  #define log_error(str) \ -	_logf(LOGLEVEL_ERROR, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str) +	_logf(LIBSEAT_LOG_LEVEL_ERROR, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str)  #ifdef DEBUG -#define log_debugf(fmt, ...) \ -	_logf(LOGLEVEL_DEBUG, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, __VA_ARGS__) +#define log_debugf(fmt, ...)                                                                 \ +	_logf(LIBSEAT_LOG_LEVEL_DEBUG, "[%s:%d] %s: " fmt, __FILENAME__, __LINE__, __func__, \ +	      __VA_ARGS__)  #define log_debug(str) \ -	_logf(LOGLEVEL_DEBUG, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str) +	_logf(LIBSEAT_LOG_LEVEL_DEBUG, "[%s:%d] %s: %s", __FILENAME__, __LINE__, __func__, str)  #else  #define log_debugf(fmt, ...)  #define log_debug(str)  #endif -enum log_level { -	LOGLEVEL_SILENT = 0, -	LOGLEVEL_ERROR = 1, -	LOGLEVEL_INFO = 2, -	LOGLEVEL_DEBUG = 3, -	LOGLEVEL_LAST, +enum libseat_log_level { +	LIBSEAT_LOG_LEVEL_SILENT = 0, +	LIBSEAT_LOG_LEVEL_ERROR = 1, +	LIBSEAT_LOG_LEVEL_INFO = 2, +	LIBSEAT_LOG_LEVEL_DEBUG = 3, +	LIBSEAT_LOG_LEVEL_LAST,  }; -void log_init(enum log_level level); -void _logf(enum log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3); +void log_init(enum libseat_log_level level); +void _logf(enum libseat_log_level level, const char *fmt, ...) ATTRIB_PRINTF(2, 3);  #endif diff --git a/libseat/libseat.c b/libseat/libseat.c index 121a3b0..1b6a99d 100644 --- a/libseat/libseat.c +++ b/libseat/libseat.c @@ -38,14 +38,14 @@ struct libseat *libseat_open_seat(struct libseat_seat_listener *listener, void *  	}  	char *loglevel = getenv("LIBSEAT_LOGLEVEL"); -	enum log_level level = LOGLEVEL_SILENT; +	enum libseat_log_level level = LIBSEAT_LOG_LEVEL_SILENT;  	if (loglevel != NULL) {  		if (strcmp(loglevel, "silent") == 0) { -			level = LOGLEVEL_SILENT; +			level = LIBSEAT_LOG_LEVEL_SILENT;  		} else if (strcmp(loglevel, "info") == 0) { -			level = LOGLEVEL_INFO; +			level = LIBSEAT_LOG_LEVEL_INFO;  		} else if (strcmp(loglevel, "debug") == 0) { -			level = LOGLEVEL_DEBUG; +			level = LIBSEAT_LOG_LEVEL_DEBUG;  		}  	}  	log_init(level); diff --git a/seatd/seatd.c b/seatd/seatd.c index ada6e75..71d6b2f 100644 --- a/seatd/seatd.c +++ b/seatd/seatd.c @@ -54,14 +54,14 @@ static int open_socket(char *path, int uid, int gid) {  int main(int argc, char *argv[]) {  	char *loglevel = getenv("SEATD_LOGLEVEL"); -	enum log_level level = LOGLEVEL_ERROR; +	enum libseat_log_level level = LIBSEAT_LOG_LEVEL_ERROR;  	if (loglevel != NULL) {  		if (strcmp(loglevel, "silent") == 0) { -			level = LOGLEVEL_SILENT; +			level = LIBSEAT_LOG_LEVEL_SILENT;  		} else if (strcmp(loglevel, "info") == 0) { -			level = LOGLEVEL_INFO; +			level = LIBSEAT_LOG_LEVEL_INFO;  		} else if (strcmp(loglevel, "debug") == 0) { -			level = LOGLEVEL_DEBUG; +			level = LIBSEAT_LOG_LEVEL_DEBUG;  		}  	}  	log_init(level); | 
