Force log rotation if LogFileMaxSize is non-zero

This commit is contained in:
Shawn webb
2012-08-23 16:33:45 -04:00
parent d3b0b428e2
commit e1c3ee76aa
4 changed files with 13 additions and 19 deletions

View File

@@ -225,7 +225,8 @@ Example
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes). To specify the size
# in bytes just don't use modifiers.
# in bytes just don't use modifiers. If LogFileMaxSize is enabled, log
# rotation (the LogRotate option) will always be enabled.
#
# Default: 1M
#LogFileMaxSize 2M
@@ -251,7 +252,7 @@ Example
# Default: no
#LogVerbose yes
# Enable log rotation.
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
# Default: no
#LogRotate yes

View File

@@ -25,7 +25,8 @@ Example
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes). To specify the size
# in bytes just don't use modifiers.
# in bytes just don't use modifiers. If LogFileMaxSize is enabled, log
# rotation (the LogRotate option) will always be enabled.
# Default: 1M
#LogFileMaxSize 2M
@@ -51,7 +52,7 @@ Example
# Default: no
#LogVerbose yes
# Enable log rotation.
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
# Default: no
#LogRotate yes

View File

@@ -20,7 +20,8 @@ Example
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes).
# in bytes just don't use modifiers.
# in bytes just don't use modifiers. If LogFileMaxSize is enabled,
# log rotation (the LogRotate option) will always be enabled.
# Default: 1M
#LogFileMaxSize 2M
@@ -41,7 +42,7 @@ Example
# Default: LOG_LOCAL6
#LogFacility LOG_MAIL
# Enable log rotation.
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
# Default: no
#LogRotate yes

View File

@@ -214,34 +214,25 @@ static int rename_logg(STATBUF *sb)
if (!logg_rotate) {
if (logg_fp) {
fprintf(logg_fp, "Log size = %u, max = %u\n", sb->st_size, logg_size);
fprintf(logg_fp, "LOGGING DISABLED (Maximal log file size exceeded).\n");
fclose(logg_fp);
logg_fp = NULL;
fprintf(logg_fp, "WARNING: Log size limit met but log file rotation turned off. Forcing log file rotation anyways.\n");
}
logg_file = NULL;
return 0;
logg_rotate = 1;
}
rotate_file_len = strlen(logg_file) + sizeof("-YYYY-MM-DD_HH:MM:SS");
rotate_file = calloc(1, rotate_file_len + 1);
if (!rotate_file) {
if (logg_fp) {
if (logg_fp)
fprintf(logg_fp, "Need to rotate log file due to size but ran out of memory.\n");
fclose(logg_fp);
logg_fp = NULL;
}
return -1;
}
t = time(NULL);
if (!localtime_r(&t, &tmp)) {
if (logg_fp) {
if (logg_fp)
fprintf(logg_fp, "Need to rotate log file due to size but could not get local time.\n");
fclose(logg_fp);
logg_fp = NULL;
}
free(rotate_file);
return -1;