log logging settings

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@4467 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
ac_stef
2009-06-03 14:30:52 +00:00
parent f88a5e0b46
commit be3ab39a36
4 changed files with 19 additions and 9 deletions
+12 -3
View File
@@ -14,7 +14,8 @@
static const int levels[] = { LOG_DEBUG, LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERR };
#endif
static const char *leveldesc[] = { "", "", "", "WARNING: ", "ERROR: " };
static const char *levelprefix[] = { "", "", "", "WARNING: ", "ERROR: " };
static const char *levelname[] = { "DEBUG", "VERBOSE", "INFO", "WARNING", "ERROR", "DISABLED" };
static FILE *fp = NULL;
static string filepath, ident;
static int facility = -1,
@@ -39,7 +40,7 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file
if(syslogthreshold < ACLOG_NUM)
{
facility &= 7;
s_sprintf(ident)("AssaultCube%s", identity);
s_sprintf(ident)("AssaultCube[%s]", identity);
openlog(ident, LOG_NDELAY, facilities[facility]);
}
#endif
@@ -50,7 +51,15 @@ bool initlogging(const char *identity, int facility_, int consolethres, int file
fp = fopen(filepath, "w");
if(!fp) printf("failed to open \"%s\" for writing\n", filepath);
}
s_sprintfd(msg)("logging started: console(%s), file(%s", levelname[consolethreshold], levelname[fp ? filethreshold : ACLOG_NUM]);
if(fp) s_strcatf(msg, ", \"%s\"", filepath);
#ifdef AC_USE_SYSLOG
s_strcatf(msg, "), syslog(%s", levelname[syslogthreshold]);
if(syslogthreshold < ACLOG_NUM) s_strcatf(msg, ", \"%s\", local%d", ident, facility);
#endif
s_strcatf(msg, "), timestamp(%s)", timestamp ? "ENABLED" : "DISABLED");
enabled = consolethreshold < ACLOG_NUM || fp || syslogthreshold < ACLOG_NUM;
if(enabled) printf("%s\n", msg);
return enabled;
}
@@ -70,7 +79,7 @@ bool logline(int level, const char *msg, ...)
if(level < 0 || level >= ACLOG_NUM) return false;
s_sprintfdv(sf, msg);
filtertext(sf, sf, 2);
const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = leveldesc[level];
const char *ts = timestamp ? timestring(true, "%b %d %H:%M:%S ") : "", *ld = levelprefix[level];
char *p, *l = sf;
do
{ // break into single lines first
+1
View File
@@ -803,6 +803,7 @@ struct servercommandline
char *buf = loadcfgfile(clfilename, a, &len);
if(buf)
{
printf("reading commandline parameters from file '%s'\n", clfilename);
for(char *p = buf, *l; p < buf + len; line++)
{
l = p; p += strlen(p) + 1;
+3 -3
View File
@@ -3925,12 +3925,12 @@ void initserver(bool dedicated)
srand(time(NULL));
string identity;
if(scl.logident[0]) s_sprintf(identity)("[%s]", scl.logident);
else s_sprintf(identity)("[%s#%d]", scl.ip[0] ? scl.ip : "local", scl.serverport);
if(scl.logident[0]) filtertext(identity, scl.logident, 0);
else s_sprintf(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");
logline(ACLOG_INFO, "logging local AssaultCube server (version %d, protocol %d/%d, logident %s(%d)) now..", AC_VERSION, SERVER_PROTOCOL_VERSION, EXT_VERSION, identity, scl.syslogfacility);
logline(ACLOG_INFO, "logging local AssaultCube server (version %d, protocol %d/%d) now..", AC_VERSION, SERVER_PROTOCOL_VERSION, EXT_VERSION);
s_strcpy(servdesc_current, scl.servdesc_full);
servermsinit(scl.master ? scl.master : AC_MASTER_URI, scl.ip, CUBE_SERVINFO_PORT(scl.serverport), dedicated);
+3 -3
View File
@@ -286,7 +286,7 @@ void servermsinit(const char *master, const char *ip, int infoport, bool listen)
ENetAddress address = { ENET_HOST_ANY, infoport };
if(*ip)
{
if(enet_address_set_host(&address, ip)<0) logline(ACLOG_WARNING, "server ip not resolved\n");
if(enet_address_set_host(&address, ip)<0) logline(ACLOG_WARNING, "server ip not resolved");
else msaddress.host = address.host;
}
pongsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
@@ -295,7 +295,7 @@ void servermsinit(const char *master, const char *ip, int infoport, bool listen)
enet_socket_destroy(pongsock);
pongsock = ENET_SOCKET_NULL;
}
if(pongsock == ENET_SOCKET_NULL) fatal("could not create server info socket\n");
if(pongsock == ENET_SOCKET_NULL) fatal("could not create server info socket");
else enet_socket_set_option(pongsock, ENET_SOCKOPT_NONBLOCK, 1);
address.port = CUBE_SERVINFO_PORT_LAN;
lansock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM);
@@ -304,7 +304,7 @@ void servermsinit(const char *master, const char *ip, int infoport, bool listen)
enet_socket_destroy(lansock);
lansock = ENET_SOCKET_NULL;
}
if(lansock == ENET_SOCKET_NULL) logline(ACLOG_WARNING, "could not create LAN server info socket\n");
if(lansock == ENET_SOCKET_NULL) logline(ACLOG_WARNING, "could not create LAN server info socket");
else enet_socket_set_option(lansock, ENET_SOCKOPT_NONBLOCK, 1);
}
}