]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 50 Log file handling */
12 #include "debug/Messages.h"
16 #include "log/ModDaemon.h"
17 #include "log/ModStdio.h"
18 #include "log/ModSyslog.h"
19 #include "log/ModUdp.h"
20 #include "log/TcpLogger.h"
21 #include "sbuf/SBuf.h"
23 CBDATA_CLASS_INIT(Logfile
);
25 Logfile::Logfile(const char *aPath
) :
35 xstrncpy(path
, aPath
, sizeof(path
));
40 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
45 debugs(50, Important(26), "Logfile: opening log " << path
);
47 Logfile
*lf
= new Logfile(path
);
49 /* need to call the per-logfile-type code */
50 if (strncmp(path
, "stdio:", 6) == 0) {
52 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
53 } else if (strncmp(path
, "daemon:", 7) == 0) {
55 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
56 } else if (strncmp(path
, "tcp:", 4) == 0) {
58 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
59 } else if (strncmp(path
, "udp:", 4) == 0) {
61 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
63 } else if (strncmp(path
, "syslog:", 7) == 0) {
65 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
68 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
69 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
70 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
74 fatalf("logfileOpen: %s: couldn't open!\n", path
);
76 debugs(50, DBG_IMPORTANT
, "ERROR: logfileOpen: " << path
<< ": could not open!");
81 assert(lf
->data
!= nullptr);
86 lf
->sequence_number
= 0;
92 logfileClose(Logfile
* lf
)
94 debugs(50, Important(27), "Logfile: closing log " << lf
->path
);
101 logfileRotate(Logfile
* lf
, int16_t rotateCount
)
103 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
104 lf
->f_rotate(lf
, rotateCount
);
108 logfileWrite(Logfile
* lf
, const char *buf
, size_t len
)
110 lf
->f_linewrite(lf
, buf
, len
);
114 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
120 sbuf
.vappendf(fmt
, args
); // Throws on overflow. TODO: handle that better
121 logfileWrite(lf
, sbuf
.c_str(), sbuf
.length());
126 logfileLineStart(Logfile
* lf
)
132 logfileLineEnd(Logfile
* lf
)
135 ++ lf
->sequence_number
;
139 logfileFlush(Logfile
* lf
)