]> git.ipfire.org Git - thirdparty/squid.git/blame - src/log/FormatHttpdCommon.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / log / FormatHttpdCommon.cc
CommitLineData
fd2c5549 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
fd2c5549 3 *
bbc27441
AJ
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.
fd2c5549 7 */
8
bbc27441
AJ
9/* DEBUG: section 46 Access Log - Apache common format */
10
f7f3304a 11#include "squid.h"
20efa1c2 12#include "AccessLogEntry.h"
38e16f92 13#include "format/Quoting.h"
31971e6a 14#include "format/Token.h"
582c2af2 15#include "globals.h"
c0e8c76f 16#include "HttpRequest.h"
82b7abe3 17#include "log/File.h"
20efa1c2 18#include "log/Formats.h"
4d5904f7 19#include "SquidConfig.h"
0268f798 20#include "SquidTime.h"
21
fd2c5549 22void
41ebd397 23Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile)
fd2c5549 24{
c0e8c76f
AJ
25 const char *user_auth = NULL;
26#if USE_AUTH
27 if (al->request && al->request->auth_user_request != NULL)
28 user_auth = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
29#endif
38e16f92 30 const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
20efa1c2 31
d4204018
AJ
32 char clientip[MAX_IPSTRLEN];
33 al->getLogClientIp(clientip, MAX_IPSTRLEN);
34
58b148e1 35 const SBuf method(al->getLogMethod());
7f06a3d8 36
f57ae909 37 logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " %s:%s%s",
d4204018 38 clientip,
20efa1c2
AJ
39 user_ident ? user_ident : dash_str,
40 user_auth ? user_auth : dash_str,
41 Time::FormatHttpd(squid_curtime),
7f06a3d8 42 SQUIDSBUFPRINT(method),
f57ae909 43 SQUIDSBUFPRINT(al->url),
c9fd01b4 44 AnyP::ProtocolType_str[al->http.version.protocol],
20efa1c2
AJ
45 al->http.version.major, al->http.version.minor,
46 al->http.code,
cc0ca3b9 47 al->http.clientReplySz.messageTotal(),
91369933 48 al->cache.code.c_str(),
20efa1c2
AJ
49 hier_code_str[al->hier.code],
50 (Config.onoff.log_mime_hdrs?"":"\n"));
51
52 safe_free(user_auth);
53 safe_free(user_ident);
54
55 if (Config.onoff.log_mime_hdrs) {
38e16f92
AJ
56 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
57 char *erep = ::Format::QuoteMimeBlob(al->headers.reply);
20efa1c2
AJ
58 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
59 safe_free(ereq);
60 safe_free(erep);
fd2c5549 61 }
c9b99797 62}
f53969cc 63