]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_log.cc
Prep for 3.3.12 and 3.4.4
[thirdparty/squid.git] / src / store_log.cc
CommitLineData
9cef6668 1/*
9cef6668 2 * DEBUG: section 20 Storage Manager Logging Functions
3 * AUTHOR: Duane Wessels
4 *
2b6662ba 5 * SQUID Web Proxy Cache http://www.squid-cache.org/
9cef6668 6 * ----------------------------------------------------------
7 *
2b6662ba 8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
9cef6668 16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
26ac0430 21 *
9cef6668 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26ac0430 26 *
9cef6668 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
582c2af2 33#include "squid.h"
31971e6a 34#include "format/Token.h"
82b7abe3
AJ
35#include "HttpReply.h"
36#include "log/File.h"
37#include "MemObject.h"
8822ebee 38#include "mgr/Registration.h"
4d5904f7 39#include "SquidConfig.h"
cc192b50 40#include "SquidTime.h"
602d9612
A
41#include "Store.h"
42#include "store_log.h"
e3ef2b09 43
26ac0430
AJ
44static const char *storeLogTags[] = {
45 "CREATE",
46 "SWAPIN",
47 "SWAPOUT",
48 "RELEASE",
49 "SO_FAIL",
50};
e3ef2b09 51
91fabb06 52static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
53static OBJH storeLogTagsHist;
54
5673c2e2 55static Logfile *storelog = NULL;
e3ef2b09 56
811d914c 57static String str_unknown;
9b558d8a 58
e3ef2b09 59void
60storeLog(int tag, const StoreEntry * e)
61{
e3ef2b09 62 MemObject *mem = e->mem_obj;
528b2c61 63 HttpReply const *reply;
62e76326 64
a1377698 65 if (str_unknown.size()==0)
811d914c
FC
66 str_unknown="unknown"; //hack. Delay initialization as string doesn't support global variables..
67
5673c2e2 68 if (NULL == storelog)
62e76326 69 return;
70
5db6bf73 71 ++storeLogTagsCounts[tag];
6a80d786 72 if (mem != NULL) {
62e76326 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 */
9b558d8a
FC
79
80 String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
81
82b7abe3 82 logfileLineStart(storelog);
c91ca3ce 83 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " %s %s\n",
62e76326 84 (int) current_time.tv_sec,
85 (int) current_time.tv_usec / 1000,
86 storeLogTags[tag],
87 e->swap_dirn,
88 e->swap_filen,
89 e->getMD5Text(),
9b769c67 90 reply->sline.status(),
62e76326 91 (int) reply->date,
92 (int) reply->last_modified,
93 (int) reply->expires,
826a1fed 94 SQUIDSTRINGPRINT(ctype),
62e76326 95 reply->content_length,
b37bde1e 96 e->contentLen(),
60745f24 97 RequestMethodStr(mem->method),
c877c0bc 98 mem->logUri());
82b7abe3 99 logfileLineEnd(storelog);
6a80d786 100 } else {
62e76326 101 /* no mem object. Most RELEASE cases */
82b7abe3 102 logfileLineStart(storelog);
62e76326 103 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
104 (int) current_time.tv_sec,
105 (int) current_time.tv_usec / 1000,
106 storeLogTags[tag],
107 e->swap_dirn,
108 e->swap_filen,
109 e->getMD5Text());
82b7abe3 110 logfileLineEnd(storelog);
6a80d786 111 }
e3ef2b09 112}
113
114void
115storeLogRotate(void)
116{
5673c2e2 117 if (NULL == storelog)
62e76326 118 return;
119
5673c2e2 120 logfileRotate(storelog);
e3ef2b09 121}
122
123void
124storeLogClose(void)
125{
5673c2e2 126 if (NULL == storelog)
62e76326 127 return;
128
5673c2e2 129 logfileClose(storelog);
62e76326 130
5673c2e2 131 storelog = NULL;
e3ef2b09 132}
133
5f5e883f
FC
134static void
135storeLogRegisterWithCacheManager(void)
136{
8822ebee 137 Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
d9fc6862 138 storeLogTagsHist, 0, 1);
5f5e883f
FC
139}
140
e3ef2b09 141void
142storeLogOpen(void)
143{
6852be71 144 storeLogRegisterWithCacheManager();
26ac0430 145
649c2bd3 146 if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
e0236918 147 debugs(20, DBG_IMPORTANT, "Store logging disabled");
62e76326 148 return;
5673c2e2 149 }
62e76326 150
08e8e020 151 storelog = logfileOpen(Config.Log.store, 0, 1);
e3ef2b09 152}
91fabb06 153
91fabb06 154void
155storeLogTagsHist(StoreEntry *e)
156{
157 int tag;
5db6bf73 158 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; ++tag) {
26ac0430
AJ
159 storeAppendPrintf(e, "%s %d\n",
160 storeLogTags[tag],
161 storeLogTagsCounts[tag]);
91fabb06 162 }
163}