]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/File.cc
2 * Copyright (C) 1996-2015 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"
24 logfileOpen(const char *path
, size_t bufsz
, int fatal_flag
)
29 debugs(50, DBG_IMPORTANT
, "Logfile: opening log " << path
);
30 CBDATA_INIT_TYPE(Logfile
);
32 Logfile
*lf
= cbdataAlloc(Logfile
);
33 xstrncpy(lf
->path
, path
, MAXPATHLEN
);
35 /* need to call the per-logfile-type code */
36 if (strncmp(path
, "stdio:", 6) == 0) {
38 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
39 } else if (strncmp(path
, "daemon:", 7) == 0) {
41 ret
= logfile_mod_daemon_open(lf
, patharg
, bufsz
, fatal_flag
);
42 } else if (strncmp(path
, "tcp:", 4) == 0) {
44 ret
= Log::TcpLogger::Open(lf
, patharg
, bufsz
, fatal_flag
);
45 } else if (strncmp(path
, "udp:", 4) == 0) {
47 ret
= logfile_mod_udp_open(lf
, patharg
, bufsz
, fatal_flag
);
49 } else if (strncmp(path
, "syslog:", 7) == 0) {
51 ret
= logfile_mod_syslog_open(lf
, patharg
, bufsz
, fatal_flag
);
54 debugs(50, DBG_IMPORTANT
, "WARNING: log name now starts with a module name. Use 'stdio:" << patharg
<< "'");
55 snprintf(lf
->path
, MAXPATHLEN
, "stdio:%s", patharg
);
56 ret
= logfile_mod_stdio_open(lf
, patharg
, bufsz
, fatal_flag
);
60 fatalf("logfileOpen: %s: couldn't open!\n", path
);
62 debugs(50, DBG_IMPORTANT
, "logfileOpen: " << path
<< ": couldn't open!");
67 assert(lf
->data
!= NULL
);
72 lf
->sequence_number
= 0;
78 logfileClose(Logfile
* lf
)
80 debugs(50, DBG_IMPORTANT
, "Logfile: closing log " << lf
->path
);
87 logfileRotate(Logfile
* lf
)
89 debugs(50, DBG_IMPORTANT
, "logfileRotate: " << lf
->path
);
94 logfileWrite(Logfile
* lf
, char *buf
, size_t len
)
96 lf
->f_linewrite(lf
, buf
, len
);
100 logfilePrintf(Logfile
* lf
, const char *fmt
,...)
108 s
= vsnprintf(buf
, 8192, fmt
, args
);
113 if (fmt
[strlen(fmt
) - 1] == '\n')
117 logfileWrite(lf
, buf
, (size_t) s
);
122 logfileLineStart(Logfile
* lf
)
128 logfileLineEnd(Logfile
* lf
)
131 ++ lf
->sequence_number
;
135 logfileFlush(Logfile
* lf
)