]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatHttpdCommon.cc
mkrelease: allow two digits for minor release numbers (#1837)
[thirdparty/squid.git] / src / log / FormatHttpdCommon.cc
1 /*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 /* DEBUG: section 46 Access Log - Apache common format */
10
11 #include "squid.h"
12 #include "AccessLogEntry.h"
13 #include "format/Quoting.h"
14 #include "format/Token.h"
15 #include "globals.h"
16 #include "HttpRequest.h"
17 #include "log/File.h"
18 #include "log/Formats.h"
19 #include "SquidConfig.h"
20
21 void
22 Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile)
23 {
24 const char *user_auth = nullptr;
25 #if USE_AUTH
26 if (al->request && al->request->auth_user_request != nullptr)
27 user_auth = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
28 #endif
29
30 char clientip[MAX_IPSTRLEN];
31 al->getLogClientIp(clientip, MAX_IPSTRLEN);
32
33 const SBuf method(al->getLogMethod());
34
35 logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " %s:%s%s",
36 clientip,
37 dash_str,
38 user_auth ? user_auth : dash_str,
39 Time::FormatHttpd(squid_curtime),
40 SQUIDSBUFPRINT(method),
41 SQUIDSBUFPRINT(al->url),
42 AnyP::ProtocolType_str[al->http.version.protocol],
43 al->http.version.major, al->http.version.minor,
44 al->http.code,
45 al->http.clientReplySz.messageTotal(),
46 al->cache.code.c_str(),
47 hier_code_str[al->hier.code],
48 (Config.onoff.log_mime_hdrs?"":"\n"));
49
50 safe_free(user_auth);
51
52 if (Config.onoff.log_mime_hdrs) {
53 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
54 MemBuf mb;
55 mb.init();
56 al->packReplyHeaders(mb);
57 auto erep = ::Format::QuoteMimeBlob(mb.content());
58 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
59 safe_free(ereq);
60 safe_free(erep);
61 }
62 }
63