Use thread-safe localtime and tweak loglevel

This commit is contained in:
2016-08-09 15:02:16 +03:00
parent 3fecfdbbc4
commit 0c4a57faed
3 changed files with 8 additions and 6 deletions

View File

@@ -273,7 +273,7 @@ static int test_conf_syntax()
failed = 1;*/
} else if (!strcmp(buf, "rmps.loglevel")) {
if (strlen(tmp + 1) == 1 && (tmp[1] > '0' && tmp[1] < '5'))
conf.rmps.loglevel = tmp[1];
conf.rmps.loglevel = tmp[1] - '0';
else
failed = 1;
} else if (!strcmp(buf, "rmps.certfile")) {

View File

@@ -1,6 +1,8 @@
#ifndef CONFPARSER_H
#define CONFPARSER_H
#include "log_trace.h"
#define MAXPATHSIZE 256
#define HOSTNAMESIZE 128
#define CFGLINESIZE 300
@@ -16,7 +18,7 @@ struct conf_rmps {
char bind_on_port[6];
char logfile[MAXPATHSIZE];
char errlog[MAXPATHSIZE];
char loglevel;
LOG_LEVEL loglevel;
char pidfile[MAXPATHSIZE];
char certfile[MAXPATHSIZE];
char keyfile[MAXPATHSIZE];

View File

@@ -33,21 +33,21 @@ static void set_fpts(void)
void log_trace(LOG_LEVEL lvl, char *fmt, ... )
{
LOG_LEVEL cur_lvl = conf.rmps.loglevel - '0';
char fmt_with_pfx[1024];
pthread_once(&init_once, set_fpts);
if (conf.isvalid)
pthread_once(&once, open_logs);
if (lvl <= cur_lvl) {
if (lvl <= conf.rmps.loglevel) {
va_list list;
FILE *fp;
static const char *prefixes[] = {
"ERROR", "WARNING", "INFO", "VERBOSE"
};
time_t t = time(NULL);
struct tm tm = *localtime(&t);
if (lvl == ERROR || lvl == WARNING)
struct tm tm;
localtime_r(&t, &tm);
if (conf.rmps.loglevel == ERROR || conf.rmps.loglevel == WARNING)
fp = fderr;
else
fp = fdout;