Skip to content

Commit

Permalink
contrib: sync slog
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <hexian000@outlook.com>
  • Loading branch information
hexian000 committed Jan 28, 2024
1 parent e8d94ed commit c5aa27e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions contrib/csnippets/utils/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <ctype.h>
#include <inttypes.h>
#include <stddef.h>
#include <stdio.h>

void print_txt(FILE *f, const char *indent, const void *data, size_t n)
{
Expand Down
6 changes: 3 additions & 3 deletions contrib/csnippets/utils/slog.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FILE *slog_file = NULL;
static int slog_output_type = SLOG_OUTPUT_DISCARD;

static const unsigned char slog_level_char[] = {
'-', 'F', 'E', 'W', 'N', 'I', 'D', 'V',
'-', 'F', 'E', 'W', 'I', 'I', 'D', 'V', 'V',
};

static _Thread_local struct {
Expand Down Expand Up @@ -125,8 +125,8 @@ static void slog_write_syslog(
va_list args)
{
static const int slog_level_map[] = {
LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
LOG_NOTICE, LOG_INFO, LOG_DEBUG, LOG_DEBUG,
LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE,
LOG_INFO, LOG_DEBUG, LOG_DEBUG, LOG_DEBUG,
};

const char *log_filename = strrchr(path, PATH_SEPARATOR);
Expand Down
13 changes: 12 additions & 1 deletion contrib/csnippets/utils/slog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum {
LOG_LEVEL_INFO,
LOG_LEVEL_DEBUG,
LOG_LEVEL_VERBOSE,
LOG_LEVEL_VERYVERBOSE,
};
extern int slog_level;
extern FILE *slog_file;
Expand Down Expand Up @@ -67,7 +68,7 @@ void slog_write(int level, const char *path, int line, const char *format, ...);
} while (0)
#define LOGW(message) LOGW_F("%s", message)

/* Notice: Important status changes. */
/* Notice: Important status changes. The prefix is 'I'. */
#define LOGN_F(format, ...) \
do { \
if (!LOGLEVEL(NOTICE)) { \
Expand Down Expand Up @@ -107,4 +108,14 @@ void slog_write(int level, const char *path, int line, const char *format, ...);
} while (0)
#define LOGV(message) LOGV_F("%s", message)

/* VeryVerbose: More details that may significantly impact performance. The prefix is 'V'. */
#define LOGVV_F(format, ...) \
do { \
if (!LOGLEVEL(VERYVERBOSE)) { \
break; \
} \
LOG_F(VERYVERBOSE, format, __VA_ARGS__); \
} while (0)
#define LOGVV(message) LOGVV_F("%s", message)

#endif /* UTILS_SLOG_H */

0 comments on commit c5aa27e

Please sign in to comment.