mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-07 17:03:12 +02:00
Added log::maxsize
This commit is contained in:
@@ -770,3 +770,4 @@ seen. gmtime warning still there
|
||||
- Fixed a win32 bug where /restart didn't remove the tray icon, reported by PHANTOm and Gilou
|
||||
- Fixed Osiris's example.conf
|
||||
- Fixed IPv6 bindip error found by Madkiss
|
||||
- Added log::maxsize, when this size is reached the log is cleared and started over again
|
||||
|
||||
@@ -1023,6 +1023,7 @@ struct _configitem_log {
|
||||
ConfigFlag flag;
|
||||
ConfigItem *prev, *next;
|
||||
char *file;
|
||||
long maxsize;
|
||||
int flags;
|
||||
};
|
||||
|
||||
|
||||
@@ -2627,6 +2627,8 @@ int _conf_log(ConfigFile *conf, ConfigEntry *ce)
|
||||
cep->ce_varlinenum);
|
||||
continue;
|
||||
}
|
||||
if (!strcmp(cep->ce_varname, "maxsize"))
|
||||
log->maxsize = atol(cep->ce_vardata);
|
||||
if (!strcmp(cep->ce_varname, "flags")) {
|
||||
for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next)
|
||||
{
|
||||
|
||||
@@ -426,12 +426,25 @@ void ircd_log(int flags, char *format, ...)
|
||||
ConfigItem_log *logs;
|
||||
char buf[2048], timebuf[128];
|
||||
int fd;
|
||||
struct stat fstats;
|
||||
va_start(ap, format);
|
||||
ircvsprintf(buf, format, ap);
|
||||
strcat(buf, "\n");
|
||||
sprintf(timebuf, "[%s] - ", myctime(TStime()));
|
||||
for (logs = conf_log; logs; logs = (ConfigItem_log *) logs->next) {
|
||||
if (logs->flags & flags) {
|
||||
stat(logs->file, &fstats);
|
||||
if (logs->maxsize && fstats.st_size >= logs->maxsize) {
|
||||
#ifndef _WIN32
|
||||
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
|
||||
#else
|
||||
fd = open(logs->file, O_CREAT|O_WRONLY|O_TRUNC);
|
||||
#endif
|
||||
if (fd == -1)
|
||||
continue;
|
||||
write(fd, "Max file size reached, starting new log file\n", 46);
|
||||
}
|
||||
else {
|
||||
#ifndef _WIN32
|
||||
fd = open(logs->file, O_CREAT|O_APPEND|O_WRONLY, S_IRUSR|S_IWUSR);
|
||||
#else
|
||||
@@ -439,6 +452,7 @@ void ircd_log(int flags, char *format, ...)
|
||||
#endif
|
||||
if (fd == -1)
|
||||
continue;
|
||||
}
|
||||
write(fd, timebuf, strlen(timebuf));
|
||||
write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
|
||||
Reference in New Issue
Block a user