]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_log.cc
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 20 Storage Manager Logging Functions */
12 #include "format/Token.h"
13 #include "HttpReply.h"
15 #include "MemObject.h"
16 #include "mgr/Registration.h"
17 #include "SquidConfig.h"
18 #include "SquidTime.h"
20 #include "store_log.h"
22 static const char *storeLogTags
[] = {
30 static int storeLogTagsCounts
[STORE_LOG_SWAPOUTFAIL
+1];
31 static OBJH storeLogTagsHist
;
33 static Logfile
*storelog
= NULL
;
35 static String str_unknown
;
38 storeLog(int tag
, const StoreEntry
* e
)
40 MemObject
*mem
= e
->mem_obj
;
41 HttpReply
const *reply
;
43 if (str_unknown
.size()==0)
44 str_unknown
="unknown"; //hack. Delay initialization as string doesn't support global variables..
49 ++storeLogTagsCounts
[tag
];
51 reply
= e
->getReply();
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.
58 String ctype
=(reply
->content_type
.size() ? reply
->content_type
.termedBuf() : str_unknown
);
60 logfileLineStart(storelog
);
61 logfilePrintf(storelog
, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH
" %" PRId64
"/%" PRId64
" " SQUIDSBUFPH
" %s\n",
62 (int) current_time
.tv_sec
,
63 (int) current_time
.tv_usec
/ 1000,
68 reply
->sline
.status(),
70 (int) reply
->last_modified
,
72 SQUIDSTRINGPRINT(ctype
),
73 reply
->content_length
,
75 SQUIDSBUFPRINT(mem
->method
.image()),
77 logfileLineEnd(storelog
);
79 /* no mem object. Most RELEASE cases */
80 logfileLineStart(storelog
);
81 logfilePrintf(storelog
, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
82 (int) current_time
.tv_sec
,
83 (int) current_time
.tv_usec
/ 1000,
88 logfileLineEnd(storelog
);
98 logfileRotate(storelog
, Config
.Log
.rotateNumber
);
104 if (NULL
== storelog
)
107 logfileClose(storelog
);
113 storeLogRegisterWithCacheManager(void)
115 Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
116 storeLogTagsHist
, 0, 1);
122 storeLogRegisterWithCacheManager();
124 if (Config
.Log
.store
== NULL
|| strcmp(Config
.Log
.store
, "none") == 0) {
125 debugs(20, DBG_IMPORTANT
, "Store logging disabled");
129 storelog
= logfileOpen(Config
.Log
.store
, 0, 1);
133 storeLogTagsHist(StoreEntry
*e
)
136 for (tag
= 0; tag
<= STORE_LOG_SWAPOUTFAIL
; ++tag
) {
137 storeAppendPrintf(e
, "%s %d\n",
139 storeLogTagsCounts
[tag
]);