FormatHttpdCombined.cc
Go to the documentation of this file.
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 combined 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
23 {
24  const char *user_auth = nullptr;
25  const char *referer = nullptr;
26  const char *agent = nullptr;
27 
28  if (al->request) {
29 #if USE_AUTH
30  if (al->request->auth_user_request != nullptr)
32 #endif
35  }
36 
37  if (!referer || *referer == '\0')
38  referer = "-";
39 
40  if (!agent || *agent == '\0')
41  agent = "-";
42 
43  char clientip[MAX_IPSTRLEN];
44  al->getLogClientIp(clientip, MAX_IPSTRLEN);
45 
46  const SBuf method(al->getLogMethod());
47 
48  logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s:%s%s",
49  clientip,
50  dash_str,
51  user_auth ? user_auth : dash_str,
53  SQUIDSBUFPRINT(method),
54  SQUIDSBUFPRINT(al->url),
57  al->http.code,
59  referer,
60  agent,
61  al->cache.code.c_str(),
62  hier_code_str[al->hier.code],
63  (Config.onoff.log_mime_hdrs?"":"\n"));
64 
65  safe_free(user_auth);
66 
68  char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
69  MemBuf mb;
70  mb.init();
71  al->packReplyHeaders(mb);
72  auto erep = ::Format::QuoteMimeBlob(mb.content());
73  logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
74  safe_free(ereq);
75  safe_free(erep);
76  }
77 }
78 
unsigned int major
major version number
void HttpdCombined(const AccessLogEntryPointer &al, Logfile *logfile)
Log with Apache httpd combined format.
const char * getStr(Http::HdrType id) const
Definition: HttpHeader.cc:1163
HttpHeader header
Definition: Message.h:74
int log_mime_hdrs
Definition: SquidConfig.h:286
char * QuoteMimeBlob(const char *header)
Definition: Quoting.cc:43
unsigned int minor
minor version number
void init(mb_size_t szInit, mb_size_t szMax)
Definition: MemBuf.cc:93
const char * ProtocolType_str[]
Definition: SBuf.h:93
struct SquidConfig::@97 onoff
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
HierarchyLogEntry hier
char * QuoteUrlEncodeUsername(const char *name)
Definition: Quoting.cc:31
AnyP::ProtocolVersion version
ProtocolType protocol
which protocol this version is for
class AccessLogEntry::HttpDetails http
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:114
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:75
const char * FormatHttpd(time_t)
Definition: gadgets.cc:116
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:25
HttpRequest * request
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
const char * username() const
Definition: UserRequest.cc:32
Definition: MemBuf.h:23
#define safe_free(x)
Definition: xalloc.h:73
const char * dash_str
class AccessLogEntry::CacheDetails cache
class AccessLogEntry::Headers headers
time_t squid_curtime
Definition: stub_libtime.cc:20
Definition: File.h:38
uint64_t messageTotal() const
total message size
Definition: MessageSizes.h:27
const char * hier_code_str[]
char * content()
start of the added data
Definition: MemBuf.h:41
MessageSizes clientReplySz
counters for the response sent to client
void getLogClientIp(char *buf, size_t bufsz) const
void packReplyHeaders(MemBuf &mb) const
dump all reply headers (for sending or risky logging)
#define PRId64
Definition: types.h:104
SBuf getLogMethod() const
Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
#define SQUIDSBUFPH
Definition: SBuf.h:31
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous