user syslog for logging

This commit is contained in:
lxsang 2020-02-12 12:08:36 +01:00
parent 357b45aee9
commit d5682fe186
5 changed files with 8 additions and 82 deletions

View File

@ -7,10 +7,6 @@ plugins_ext=.so
database=/opt/www/database/ database=/opt/www/database/
; tmp dir ; tmp dir
tmpdir=/opt/www/tmp/ tmpdir=/opt/www/tmp/
; server log
server_log = /var/log/antd.log
; server error log
error_log = /var/log/antd_error.log
; max concurent connection ; max concurent connection
maxcon=200 maxcon=200
; server backlocg ; server backlocg

View File

@ -27,57 +27,6 @@ config_t *config()
{ {
return &server_config; return &server_config;
} }
void error_log(const char* fmt, ...)
{
if(server_config.errorfp)
{
va_list arguments;
char * data;
va_start( arguments, fmt);
int dlen = vsnprintf(0,0,fmt,arguments) + 1;
va_end(arguments);
if ((data = (char*)malloc(dlen*sizeof(char))) != 0)
{
char buf[64];
server_time(buf,64);
fwrite(buf,strlen(buf),1,server_config.errorfp);
va_start(arguments, fmt);
vsnprintf(data, dlen, fmt, arguments);
va_end(arguments);
fwrite(data,dlen,1,server_config.errorfp);
fflush(server_config.errorfp);
free(data);
}
}
}
#ifdef DEBUG
void server_log(const char* fmt, ...)
{
if(server_config.logfp)
{
va_list arguments;
char * data;
va_start( arguments, fmt);
int dlen = vsnprintf(0,0,fmt,arguments) + 1;
va_end(arguments);
if ((data = (char*)malloc(dlen*sizeof(char))) != 0)
{
char buf[64];
server_time(buf,64);
fwrite(buf,strlen(buf),1,server_config.logfp);
va_start(arguments, fmt);
vsnprintf(data, dlen, fmt, arguments);
va_end(arguments);
fwrite(data,dlen,1,server_config.logfp);
fflush(server_config.logfp);
free(data);
}
}
}
#endif
void destroy_config() void destroy_config()
{ {
freedict(server_config.handlers); freedict(server_config.handlers);
@ -93,16 +42,6 @@ void destroy_config()
free(server_config.ssl_cipher); free(server_config.ssl_cipher);
if(server_config.gzip_types) if(server_config.gzip_types)
list_free(&server_config.gzip_types); list_free(&server_config.gzip_types);
if(server_config.errorfp)
{
fclose(server_config.errorfp);
}
#ifdef DEBUG
if(server_config.logfp)
{
fclose(server_config.logfp);
}
#endif
if(server_config.mimes) if(server_config.mimes)
freedict(server_config.mimes); freedict(server_config.mimes);
if(server_config.ports) if(server_config.ports)
@ -166,10 +105,6 @@ static int config_handler(void *conf, const char *section, const char *name,
{ {
pconfig->n_workers = atoi(value); pconfig->n_workers = atoi(value);
} }
else if (MATCH("SERVER", "error_log"))
{
pconfig->errorfp = fopen(value, "w");
}
#ifdef USE_ZLIB #ifdef USE_ZLIB
else if (MATCH("SERVER", "gzip_enable")) else if (MATCH("SERVER", "gzip_enable"))
{ {
@ -180,12 +115,6 @@ static int config_handler(void *conf, const char *section, const char *name,
pconfig->gzip_types = split(value,","); pconfig->gzip_types = split(value,",");
} }
#endif #endif
#ifdef DEBUG
else if (MATCH("SERVER", "server_log"))
{
pconfig->logfp = fopen(value, "w");
}
#endif
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
else if (MATCH("SERVER", "ssl.cert")) else if (MATCH("SERVER", "ssl.cert"))
{ {
@ -290,8 +219,6 @@ void load_config(const char *file)
server_config.maxcon = 100; server_config.maxcon = 100;
server_config.max_upload_size = 10000000; //10Mb server_config.max_upload_size = 10000000; //10Mb
server_config.connection = 0; server_config.connection = 0;
server_config.errorfp = NULL;
server_config.logfp = NULL;
server_config.mimes = dict(); server_config.mimes = dict();
server_config.enable_ssl = 0; server_config.enable_ssl = 0;
server_config.sslcert = "cert.pem"; server_config.sslcert = "cert.pem";

View File

@ -123,6 +123,8 @@ void configure_context(SSL_CTX *ctx)
void stop_serve(int dummy) { void stop_serve(int dummy) {
UNUSED(dummy); UNUSED(dummy);
// close log server
closelog ();
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
//Blocks the SIG_IGN signal (by adding SIG_IGN to newMask) //Blocks the SIG_IGN signal (by adding SIG_IGN to newMask)
@ -166,6 +168,9 @@ int main(int argc, char* argv[])
signal(SIGINT, stop_serve); signal(SIGINT, stop_serve);
config_t* conf = config(); config_t* conf = config();
// start syslog
setlogmask (LOG_UPTO (LOG_NOTICE));
openlog (SERVER_NAME, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
if( conf->enable_ssl == 1 ) if( conf->enable_ssl == 1 )

View File

@ -85,9 +85,6 @@ typedef struct {
int connection; int connection;
int n_workers; int n_workers;
int max_upload_size; int max_upload_size;
// log
FILE* errorfp;
FILE* logfp;
// ssl // ssl
int enable_ssl; int enable_ssl;
char* sslcert; char* sslcert;

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
#include <errno.h> #include <errno.h>
#include <syslog.h>
#ifdef USE_OPENSSL #ifdef USE_OPENSSL
#include <openssl/sha.h> #include <openssl/sha.h>
#else #else
@ -56,12 +57,12 @@ THE SOFTWARE.
#define false 0 #define false 0
#ifdef DEBUG #ifdef DEBUG
#define LOG(a,...) server_log(": [%s: %d]: " a "\n", __FILE__, \ #define LOG(a,...) syslog (LOG_NOTICE,"[%s: %d]: " a "\n", __FILE__, \
__LINE__, ##__VA_ARGS__) __LINE__, ##__VA_ARGS__)
#else #else
#define LOG(a,...) do{}while(0) #define LOG(a,...) do{}while(0)
#endif #endif
#define ERROR(a,...) error_log(": [%s: %d]: " a "\n", __FILE__, \ #define ERROR(a,...) syslog (LOG_ERR, "[%s: %d]: " a "\n", __FILE__, \
__LINE__, ##__VA_ARGS__) __LINE__, ##__VA_ARGS__)
// add this to the utils // add this to the utils
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)