Use thread-safe localtime and tweak loglevel
This commit is contained in:
@@ -273,7 +273,7 @@ static int test_conf_syntax()
|
|||||||
failed = 1;*/
|
failed = 1;*/
|
||||||
} else if (!strcmp(buf, "rmps.loglevel")) {
|
} else if (!strcmp(buf, "rmps.loglevel")) {
|
||||||
if (strlen(tmp + 1) == 1 && (tmp[1] > '0' && tmp[1] < '5'))
|
if (strlen(tmp + 1) == 1 && (tmp[1] > '0' && tmp[1] < '5'))
|
||||||
conf.rmps.loglevel = tmp[1];
|
conf.rmps.loglevel = tmp[1] - '0';
|
||||||
else
|
else
|
||||||
failed = 1;
|
failed = 1;
|
||||||
} else if (!strcmp(buf, "rmps.certfile")) {
|
} else if (!strcmp(buf, "rmps.certfile")) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef CONFPARSER_H
|
#ifndef CONFPARSER_H
|
||||||
#define CONFPARSER_H
|
#define CONFPARSER_H
|
||||||
|
|
||||||
|
#include "log_trace.h"
|
||||||
|
|
||||||
#define MAXPATHSIZE 256
|
#define MAXPATHSIZE 256
|
||||||
#define HOSTNAMESIZE 128
|
#define HOSTNAMESIZE 128
|
||||||
#define CFGLINESIZE 300
|
#define CFGLINESIZE 300
|
||||||
@@ -16,7 +18,7 @@ struct conf_rmps {
|
|||||||
char bind_on_port[6];
|
char bind_on_port[6];
|
||||||
char logfile[MAXPATHSIZE];
|
char logfile[MAXPATHSIZE];
|
||||||
char errlog[MAXPATHSIZE];
|
char errlog[MAXPATHSIZE];
|
||||||
char loglevel;
|
LOG_LEVEL loglevel;
|
||||||
char pidfile[MAXPATHSIZE];
|
char pidfile[MAXPATHSIZE];
|
||||||
char certfile[MAXPATHSIZE];
|
char certfile[MAXPATHSIZE];
|
||||||
char keyfile[MAXPATHSIZE];
|
char keyfile[MAXPATHSIZE];
|
||||||
|
|||||||
@@ -33,21 +33,21 @@ static void set_fpts(void)
|
|||||||
|
|
||||||
void log_trace(LOG_LEVEL lvl, char *fmt, ... )
|
void log_trace(LOG_LEVEL lvl, char *fmt, ... )
|
||||||
{
|
{
|
||||||
LOG_LEVEL cur_lvl = conf.rmps.loglevel - '0';
|
|
||||||
char fmt_with_pfx[1024];
|
char fmt_with_pfx[1024];
|
||||||
|
|
||||||
pthread_once(&init_once, set_fpts);
|
pthread_once(&init_once, set_fpts);
|
||||||
if (conf.isvalid)
|
if (conf.isvalid)
|
||||||
pthread_once(&once, open_logs);
|
pthread_once(&once, open_logs);
|
||||||
if (lvl <= cur_lvl) {
|
if (lvl <= conf.rmps.loglevel) {
|
||||||
va_list list;
|
va_list list;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
static const char *prefixes[] = {
|
static const char *prefixes[] = {
|
||||||
"ERROR", "WARNING", "INFO", "VERBOSE"
|
"ERROR", "WARNING", "INFO", "VERBOSE"
|
||||||
};
|
};
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
struct tm tm = *localtime(&t);
|
struct tm tm;
|
||||||
if (lvl == ERROR || lvl == WARNING)
|
localtime_r(&t, &tm);
|
||||||
|
if (conf.rmps.loglevel == ERROR || conf.rmps.loglevel == WARNING)
|
||||||
fp = fderr;
|
fp = fderr;
|
||||||
else
|
else
|
||||||
fp = fdout;
|
fp = fdout;
|
||||||
|
|||||||
Reference in New Issue
Block a user