]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
5f612b430c637d22dba05f91a754d823c167b25e
2 * Copyright (C) 1996-2017 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"
21 CBDATA_CLASS_INIT(Logfile
);
23 Logfile::Logfile(const char *aPath
) :
33 xstrncpy(path
, aPath
, sizeof(path
));
38 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
43 debugs(50, DBG_IMPORTANT
, "Logfile: opening log " << path
);
45 Logfile
*lf
= new Logfile(path
);
47 /* need to call the per-logfile-type code */
48 if (strncmp(path
, "stdio:", 6) == 0) {
50 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
51 } else if (strncmp(path
, "daemon:", 7) == 0) {
53 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
54 } else if (strncmp(path
, "tcp:", 4) == 0) {
56 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
57 } else if (strncmp(path
, "udp:", 4) == 0) {
59 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
61 } else if (strncmp(path
, "syslog:", 7) == 0) {
63 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
66 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
67 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
68 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
72 fatalf("logfileOpen: %s: couldn't open!\n", path
);
74 debugs(50, DBG_IMPORTANT
, "logfileOpen: " << path
<< ": couldn't open!");
79 assert(lf
->data
!= NULL
);
84 lf
->sequence_number
= 0;
90 logfileClose(Logfile
* lf
)
92 debugs(50, DBG_IMPORTANT
, "Logfile: closing log " << lf
->path
);
99 logfileRotate(Logfile
* lf
, int16_t rotateCount
)
101 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
102 lf
->f_rotate(lf
, rotateCount
);
106 logfileWrite(Logfile
* lf
, char *buf
, size_t len
)
108 lf
->f_linewrite(lf
, buf
, len
);
112 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
120 s
= vsnprintf(buf
, 8192, fmt
, args
);
125 if (fmt
[strlen(fmt
) - 1] == '\n')
129 logfileWrite(lf
, buf
, (size_t) s
);
134 logfileLineStart(Logfile
* lf
)
140 logfileLineEnd(Logfile
* lf
)
143 ++ lf
->sequence_number
;
147 logfileFlush(Logfile
* lf
)