From 9cce2ee1195cb08e2c27be7c9047e78be57425a3 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 27 Sep 2023 13:19:46 +0200 Subject: [PATCH] Some tweaks to the logging system. --- snac.c | 26 ++++++++++++-------------- snac.h | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/snac.c b/snac.c index e396135..683ff40 100644 --- a/snac.c +++ b/snac.c @@ -90,7 +90,7 @@ int validate_uid(const char *uid) } -void srv_debug(int level, xs_str *str) +void srv_log(xs_str *str) /* logs a debug message */ { if (xs_str_in(str, srv_basedir) != -1) { @@ -98,25 +98,23 @@ void srv_debug(int level, xs_str *str) str = xs_replace_i(str, srv_basedir, "~"); } - if (dbglevel >= level) { - xs *tm = xs_str_localtime(0, "%H:%M:%S"); - fprintf(stderr, "%s %s\n", tm, str); + xs *tm = xs_str_localtime(0, "%H:%M:%S"); + fprintf(stderr, "%s %s\n", tm, str); - /* if the ~/log/ folder exists, also write to a file there */ - xs *dt = xs_str_localtime(0, "%Y-%m-%d"); - xs *lf = xs_fmt("%s/log/%s.log", srv_basedir, dt); - FILE *f; - if ((f = fopen(lf, "a")) != NULL) { - fprintf(f, "%s %s\n", tm, str); - fclose(f); - } + /* if the ~/log/ folder exists, also write to a file there */ + xs *dt = xs_str_localtime(0, "%Y-%m-%d"); + xs *lf = xs_fmt("%s/log/%s.log", srv_basedir, dt); + FILE *f; + if ((f = fopen(lf, "a")) != NULL) { + fprintf(f, "%s %s\n", tm, str); + fclose(f); } xs_free(str); } -void snac_debug(snac *snac, int level, xs_str *str) +void snac_log(snac *snac, xs_str *str) /* prints a user debugging information */ { xs *o_str = str; @@ -127,7 +125,7 @@ void snac_debug(snac *snac, int level, xs_str *str) msg = xs_replace_i(msg, snac->basedir, "~"); } - srv_debug(level, msg); + srv_log(msg); } diff --git a/snac.h b/snac.h index 9b7f37a..9800bb5 100644 --- a/snac.h +++ b/snac.h @@ -27,11 +27,9 @@ int valid_status(int status); xs_str *tid(int offset); double ftime(void); -void srv_debug(int level, xs_str *str); -#define srv_log(str) srv_debug(0, str) - -int srv_open(char *basedir, int auto_upgrade); -void srv_free(void); +void srv_log(xs_str *str); +#define srv_debug(level, str) do { if (dbglevel >= (level)) \ + { srv_log((str)); } } while (0) typedef struct _snac { xs_str *uid; /* uid */ @@ -43,14 +41,18 @@ typedef struct _snac { xs_str *md5; /* actor url md5 */ } snac; +void snac_log(snac *user, xs_str *str); +#define snac_debug(user, level, str) do { if (dbglevel >= (level)) \ + { snac_log((user), (str)); } } while (0) + +int srv_open(char *basedir, int auto_upgrade); +void srv_free(void); + int user_open(snac *snac, const char *uid); void user_free(snac *snac); xs_list *user_list(void); int user_open_by_md5(snac *snac, const char *md5); -void snac_debug(snac *snac, int level, xs_str *str); -#define snac_log(snac, str) snac_debug(snac, 0, str) - int validate_uid(const char *uid); xs_str *hash_password(const char *uid, const char *passwd, const char *nonce);