]>
Commit | Line | Data |
---|---|---|
9cef6668 | 1 | /* |
262a0e14 | 2 | * $Id$ |
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. | |
26ac0430 | 23 | * |
9cef6668 | 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. | |
26ac0430 | 28 | * |
9cef6668 | 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 | ||
f7f3304a | 35 | #include "squid-old.h" |
31971e6a | 36 | #include "format/Token.h" |
82b7abe3 AJ |
37 | #include "HttpReply.h" |
38 | #include "log/File.h" | |
39 | #include "MemObject.h" | |
8822ebee | 40 | #include "mgr/Registration.h" |
82b7abe3 | 41 | #include "Store.h" |
cc192b50 | 42 | #include "SquidTime.h" |
e3ef2b09 | 43 | |
26ac0430 AJ |
44 | static const char *storeLogTags[] = { |
45 | "CREATE", | |
46 | "SWAPIN", | |
47 | "SWAPOUT", | |
48 | "RELEASE", | |
49 | "SO_FAIL", | |
50 | }; | |
e3ef2b09 | 51 | |
91fabb06 | 52 | static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1]; |
53 | static OBJH storeLogTagsHist; | |
54 | ||
5673c2e2 | 55 | static Logfile *storelog = NULL; |
e3ef2b09 | 56 | |
811d914c | 57 | static String str_unknown; |
9b558d8a | 58 | |
e3ef2b09 | 59 | void |
60 | storeLog(int tag, const StoreEntry * e) | |
61 | { | |
e3ef2b09 | 62 | MemObject *mem = e->mem_obj; |
528b2c61 | 63 | HttpReply const *reply; |
62e76326 | 64 | |
811d914c FC |
65 | if (str_unknown.undefined()) |
66 | str_unknown="unknown"; //hack. Delay initialization as string doesn't support global variables.. | |
67 | ||
5673c2e2 | 68 | if (NULL == storelog) |
62e76326 | 69 | return; |
70 | ||
91fabb06 | 71 | storeLogTagsCounts[tag]++; |
6a80d786 | 72 | if (mem != NULL) { |
62e76326 | 73 | if (mem->log_url == NULL) { |
bf8fe701 | 74 | debugs(20, 1, "storeLog: NULL log_url for " << mem->url); |
62e76326 | 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 | */ | |
9b558d8a FC |
85 | |
86 | String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown); | |
87 | ||
82b7abe3 | 88 | logfileLineStart(storelog); |
826a1fed | 89 | logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %"PRId64"/%"PRId64" %s %s\n", |
62e76326 | 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, | |
826a1fed | 100 | SQUIDSTRINGPRINT(ctype), |
62e76326 | 101 | reply->content_length, |
b37bde1e | 102 | e->contentLen(), |
60745f24 | 103 | RequestMethodStr(mem->method), |
62e76326 | 104 | mem->log_url); |
82b7abe3 | 105 | logfileLineEnd(storelog); |
6a80d786 | 106 | } else { |
62e76326 | 107 | /* no mem object. Most RELEASE cases */ |
82b7abe3 | 108 | logfileLineStart(storelog); |
62e76326 | 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()); | |
82b7abe3 | 116 | logfileLineEnd(storelog); |
6a80d786 | 117 | } |
e3ef2b09 | 118 | } |
119 | ||
120 | void | |
121 | storeLogRotate(void) | |
122 | { | |
5673c2e2 | 123 | if (NULL == storelog) |
62e76326 | 124 | return; |
125 | ||
5673c2e2 | 126 | logfileRotate(storelog); |
e3ef2b09 | 127 | } |
128 | ||
129 | void | |
130 | storeLogClose(void) | |
131 | { | |
5673c2e2 | 132 | if (NULL == storelog) |
62e76326 | 133 | return; |
134 | ||
5673c2e2 | 135 | logfileClose(storelog); |
62e76326 | 136 | |
5673c2e2 | 137 | storelog = NULL; |
e3ef2b09 | 138 | } |
139 | ||
5f5e883f FC |
140 | static void |
141 | storeLogRegisterWithCacheManager(void) | |
142 | { | |
8822ebee | 143 | Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags", |
d9fc6862 | 144 | storeLogTagsHist, 0, 1); |
5f5e883f FC |
145 | } |
146 | ||
e3ef2b09 | 147 | void |
148 | storeLogOpen(void) | |
149 | { | |
6852be71 | 150 | storeLogRegisterWithCacheManager(); |
26ac0430 | 151 | |
649c2bd3 | 152 | if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) { |
bf8fe701 | 153 | debugs(20, 1, "Store logging disabled"); |
62e76326 | 154 | return; |
5673c2e2 | 155 | } |
62e76326 | 156 | |
08e8e020 | 157 | storelog = logfileOpen(Config.Log.store, 0, 1); |
e3ef2b09 | 158 | } |
91fabb06 | 159 | |
91fabb06 | 160 | void |
161 | storeLogTagsHist(StoreEntry *e) | |
162 | { | |
163 | int tag; | |
164 | for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; tag++) { | |
26ac0430 AJ |
165 | storeAppendPrintf(e, "%s %d\n", |
166 | storeLogTags[tag], | |
167 | storeLogTagsCounts[tag]); | |
91fabb06 | 168 | } |
169 | } |