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