{
for (CustomLog* log = Config.Log.icaplogs; log; log = log->next) {
if (log->logfile) {
- logfileRotate(log->logfile);
+ logfileRotate(log->logfile, Config.Log.rotateNumber);
}
}
}
cl->filename = xstrdup(filename);
cl->type = Log::Format::CLF_UNKNOWN;
+ cl->rotateCount = -1; // default: use global logfile_rotate setting.
const char *token = ConfigParser::PeekAtToken();
if (!token) { // style #1
}
} else if (strncasecmp(token, "buffer-size=", 12) == 0) {
parseBytesOptionValue(&cl->bufferSize, B_BYTES_STR, token+12);
+ } else if (strncasecmp(token, "rotate=", 7) == 0) {
+ cl->rotateCount = xatoi(token + 7);
} else if (strncasecmp(token, "logformat=", 10) == 0) {
setLogformat(cl, token+10, true);
} else if (!strchr(token, '=')) {
switch (log->type) {
case Log::Format::CLF_CUSTOM:
- storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
+ storeAppendPrintf(entry, "%s logformat=%s", log->filename, log->logFormat->name);
break;
case Log::Format::CLF_NONE:
- storeAppendPrintf(entry, "none");
+ storeAppendPrintf(entry, "logformat=none");
break;
case Log::Format::CLF_SQUID:
- storeAppendPrintf(entry, "%s squid", log->filename);
+ storeAppendPrintf(entry, "%s logformat=squid", log->filename);
break;
case Log::Format::CLF_COMBINED:
- storeAppendPrintf(entry, "%s combined", log->filename);
+ storeAppendPrintf(entry, "%s logformat=combined", log->filename);
break;
case Log::Format::CLF_COMMON:
- storeAppendPrintf(entry, "%s common", log->filename);
+ storeAppendPrintf(entry, "%s logformat=common", log->filename);
break;
#if ICAP_CLIENT
case Log::Format::CLF_ICAP_SQUID:
- storeAppendPrintf(entry, "%s icap_squid", log->filename);
+ storeAppendPrintf(entry, "%s logformat=icap_squid", log->filename);
break;
#endif
case Log::Format::CLF_USERAGENT:
- storeAppendPrintf(entry, "%s useragent", log->filename);
+ storeAppendPrintf(entry, "%s logformat=useragent", log->filename);
break;
case Log::Format::CLF_REFERER:
- storeAppendPrintf(entry, "%s referrer", log->filename);
+ storeAppendPrintf(entry, "%s logformat=referrer", log->filename);
break;
case Log::Format::CLF_UNKNOWN:
break;
}
+ // default is on-error=die
+ if (!log->fatal)
+ storeAppendPrintf(entry, " on-error=drop");
+
+ // default: 64KB
+ if (log->bufferSize != 64*1024)
+ storeAppendPrintf(entry, " buffer-size=%d", log->bufferSize);
+
+ if (log->rotateCount >= 0)
+ storeAppendPrintf(entry, " rotate=%d", log->rotateCount);
+
if (log->aclList)
dump_acl_list(entry, log->aclList);
support has not been tested for modules other
than tcp.
+ rotate=N Specifies the number of log file rotations to
+ make when you run 'squid -k rotate'. The default
+ is to obey the logfile_rotate directive. Setting
+ rotate=0 will disable the file name rotation,
+ but the log files are still closed and re-opened.
+ This will enable you to rename the logfiles
+ yourself just before sending the rotate signal.
+ Only supported by the stdio module.
+
===== Modules Currently available =====
none Do not log any requests matching these ACL.
DEFAULT: 10
LOC: Config.Log.rotateNumber
DOC_START
- Specifies the number of logfile rotations to make when you
+ Specifies the default number of logfile rotations to make when you
type 'squid -k rotate'. The default is 10, which will rotate
with extensions 0 through 9. Setting logfile_rotate to 0 will
disable the file name rotation, but the logfiles are still closed
and re-opened. This will enable you to rename the logfiles
yourself just before sending the rotate signal.
+ Note, from Squid-3.1 this option is only a default for cache.log,
+ that log can be rotated separately by using debug_options.
+
+ Note, from Squid-3.6 this option is only a default for access.log
+ recorded by stdio: module. Those logs can be rotated separately by
+ using the rotate=N option on their access_log directive.
+
Note, the 'squid -k rotate' command normally sends a USR1
signal to the running squid process. In certain situations
(e.g. on Linux with Async I/O), USR1 is used for other
in the habit of using 'squid -k rotate' instead of 'kill -USR1
<pid>'.
- Note, from Squid-3.1 this option is only a default for cache.log,
- that log can be rotated separately by using debug_options.
DOC_END
NAME: mime_table
class Format;
}
-/// representaiton of a custom log directive. Currently a POD.
+/// representation of a custom log directive.
class CustomLog
{
public:
size_t bufferSize;
/// whether unrecoverable errors (e.g., dropping a log record) kill worker
bool fatal;
+ /// How many log files to retain when rotating. Default: obey logfile_rotate
+ int16_t rotateCount;
};
#endif /* SQUID_CUSTOMLOG_H_ */
}
void
-logfileRotate(Logfile * lf)
+logfileRotate(Logfile * lf, int16_t rotateCount)
{
debugs(50, DBG_IMPORTANT, "logfileRotate: " << lf->path);
- lf->f_rotate(lf);
+ lf->f_rotate(lf, rotateCount);
}
void
typedef void LOGWRITE(Logfile *, const char *, size_t len);
typedef void LOGLINEEND(Logfile *);
typedef void LOGFLUSH(Logfile *);
-typedef void LOGROTATE(Logfile *);
+typedef void LOGROTATE(Logfile *, const int16_t);
typedef void LOGCLOSE(Logfile *);
class Logfile
/* Legacy API */
Logfile *logfileOpen(const char *path, size_t bufsz, int);
void logfileClose(Logfile * lf);
-void logfileRotate(Logfile * lf);
+void logfileRotate(Logfile * lf, int16_t rotateCount);
void logfileWrite(Logfile * lf, char *buf, size_t len);
void logfileFlush(Logfile * lf);
void logfilePrintf(Logfile * lf, const char *fmt,...) PRINTF_FORMAT_ARG2;
}
static void
-logfile_mod_daemon_rotate(Logfile * lf)
+logfile_mod_daemon_rotate(Logfile * lf, const int16_t)
{
char tb[3];
debugs(50, DBG_IMPORTANT, "logfileRotate: " << lf->path);
}
static void
-logfile_mod_stdio_rotate(Logfile * lf)
+logfile_mod_stdio_rotate(Logfile * lf, const int16_t nRotate)
{
#ifdef S_ISREG
struct stat sb;
#endif
- int i;
char from[MAXPATHLEN];
char to[MAXPATHLEN];
l_stdio_t *ll = (l_stdio_t *) lf->data;
debugs(0, DBG_IMPORTANT, "Rotate log file " << lf->path);
/* Rotate numbers 0 through N up one */
- for (i = Config.Log.rotateNumber; i > 1;) {
+ for (int16_t i = nRotate; i > 1;) {
--i;
snprintf(from, MAXPATHLEN, "%s.%d", realpath, i - 1);
snprintf(to, MAXPATHLEN, "%s.%d", realpath, i);
file_close(ll->fd); /* always close */
- if (Config.Log.rotateNumber > 0) {
+ if (nRotate > 0) {
snprintf(to, MAXPATHLEN, "%s.%d", realpath, 0);
xrename(realpath, to);
}
}
static void
-logfile_mod_syslog_rotate(Logfile *)
+logfile_mod_syslog_rotate(Logfile *, const int16_t)
{
}
}
static void
-logfile_mod_udp_rotate(Logfile *)
+logfile_mod_udp_rotate(Logfile *, const int16_t)
{
}
}
void
-Log::TcpLogger::Rotate(Logfile *)
+Log::TcpLogger::Rotate(Logfile *, const int16_t)
{
}
static void WriteLine(Logfile *lf, const char *buf, size_t len);
static void StartLine(Logfile *lf);
static void EndLine(Logfile *lf);
- static void Rotate(Logfile *lf);
+ static void Rotate(Logfile *lf, const int16_t);
static void Close(Logfile *lf);
static TcpLogger *StillLogging(Logfile *lf);
for (log = Config.Log.accesslogs; log; log = log->next) {
if (log->logfile) {
- logfileRotate(log->logfile);
+ int16_t rc = (log->rotateCount >= 0 ? log->rotateCount : Config.Log.rotateNumber);
+ logfileRotate(log->logfile, rc);
}
}
#if HEADERS_LOG
- logfileRotate(headerslog);
+ logfileRotate(headerslog, Config.Log.rotateNumber);
#endif
}
if (NULL == storelog)
return;
- logfileRotate(storelog);
+ logfileRotate(storelog, Config.Log.rotateNumber);
}
void