/*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "log/ModSyslog.h"
#include "log/ModUdp.h"
#include "log/TcpLogger.h"
-
-CBDATA_TYPE(Logfile);
+#include "sbuf/SBuf.h"
+
+CBDATA_CLASS_INIT(Logfile);
+
+Logfile::Logfile(const char *aPath) :
+ sequence_number(0),
+ data(NULL),
+ f_linestart(NULL),
+ f_linewrite(NULL),
+ f_lineend(NULL),
+ f_flush(NULL),
+ f_rotate(NULL),
+ f_close(NULL)
+{
+ xstrncpy(path, aPath, sizeof(path));
+ flags.fatal = 0;
+}
Logfile *
logfileOpen(const char *path, size_t bufsz, int fatal_flag)
const char *patharg;
debugs(50, DBG_IMPORTANT, "Logfile: opening log " << path);
- CBDATA_INIT_TYPE(Logfile);
- Logfile *lf = cbdataAlloc(Logfile);
- xstrncpy(lf->path, path, MAXPATHLEN);
+ Logfile *lf = new Logfile(path);
patharg = path;
/* need to call the per-logfile-type code */
if (strncmp(path, "stdio:", 6) == 0) {
else
debugs(50, DBG_IMPORTANT, "logfileOpen: " << path << ": couldn't open!");
lf->f_close(lf);
- cbdataFree(lf);
+ delete lf;
return NULL;
}
assert(lf->data != NULL);
debugs(50, DBG_IMPORTANT, "Logfile: closing log " << lf->path);
lf->f_flush(lf);
lf->f_close(lf);
- cbdataFree(lf);
+ delete lf;
}
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
-logfileWrite(Logfile * lf, char *buf, size_t len)
+logfileWrite(Logfile * lf, const char *buf, size_t len)
{
lf->f_linewrite(lf, buf, len);
}
logfilePrintf(Logfile * lf, const char *fmt,...)
{
va_list args;
- char buf[8192];
- int s;
-
va_start(args, fmt);
-
- s = vsnprintf(buf, 8192, fmt, args);
-
- if (s > 8192) {
- s = 8192;
-
- if (fmt[strlen(fmt) - 1] == '\n')
- buf[8191] = '\n';
- }
-
- logfileWrite(lf, buf, (size_t) s);
+ static SBuf sbuf;
+ sbuf.clear();
+ sbuf.vappendf(fmt, args); // Throws on overflow. TODO: handle that better
+ logfileWrite(lf, sbuf.c_str(), sbuf.length());
va_end(args);
}
{
lf->f_flush(lf);
}
+