]> git.ipfire.org Git - thirdparty/squid.git/blob - src/log/FormatSquidNative.cc
Merged from trunk rev.14612
[thirdparty/squid.git] / src / log / FormatSquidNative.cc
1 /*
2 * Copyright (C) 1996-2016 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 - Squid 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 #include "SquidTime.h"
21
22 void
23 Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile)
24 {
25 char hierHost[MAX_IPSTRLEN];
26
27 const char *user = NULL;
28
29 #if USE_AUTH
30 if (al->request && al->request->auth_user_request != NULL)
31 user = ::Format::QuoteUrlEncodeUsername(al->request->auth_user_request->username());
32 #endif
33
34 if (!user)
35 user = ::Format::QuoteUrlEncodeUsername(al->cache.extuser);
36
37 #if USE_OPENSSL
38 if (!user)
39 user = ::Format::QuoteUrlEncodeUsername(al->cache.ssluser);
40 #endif
41
42 if (!user)
43 user = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931);
44
45 if (user && !*user)
46 safe_free(user);
47
48 char clientip[MAX_IPSTRLEN];
49 al->getLogClientIp(clientip, MAX_IPSTRLEN);
50
51 const SBuf method(al->getLogMethod());
52
53 logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " " SQUIDSBUFPH " %s %s%s/%s %s%s",
54 (long int) current_time.tv_sec,
55 (int) current_time.tv_usec / 1000,
56 tvToMsec(al->cache.trTime),
57 clientip,
58 al->cache.code.c_str(),
59 al->http.code,
60 al->http.clientReplySz.messageTotal(),
61 SQUIDSBUFPRINT(method),
62 SQUIDSBUFPRINT(al->url),
63 user ? user : dash_str,
64 al->hier.ping.timedout ? "TIMEOUT_" : "",
65 hier_code_str[al->hier.code],
66 al->hier.tcpServer != NULL ? al->hier.tcpServer->remote.toStr(hierHost, sizeof(hierHost)) : "-",
67 al->http.content_type,
68 (Config.onoff.log_mime_hdrs?"":"\n"));
69
70 safe_free(user);
71
72 if (Config.onoff.log_mime_hdrs) {
73 char *ereq = ::Format::QuoteMimeBlob(al->headers.request);
74 char *erep = ::Format::QuoteMimeBlob(al->headers.reply);
75 logfilePrintf(logfile, " [%s] [%s]\n", ereq, erep);
76 safe_free(ereq);
77 safe_free(erep);
78 }
79 }
80