]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_log.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / src / store_log.cc
1 /*
2 * $Id$
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-old.h"
36 #include "format/Token.h"
37 #include "HttpReply.h"
38 #include "log/File.h"
39 #include "MemObject.h"
40 #include "mgr/Registration.h"
41 #include "Store.h"
42 #include "SquidTime.h"
43
44 static const char *storeLogTags[] = {
45 "CREATE",
46 "SWAPIN",
47 "SWAPOUT",
48 "RELEASE",
49 "SO_FAIL",
50 };
51
52 static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
53 static OBJH storeLogTagsHist;
54
55 static Logfile *storelog = NULL;
56
57 static String str_unknown;
58
59 void
60 storeLog(int tag, const StoreEntry * e)
61 {
62 MemObject *mem = e->mem_obj;
63 HttpReply const *reply;
64
65 if (str_unknown.undefined())
66 str_unknown="unknown"; //hack. Delay initialization as string doesn't support global variables..
67
68 if (NULL == storelog)
69 return;
70
71 storeLogTagsCounts[tag]++;
72 if (mem != NULL) {
73 if (mem->log_url == NULL) {
74 debugs(20, 1, "storeLog: NULL log_url for " << mem->url);
75 mem->dump();
76 mem->log_url = xstrdup(mem->url);
77 }
78
79 reply = e->getReply();
80 /*
81 * XXX Ok, where should we print the dir number here?
82 * Because if we print it before the swap file number, it'll break
83 * the existing log format.
84 */
85
86 String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
87
88 logfileLineStart(storelog);
89 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %"PRId64"/%"PRId64" %s %s\n",
90 (int) current_time.tv_sec,
91 (int) current_time.tv_usec / 1000,
92 storeLogTags[tag],
93 e->swap_dirn,
94 e->swap_filen,
95 e->getMD5Text(),
96 reply->sline.status,
97 (int) reply->date,
98 (int) reply->last_modified,
99 (int) reply->expires,
100 SQUIDSTRINGPRINT(ctype),
101 reply->content_length,
102 e->contentLen(),
103 RequestMethodStr(mem->method),
104 mem->log_url);
105 logfileLineEnd(storelog);
106 } else {
107 /* no mem object. Most RELEASE cases */
108 logfileLineStart(storelog);
109 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
110 (int) current_time.tv_sec,
111 (int) current_time.tv_usec / 1000,
112 storeLogTags[tag],
113 e->swap_dirn,
114 e->swap_filen,
115 e->getMD5Text());
116 logfileLineEnd(storelog);
117 }
118 }
119
120 void
121 storeLogRotate(void)
122 {
123 if (NULL == storelog)
124 return;
125
126 logfileRotate(storelog);
127 }
128
129 void
130 storeLogClose(void)
131 {
132 if (NULL == storelog)
133 return;
134
135 logfileClose(storelog);
136
137 storelog = NULL;
138 }
139
140 static void
141 storeLogRegisterWithCacheManager(void)
142 {
143 Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
144 storeLogTagsHist, 0, 1);
145 }
146
147 void
148 storeLogOpen(void)
149 {
150 storeLogRegisterWithCacheManager();
151
152 if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
153 debugs(20, 1, "Store logging disabled");
154 return;
155 }
156
157 storelog = logfileOpen(Config.Log.store, 0, 1);
158 }
159
160 void
161 storeLogTagsHist(StoreEntry *e)
162 {
163 int tag;
164 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; tag++) {
165 storeAppendPrintf(e, "%s %d\n",
166 storeLogTags[tag],
167 storeLogTagsCounts[tag]);
168 }
169 }