]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_log.cc
Merged from trunk
[thirdparty/squid.git] / src / store_log.cc
1 /*
2 * $Id: store_log.cc,v 1.37 2008/01/20 08:54:28 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 "CREATE",
44 "SWAPIN",
45 "SWAPOUT",
46 "RELEASE",
47 "SO_FAIL",
48 };
49
50 static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
51 static OBJH storeLogTagsHist;
52
53 static Logfile *storelog = NULL;
54
55 void
56 storeLog(int tag, const StoreEntry * e)
57 {
58 MemObject *mem = e->mem_obj;
59 HttpReply const *reply;
60
61 if (NULL == storelog)
62 return;
63
64 storeLogTagsCounts[tag]++;
65 if (mem != NULL) {
66 if (mem->log_url == NULL) {
67 debugs(20, 1, "storeLog: NULL log_url for " << mem->url);
68 mem->dump();
69 mem->log_url = xstrdup(mem->url);
70 }
71
72 reply = e->getReply();
73 /*
74 * XXX Ok, where should we print the dir number here?
75 * Because if we print it before the swap file number, it'll break
76 * the existing log format.
77 */
78 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d %s %"PRId64"/%"PRId64" %s %s\n",
79 (int) current_time.tv_sec,
80 (int) current_time.tv_usec / 1000,
81 storeLogTags[tag],
82 e->swap_dirn,
83 e->swap_filen,
84 e->getMD5Text(),
85 reply->sline.status,
86 (int) reply->date,
87 (int) reply->last_modified,
88 (int) reply->expires,
89 reply->content_type.size() ? reply->content_type.buf() : "unknown",
90 reply->content_length,
91 e->contentLen(),
92 RequestMethodStr(mem->method),
93 mem->log_url);
94 } else {
95 /* no mem object. Most RELEASE cases */
96 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
97 (int) current_time.tv_sec,
98 (int) current_time.tv_usec / 1000,
99 storeLogTags[tag],
100 e->swap_dirn,
101 e->swap_filen,
102 e->getMD5Text());
103 }
104 }
105
106 void
107 storeLogRotate(void)
108 {
109 if (NULL == storelog)
110 return;
111
112 logfileRotate(storelog);
113 }
114
115 void
116 storeLogClose(void)
117 {
118 if (NULL == storelog)
119 return;
120
121 logfileClose(storelog);
122
123 storelog = NULL;
124 }
125
126 static void
127 storeLogRegisterWithCacheManager(void)
128 {
129 CacheManager::GetInstance()->
130 registerAction("store_log_tags", "Histogram of store.log tags",
131 storeLogTagsHist, 0, 1);
132 }
133
134 void
135 storeLogOpen(void)
136 {
137 storeLogRegisterWithCacheManager();
138
139 if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
140 debugs(20, 1, "Store logging disabled");
141 return;
142 }
143
144 storelog = logfileOpen(Config.Log.store, 0, 1);
145 }
146
147 void
148 storeLogTagsHist(StoreEntry *e)
149 {
150 int tag;
151 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; tag++) {
152 storeAppendPrintf(e, "%s %d\n",
153 storeLogTags[tag],
154 storeLogTagsCounts[tag]);
155 }
156 }