]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_log.cc
Import IPv6 support from squid3-ipv6 branch to 3-HEAD.
[thirdparty/squid.git] / src / store_log.cc
1 /*
2 * $Id: store_log.cc,v 1.36 2007/12/14 23:11:48 amosjeffries Exp $
3 *
4 * DEBUG: section 20 Storage Manager Logging Functions
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #include "squid.h"
36 #include "Store.h"
37 #include "MemObject.h"
38 #include "HttpReply.h"
39 #include "CacheManager.h"
40 #include "SquidTime.h"
41
42 static const char *storeLogTags[] =
43 {
44 "CREATE",
45 "SWAPIN",
46 "SWAPOUT",
47 "RELEASE",
48 "SO_FAIL",
49 };
50
51 static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
52 static OBJH storeLogTagsHist;
53
54 static Logfile *storelog = NULL;
55
56 void
57 storeLog(int tag, const StoreEntry * e)
58 {
59 MemObject *mem = e->mem_obj;
60 HttpReply const *reply;
61
62 if (NULL == storelog)
63 return;
64
65 storeLogTagsCounts[tag]++;
66 if (mem != NULL) {
67 if (mem->log_url == NULL) {
68 debugs(20, 1, "storeLog: NULL log_url for " << mem->url);
69 mem->dump();
70 mem->log_url = xstrdup(mem->url);
71 }
72
73 reply = e->getReply();
74 /*
75 * XXX Ok, where should we print the dir number here?
76 * Because if we print it before the swap file number, it'll break
77 * the existing log format.
78 */
79 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d %s %"PRId64"/%"PRId64" %s %s\n",
80 (int) current_time.tv_sec,
81 (int) current_time.tv_usec / 1000,
82 storeLogTags[tag],
83 e->swap_dirn,
84 e->swap_filen,
85 e->getMD5Text(),
86 reply->sline.status,
87 (int) reply->date,
88 (int) reply->last_modified,
89 (int) reply->expires,
90 reply->content_type.size() ? reply->content_type.buf() : "unknown",
91 reply->content_length,
92 e->contentLen(),
93 RequestMethodStr[mem->method],
94 mem->log_url);
95 } else {
96 /* no mem object. Most RELEASE cases */
97 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
98 (int) current_time.tv_sec,
99 (int) current_time.tv_usec / 1000,
100 storeLogTags[tag],
101 e->swap_dirn,
102 e->swap_filen,
103 e->getMD5Text());
104 }
105 }
106
107 void
108 storeLogRotate(void)
109 {
110 if (NULL == storelog)
111 return;
112
113 logfileRotate(storelog);
114 }
115
116 void
117 storeLogClose(void)
118 {
119 if (NULL == storelog)
120 return;
121
122 logfileClose(storelog);
123
124 storelog = NULL;
125 }
126
127 void
128 storeLogOpen(void)
129 {
130 if (strcmp(Config.Log.store, "none") == 0) {
131 debugs(20, 1, "Store logging disabled");
132 return;
133 }
134
135 storelog = logfileOpen(Config.Log.store, 0, 1);
136 }
137
138 void
139 storeLogRegisterWithCacheManager(CacheManager & manager)
140 {
141 manager.registerAction("store_log_tags",
142 "Histogram of store.log tags",
143 storeLogTagsHist, 0, 1);
144 }
145
146 void
147 storeLogTagsHist(StoreEntry *e)
148 {
149 int tag;
150 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; tag++) {
151 storeAppendPrintf(e, "%s %d\n",
152 storeLogTags[tag],
153 storeLogTagsCounts[tag]);
154 }
155 }