]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatHttpdCombined.cc
2 * Copyright (C) 1996-2022 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 46 Access Log - Apache combined format */
12 #include "AccessLogEntry.h"
13 #include "format/Quoting.h"
14 #include "format/Token.h"
16 #include "HttpRequest.h"
18 #include "log/Formats.h"
19 #include "SquidConfig.h"
22 Log::Format::HttpdCombined(const AccessLogEntry::Pointer
&al
, Logfile
* logfile
)
24 const char *user_ident
= ::Format::QuoteUrlEncodeUsername(al
->getClientIdent());
25 const char *user_auth
= nullptr;
26 const char *referer
= nullptr;
27 const char *agent
= nullptr;
31 if (al
->request
->auth_user_request
!= nullptr)
32 user_auth
= ::Format::QuoteUrlEncodeUsername(al
->request
->auth_user_request
->username());
34 referer
= al
->request
->header
.getStr(Http::HdrType::REFERER
);
35 agent
= al
->request
->header
.getStr(Http::HdrType::USER_AGENT
);
38 if (!referer
|| *referer
== '\0')
41 if (!agent
|| *agent
== '\0')
44 char clientip
[MAX_IPSTRLEN
];
45 al
->getLogClientIp(clientip
, MAX_IPSTRLEN
);
47 const SBuf
method(al
->getLogMethod());
49 logfilePrintf(logfile
, "%s %s %s [%s] \"" SQUIDSBUFPH
" " SQUIDSBUFPH
" %s/%d.%d\" %d %" PRId64
" \"%s\" \"%s\" %s:%s%s",
51 user_ident
? user_ident
: dash_str
,
52 user_auth
? user_auth
: dash_str
,
53 Time::FormatHttpd(squid_curtime
),
54 SQUIDSBUFPRINT(method
),
55 SQUIDSBUFPRINT(al
->url
),
56 AnyP::ProtocolType_str
[al
->http
.version
.protocol
],
57 al
->http
.version
.major
, al
->http
.version
.minor
,
59 al
->http
.clientReplySz
.messageTotal(),
62 al
->cache
.code
.c_str(),
63 hier_code_str
[al
->hier
.code
],
64 (Config
.onoff
.log_mime_hdrs
?"":"\n"));
66 safe_free(user_ident
);
69 if (Config
.onoff
.log_mime_hdrs
) {
70 char *ereq
= ::Format::QuoteMimeBlob(al
->headers
.request
);
73 al
->packReplyHeaders(mb
);
74 auto erep
= ::Format::QuoteMimeBlob(mb
.content());
75 logfilePrintf(logfile
, " [%s] [%s]\n", ereq
, erep
);