]> git.ipfire.org Git - thirdparty/squid.git/blame - src/store_log.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / store_log.cc
CommitLineData
9cef6668 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
9cef6668 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9cef6668 7 */
8
bbc27441
AJ
9/* DEBUG: section 20 Storage Manager Logging Functions */
10
582c2af2 11#include "squid.h"
31971e6a 12#include "format/Token.h"
82b7abe3
AJ
13#include "HttpReply.h"
14#include "log/File.h"
15#include "MemObject.h"
8822ebee 16#include "mgr/Registration.h"
4d5904f7 17#include "SquidConfig.h"
cc192b50 18#include "SquidTime.h"
602d9612
A
19#include "Store.h"
20#include "store_log.h"
e3ef2b09 21
26ac0430
AJ
22static const char *storeLogTags[] = {
23 "CREATE",
24 "SWAPIN",
25 "SWAPOUT",
26 "RELEASE",
27 "SO_FAIL",
28};
e3ef2b09 29
91fabb06 30static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
31static OBJH storeLogTagsHist;
32
5673c2e2 33static Logfile *storelog = NULL;
e3ef2b09 34
811d914c 35static String str_unknown;
9b558d8a 36
e3ef2b09 37void
38storeLog(int tag, const StoreEntry * e)
39{
e3ef2b09 40 MemObject *mem = e->mem_obj;
528b2c61 41 HttpReply const *reply;
62e76326 42
a1377698 43 if (str_unknown.size()==0)
811d914c
FC
44 str_unknown="unknown"; //hack. Delay initialization as string doesn't support global variables..
45
5673c2e2 46 if (NULL == storelog)
62e76326 47 return;
48
5db6bf73 49 ++storeLogTagsCounts[tag];
6a80d786 50 if (mem != NULL) {
62e76326 51 reply = e->getReply();
52 /*
53 * XXX Ok, where should we print the dir number here?
54 * Because if we print it before the swap file number, it'll break
55 * the existing log format.
56 */
9b558d8a
FC
57
58 String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
59
82b7abe3 60 logfileLineStart(storelog);
7f06a3d8 61 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " " SQUIDSBUFPH " %s\n",
62e76326 62 (int) current_time.tv_sec,
63 (int) current_time.tv_usec / 1000,
64 storeLogTags[tag],
65 e->swap_dirn,
66 e->swap_filen,
67 e->getMD5Text(),
9b769c67 68 reply->sline.status(),
62e76326 69 (int) reply->date,
70 (int) reply->last_modified,
71 (int) reply->expires,
826a1fed 72 SQUIDSTRINGPRINT(ctype),
62e76326 73 reply->content_length,
b37bde1e 74 e->contentLen(),
7f06a3d8 75 SQUIDSBUFPRINT(mem->method.image()),
c877c0bc 76 mem->logUri());
82b7abe3 77 logfileLineEnd(storelog);
6a80d786 78 } else {
62e76326 79 /* no mem object. Most RELEASE cases */
82b7abe3 80 logfileLineStart(storelog);
62e76326 81 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
82 (int) current_time.tv_sec,
83 (int) current_time.tv_usec / 1000,
84 storeLogTags[tag],
85 e->swap_dirn,
86 e->swap_filen,
87 e->getMD5Text());
82b7abe3 88 logfileLineEnd(storelog);
6a80d786 89 }
e3ef2b09 90}
91
92void
93storeLogRotate(void)
94{
5673c2e2 95 if (NULL == storelog)
62e76326 96 return;
97
efc23871 98 logfileRotate(storelog, Config.Log.rotateNumber);
e3ef2b09 99}
100
101void
102storeLogClose(void)
103{
5673c2e2 104 if (NULL == storelog)
62e76326 105 return;
106
5673c2e2 107 logfileClose(storelog);
62e76326 108
5673c2e2 109 storelog = NULL;
e3ef2b09 110}
111
5f5e883f
FC
112static void
113storeLogRegisterWithCacheManager(void)
114{
8822ebee 115 Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
d9fc6862 116 storeLogTagsHist, 0, 1);
5f5e883f
FC
117}
118
e3ef2b09 119void
120storeLogOpen(void)
121{
6852be71 122 storeLogRegisterWithCacheManager();
26ac0430 123
649c2bd3 124 if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
e0236918 125 debugs(20, DBG_IMPORTANT, "Store logging disabled");
62e76326 126 return;
5673c2e2 127 }
62e76326 128
08e8e020 129 storelog = logfileOpen(Config.Log.store, 0, 1);
e3ef2b09 130}
91fabb06 131
91fabb06 132void
133storeLogTagsHist(StoreEntry *e)
134{
135 int tag;
5db6bf73 136 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; ++tag) {
26ac0430
AJ
137 storeAppendPrintf(e, "%s %d\n",
138 storeLogTags[tag],
139 storeLogTagsCounts[tag]);
91fabb06 140 }
141}
f53969cc 142