]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
2 * DEBUG: section 50 Log file handling
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36 #include "log/ModDaemon.h"
37 #include "log/ModStdio.h"
38 #include "log/ModSyslog.h"
39 #include "log/ModUdp.h"
40 #include "log/TcpLogger.h"
45 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
50 debugs(50, DBG_IMPORTANT
, "Logfile: opening log " << path
);
51 CBDATA_INIT_TYPE(Logfile
);
53 Logfile
*lf
= cbdataAlloc(Logfile
);
54 xstrncpy(lf
->path
, path
, MAXPATHLEN
);
56 /* need to call the per-logfile-type code */
57 if (strncmp(path
, "stdio:", 6) == 0) {
59 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
60 } else if (strncmp(path
, "daemon:", 7) == 0) {
62 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
63 } else if (strncmp(path
, "tcp:", 4) == 0) {
65 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
66 } else if (strncmp(path
, "udp:", 4) == 0) {
68 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
70 } else if (strncmp(path
, "syslog:", 7) == 0) {
72 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
75 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
76 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
77 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
81 fatalf("logfileOpen: %s: couldn't open!\n", path
);
83 debugs(50, DBG_IMPORTANT
, "logfileOpen: " << path
<< ": couldn't open!");
88 assert(lf
->data
!= NULL
);
93 lf
->sequence_number
= 0;
99 logfileClose(Logfile
* lf
)
101 debugs(50, DBG_IMPORTANT
, "Logfile: closing log " << lf
->path
);
108 logfileRotate(Logfile
* lf
)
110 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
115 logfileWrite(Logfile
* lf
, char *buf
, size_t len
)
117 lf
->f_linewrite(lf
, buf
, len
);
121 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
129 s
= vsnprintf(buf
, 8192, fmt
, args
);
134 if (fmt
[strlen(fmt
) - 1] == '\n')
138 logfileWrite(lf
, buf
, (size_t) s
);
143 logfileLineStart(Logfile
* lf
)
149 logfileLineEnd(Logfile
* lf
)
152 ++ lf
->sequence_number
;
156 logfileFlush(Logfile
* lf
)