From 1c109bfa62681f289a983c5da407f1a90df3e44f Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 26 Feb 2016 18:01:48 +0100 Subject: [PATCH] new commandline parameter to specify path for server logfiles use -H to set path default is logs/ --- .gitignore | 1 + config/servercmdline.txt | 1 + source/src/log.cpp | 5 +++-- source/src/protos.h | 9 +++++---- source/src/server.cpp | 5 +++-- source/src/serverfiles.h | 9 ++------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 349c36e6..bcd9169f 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ clientlog*.txt dumpmapconfig.txt packetlog.txt profile/* +logs/* diff --git a/config/servercmdline.txt b/config/servercmdline.txt index 160fd56f..3bce2d98 100644 --- a/config/servercmdline.txt +++ b/config/servercmdline.txt @@ -37,6 +37,7 @@ // -kA // kickthreshold (in seconds) for being AFK, > 30, default 45 // -kB // time in minutes a banned player will stay banned, default 20 // -y // banthreshold, -1..-100, default -6 +// -H // server logfile path, default logs/ // -r // server maprot file, default config/maprot.cfg // -X // server passwords file, default config/serverpwd.cfg // -B // server IP blacklist file, default config/serverblacklist.cfg diff --git a/source/src/log.cpp b/source/src/log.cpp index 8fb8dc4c..5337466e 100644 --- a/source/src/log.cpp +++ b/source/src/log.cpp @@ -32,7 +32,7 @@ static int facility = -1, consolethreshold = ACLOG_INFO; static bool timestamp = false, enabled = false; -bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp) +bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp, const char *logfilepath) { facility = facility_; timestamp = logtimestamp; @@ -49,7 +49,8 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file if((logsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM)) == ENET_SOCKET_NULL || enet_address_set_host(&logdest, "localhost") < 0) syslogthreshold = ACLOG_NUM; #endif } - formatstring(filepath)("serverlog_%s_%s.txt", timestring(true), identity); + formatstring(filepath)("%sserverlog_%s_%s.txt", logfilepath, timestring(true), identity); + path(filepath); if(fp) { fclose(fp); fp = NULL; } if(filethreshold < ACLOG_NUM) { diff --git a/source/src/protos.h b/source/src/protos.h index 3bbf5854..2023b18d 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -1107,7 +1107,7 @@ extern void enddemoplayback(); enum { ACLOG_DEBUG = 0, ACLOG_VERBOSE, ACLOG_INFO, ACLOG_WARNING, ACLOG_ERROR, ACLOG_NUM }; -extern bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp); +extern bool initlogging(const char *identity, int facility_, int consolethres, int filethres, int syslogthres, bool logtimestamp, const char *logfilepath); extern void exitlogging(); extern bool logcheck(int level); extern bool logline(int level, const char *msg, ...) PRINTFARGS(2, 3); @@ -1131,7 +1131,7 @@ struct serverconfigfile struct servercommandline { int uprate, serverport, syslogfacility, filethres, syslogthres, maxdemos, maxclients, kickthreshold, banthreshold, verbose, incoming_limit, afk_limit, ban_time, demotimelocal; - const char *ip, *master, *logident, *serverpassword, *adminpasswd, *demopath, *maprot, *pwdfile, *blfile, *geoipfile, *nbfile, *infopath, *motdpath, *forbidden, *demofilenameformat, *demotimestampformat, *service; + const char *ip, *master, *logident, *serverpassword, *adminpasswd, *demopath, *maprot, *pwdfile, *blfile, *geoipfile, *nbfile, *infopath, *motdpath, *forbidden, *demofilenameformat, *demotimestampformat, *service, *logfilepath; uchar *ssk; bool logtimestamp, demo_interm, loggamestatus; string motd, servdesc_full, servdesc_pre, servdesc_suf, voteperm, mapperm; @@ -1142,7 +1142,7 @@ struct servercommandline maxclients(DEFAULTCLIENTS), kickthreshold(-5), banthreshold(-6), verbose(0), incoming_limit(10), afk_limit(45000), ban_time(20*60*1000), demotimelocal(0), ip(""), master(NULL), logident(""), serverpassword(""), adminpasswd(""), demopath(""), maprot("config/maprot.cfg"), pwdfile("config/serverpwd.cfg"), blfile("config/serverblacklist.cfg"), geoipfile("config/geoip.cfg"), nbfile("config/nicknameblacklist.cfg"), - infopath("config/serverinfo"), motdpath("config/motd"), forbidden("config/forbidden.cfg"), service(NULL), + infopath("config/serverinfo"), motdpath("config/motd"), forbidden("config/forbidden.cfg"), service(NULL), logfilepath("logs/"), ssk(NULL), logtimestamp(false), demo_interm(false), loggamestatus(true), clfilenesting(0) @@ -1160,7 +1160,7 @@ struct servercommandline int ai = atoi(a); // client: dtwhzbsave switch(arg[1]) - { // todo: gjlqEHJQU + { // todo: gjlqEJQU case 'Y': // private server key { uchar temp[64]; @@ -1208,6 +1208,7 @@ struct servercommandline case 'S': syslogthres = atoi(a + 1); break; } break; + case 'H': logfilepath = a; break; case 'A': if(*a) adminonlymaps.add(a); break; case 'c': if(ai > 0) maxclients = min(ai, MAXCLIENTS); break; case 'k': diff --git a/source/src/server.cpp b/source/src/server.cpp index 35e63c73..bbecd61c 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -4322,7 +4322,7 @@ void initserver(bool dedicated) if(scl.logident[0]) filtertext(identity, scl.logident, FTXT__LOGIDENT); else formatstring(identity)("%s#%d", scl.ip[0] ? scl.ip : "local", scl.serverport); int conthres = scl.verbose > 1 ? ACLOG_DEBUG : (scl.verbose ? ACLOG_VERBOSE : ACLOG_INFO); - if(dedicated && !initlogging(identity, scl.syslogfacility, conthres, scl.filethres, scl.syslogthres, scl.logtimestamp)) printf("WARNING: logging not started!\n"); + if(dedicated && !initlogging(identity, scl.syslogfacility, conthres, scl.filethres, scl.syslogthres, scl.logtimestamp, scl.logfilepath)) printf("WARNING: logging not started!\n"); logline(ACLOG_INFO, "logging local AssaultCube server (version %d, protocol %d/%d) now..", AC_VERSION, SERVER_PROTOCOL_VERSION, EXT_VERSION); copystring(sg->servdesc_current, scl.servdesc_full); servermsinit(dedicated); @@ -4387,7 +4387,8 @@ void initserver(bool dedicated) // start file-IO threads readmapsthread_sem = new sl_semaphore(0, NULL); - sl_createthread(readmapsthread, (void *)"xxxx"); + defformatstring(readmapslogfilename)("%sreadmaps_log.txt", scl.logfilepath); + sl_createthread(readmapsthread, (void *)path(readmapslogfilename)); for(;;) serverslice(5); } diff --git a/source/src/serverfiles.h b/source/src/serverfiles.h index 8140eda2..b3b011b9 100644 --- a/source/src/serverfiles.h +++ b/source/src/serverfiles.h @@ -473,7 +473,7 @@ void tagmapfile(const char *fpath, const char *fname, int epoch) // tag list en if(mapfileindex >= 0) mapfilenames[mapfileindex].epoch = epoch; } -int readmapsthread(void *logfileprefix) +int readmapsthread(void *logfilename) { static int readmaps_epoch = 0; @@ -481,12 +481,7 @@ int readmapsthread(void *logfileprefix) { while(!startnewservermapsepoch) readmapsthread_sem->wait(); // wait without using the cpu - if(logfileprefix) - { - defformatstring(logfilename)("%sreadmaps_log.txt", (const char *)logfileprefix); - path(logfilename); - readmaplog = openfile(logfilename, "a"); - } + if(logfilename) readmaplog = openfile((const char *)logfilename, "a"); vector maps_off, maps_serv, maps_incom;