]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
2 * Copyright (C) 1996-2014 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 */
14 #include "log/ModDaemon.h"
15 #include "log/ModStdio.h"
16 #include "log/ModSyslog.h"
17 #include "log/ModUdp.h"
18 #include "log/TcpLogger.h"
23 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
28 debugs(50, DBG_IMPORTANT
, "Logfile: opening log " << path
);
29 CBDATA_INIT_TYPE(Logfile
);
31 Logfile
*lf
= cbdataAlloc(Logfile
);
32 xstrncpy(lf
->path
, path
, MAXPATHLEN
);
34 /* need to call the per-logfile-type code */
35 if (strncmp(path
, "stdio:", 6) == 0) {
37 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
38 } else if (strncmp(path
, "daemon:", 7) == 0) {
40 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
41 } else if (strncmp(path
, "tcp:", 4) == 0) {
43 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
44 } else if (strncmp(path
, "udp:", 4) == 0) {
46 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
48 } else if (strncmp(path
, "syslog:", 7) == 0) {
50 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
53 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
54 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
55 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
59 fatalf("logfileOpen: %s: couldn't open!\n", path
);
61 debugs(50, DBG_IMPORTANT
, "logfileOpen: " << path
<< ": couldn't open!");
66 assert(lf
->data
!= NULL
);
71 lf
->sequence_number
= 0;
77 logfileClose(Logfile
* lf
)
79 debugs(50, DBG_IMPORTANT
, "Logfile: closing log " << lf
->path
);
86 logfileRotate(Logfile
* lf
)
88 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
93 logfileWrite(Logfile
* lf
, char *buf
, size_t len
)
95 lf
->f_linewrite(lf
, buf
, len
);
99 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
107 s
= vsnprintf(buf
, 8192, fmt
, args
);
112 if (fmt
[strlen(fmt
) - 1] == '\n')
116 logfileWrite(lf
, buf
, (size_t) s
);
121 logfileLineStart(Logfile
* lf
)
127 logfileLineEnd(Logfile
* lf
)
130 ++ lf
->sequence_number
;
134 logfileFlush(Logfile
* lf
)