Some tweaks to the logging system.

This commit is contained in:
default 2023-09-27 13:19:46 +02:00
parent eb8430d461
commit 9cce2ee119
2 changed files with 22 additions and 22 deletions

26
snac.c
View file

@ -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);
}

18
snac.h
View file

@ -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);