]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
2 * Copyright (C) 1996-2021 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 */
15 #include "log/ModDaemon.h"
16 #include "log/ModStdio.h"
17 #include "log/ModSyslog.h"
18 #include "log/ModUdp.h"
19 #include "log/TcpLogger.h"
20 #include "sbuf/SBuf.h"
22 CBDATA_CLASS_INIT(Logfile
);
24 Logfile::Logfile(const char *aPath
) :
34 xstrncpy(path
, aPath
, sizeof(path
));
39 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
44 debugs(50, DBG_IMPORTANT
, "Logfile: opening log " << path
);
46 Logfile
*lf
= new Logfile(path
);
48 /* need to call the per-logfile-type code */
49 if (strncmp(path
, "stdio:", 6) == 0) {
51 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
52 } else if (strncmp(path
, "daemon:", 7) == 0) {
54 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
55 } else if (strncmp(path
, "tcp:", 4) == 0) {
57 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
58 } else if (strncmp(path
, "udp:", 4) == 0) {
60 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
62 } else if (strncmp(path
, "syslog:", 7) == 0) {
64 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
67 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
68 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
69 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
73 fatalf("logfileOpen: %s: couldn't open!\n", path
);
75 debugs(50, DBG_IMPORTANT
, "logfileOpen: " << path
<< ": couldn't open!");
80 assert(lf
->data
!= NULL
);
85 lf
->sequence_number
= 0;
91 logfileClose(Logfile
* lf
)
93 debugs(50, DBG_IMPORTANT
, "Logfile: closing log " << lf
->path
);
100 logfileRotate(Logfile
* lf
, int16_t rotateCount
)
102 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
103 lf
->f_rotate(lf
, rotateCount
);
107 logfileWrite(Logfile
* lf
, const char *buf
, size_t len
)
109 lf
->f_linewrite(lf
, buf
, len
);
113 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
119 sbuf
.vappendf(fmt
, args
); // Throws on overflow. TODO: handle that better
120 logfileWrite(lf
, sbuf
.c_str(), sbuf
.length());
125 logfileLineStart(Logfile
* lf
)
131 logfileLineEnd(Logfile
* lf
)
134 ++ lf
->sequence_number
;
138 logfileFlush(Logfile
* lf
)