]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_log.cc
Import IPv6 support from squid3-ipv6 branch to 3-HEAD.
[thirdparty/squid.git] / src / store_log.cc
CommitLineData
9cef6668 1/*
cc192b50 2 * $Id: store_log.cc,v 1.36 2007/12/14 23:11:48 amosjeffries Exp $
9cef6668 3 *
4 * DEBUG: section 20 Storage Manager Logging Functions
5 * AUTHOR: Duane Wessels
6 *
2b6662ba 7 * SQUID Web Proxy Cache http://www.squid-cache.org/
9cef6668 8 * ----------------------------------------------------------
9 *
2b6662ba 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.
9cef6668 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
e3ef2b09 35#include "squid.h"
e6ccf245 36#include "Store.h"
528b2c61 37#include "MemObject.h"
924f73bc 38#include "HttpReply.h"
91fabb06 39#include "CacheManager.h"
cc192b50 40#include "SquidTime.h"
e3ef2b09 41
a2c963ae 42static const char *storeLogTags[] =
62e76326 43 {
44 "CREATE",
45 "SWAPIN",
46 "SWAPOUT",
47 "RELEASE",
48 "SO_FAIL",
49 };
e3ef2b09 50
91fabb06 51static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
52static OBJH storeLogTagsHist;
53
5673c2e2 54static Logfile *storelog = NULL;
e3ef2b09 55
56void
57storeLog(int tag, const StoreEntry * e)
58{
e3ef2b09 59 MemObject *mem = e->mem_obj;
528b2c61 60 HttpReply const *reply;
62e76326 61
5673c2e2 62 if (NULL == storelog)
62e76326 63 return;
64
91fabb06 65 storeLogTagsCounts[tag]++;
6a80d786 66 if (mem != NULL) {
62e76326 67 if (mem->log_url == NULL) {
bf8fe701 68 debugs(20, 1, "storeLog: NULL log_url for " << mem->url);
62e76326 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 */
47f6e231 79 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d %s %"PRId64"/%"PRId64" %s %s\n",
62e76326 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,
30abd221 90 reply->content_type.size() ? reply->content_type.buf() : "unknown",
62e76326 91 reply->content_length,
b37bde1e 92 e->contentLen(),
62e76326 93 RequestMethodStr[mem->method],
94 mem->log_url);
6a80d786 95 } else {
62e76326 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());
6a80d786 104 }
e3ef2b09 105}
106
107void
108storeLogRotate(void)
109{
5673c2e2 110 if (NULL == storelog)
62e76326 111 return;
112
5673c2e2 113 logfileRotate(storelog);
e3ef2b09 114}
115
116void
117storeLogClose(void)
118{
5673c2e2 119 if (NULL == storelog)
62e76326 120 return;
121
5673c2e2 122 logfileClose(storelog);
62e76326 123
5673c2e2 124 storelog = NULL;
e3ef2b09 125}
126
127void
128storeLogOpen(void)
129{
5673c2e2 130 if (strcmp(Config.Log.store, "none") == 0) {
bf8fe701 131 debugs(20, 1, "Store logging disabled");
62e76326 132 return;
5673c2e2 133 }
62e76326 134
08e8e020 135 storelog = logfileOpen(Config.Log.store, 0, 1);
e3ef2b09 136}
91fabb06 137
138void
139storeLogRegisterWithCacheManager(CacheManager & manager)
140{
141 manager.registerAction("store_log_tags",
142 "Histogram of store.log tags",
143 storeLogTagsHist, 0, 1);
144}
145
146void
147storeLogTagsHist(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}