]>
Commit | Line | Data |
---|---|---|
25535cbe | 1 | |
9cef6668 | 2 | /* |
47f6e231 | 3 | * $Id: store_log.cc,v 1.35 2007/08/13 17:20:51 hno Exp $ |
9cef6668 | 4 | * |
5 | * DEBUG: section 20 Storage Manager Logging Functions | |
6 | * AUTHOR: Duane Wessels | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
9cef6668 | 9 | * ---------------------------------------------------------- |
10 | * | |
2b6662ba | 11 | * Squid is the result of efforts by numerous individuals from |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
9cef6668 | 19 | * |
20 | * This program is free software; you can redistribute it and/or modify | |
21 | * it under the terms of the GNU General Public License as published by | |
22 | * the Free Software Foundation; either version 2 of the License, or | |
23 | * (at your option) any later version. | |
24 | * | |
25 | * This program is distributed in the hope that it will be useful, | |
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 | * GNU General Public License for more details. | |
29 | * | |
30 | * You should have received a copy of the GNU General Public License | |
31 | * along with this program; if not, write to the Free Software | |
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
33 | * | |
34 | */ | |
35 | ||
e3ef2b09 | 36 | #include "squid.h" |
e6ccf245 | 37 | #include "Store.h" |
528b2c61 | 38 | #include "MemObject.h" |
924f73bc | 39 | #include "HttpReply.h" |
91fabb06 | 40 | #include "CacheManager.h" |
e3ef2b09 | 41 | |
a2c963ae | 42 | static const char *storeLogTags[] = |
62e76326 | 43 | { |
44 | "CREATE", | |
45 | "SWAPIN", | |
46 | "SWAPOUT", | |
47 | "RELEASE", | |
48 | "SO_FAIL", | |
49 | }; | |
e3ef2b09 | 50 | |
91fabb06 | 51 | static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1]; |
52 | static OBJH storeLogTagsHist; | |
53 | ||
5673c2e2 | 54 | static Logfile *storelog = NULL; |
e3ef2b09 | 55 | |
56 | void | |
57 | storeLog(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 | ||
107 | void | |
108 | storeLogRotate(void) | |
109 | { | |
5673c2e2 | 110 | if (NULL == storelog) |
62e76326 | 111 | return; |
112 | ||
5673c2e2 | 113 | logfileRotate(storelog); |
e3ef2b09 | 114 | } |
115 | ||
116 | void | |
117 | storeLogClose(void) | |
118 | { | |
5673c2e2 | 119 | if (NULL == storelog) |
62e76326 | 120 | return; |
121 | ||
5673c2e2 | 122 | logfileClose(storelog); |
62e76326 | 123 | |
5673c2e2 | 124 | storelog = NULL; |
e3ef2b09 | 125 | } |
126 | ||
127 | void | |
128 | storeLogOpen(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 | |
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 | } |