store_log.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9/* DEBUG: section 20 Storage Manager Logging Functions */
10
11#include "squid.h"
12#include "debug/Messages.h"
13#include "format/Token.h"
14#include "HttpReply.h"
15#include "log/File.h"
16#include "MemObject.h"
17#include "mgr/Registration.h"
18#include "SquidConfig.h"
19#include "Store.h"
20#include "store_log.h"
21
22static const char *storeLogTags[] = {
23 "CREATE",
24 "SWAPIN",
25 "SWAPOUT",
26 "RELEASE",
27 "SO_FAIL",
28};
29
32
33static Logfile *storelog = nullptr;
34
36
37void
38storeLog(int tag, const StoreEntry * e)
39{
40 MemObject *mem = e->mem_obj;
41 HttpReply const *reply;
42
43 if (str_unknown.size()==0)
44 str_unknown="unknown"; //hack. Delay initialization as string doesn't support global variables..
45
46 if (nullptr == storelog)
47 return;
48
49 ++storeLogTagsCounts[tag];
50 if (mem != nullptr) {
51 reply = &mem->freshestReply();
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 */
57
58 String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
59
60 // mem_obj may still lack logging details; especially in RELEASE cases
61 const char *logUri = mem->hasUris() ? mem->logUri() : "?";
62
64 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d " SQUIDSTRINGPH " %" PRId64 "/%" PRId64 " " SQUIDSBUFPH " %s\n",
65 (int) current_time.tv_sec,
66 (int) current_time.tv_usec / 1000,
67 storeLogTags[tag],
68 e->swap_dirn,
69 e->swap_filen,
70 e->getMD5Text(),
71 reply->sline.status(),
72 (int) reply->date,
73 (int) reply->last_modified,
74 (int) reply->expires,
75 SQUIDSTRINGPRINT(ctype),
76 reply->content_length,
77 e->contentLen(),
79 logUri);
81 } else {
82 /* no mem object. Most RELEASE cases */
84 logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s ? ? ? ? ?/? ?/? ? ?\n",
85 (int) current_time.tv_sec,
86 (int) current_time.tv_usec / 1000,
87 storeLogTags[tag],
88 e->swap_dirn,
89 e->swap_filen,
90 e->getMD5Text());
92 }
93}
94
95void
97{
98 if (nullptr == storelog)
99 return;
100
102}
103
104void
106{
107 if (nullptr == storelog)
108 return;
109
111
112 storelog = nullptr;
113}
114
115static void
117{
118 Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
119 storeLogTagsHist, 0, 1);
120}
121
122void
124{
126
127 if (Config.Log.store == nullptr || strcmp(Config.Log.store, "none") == 0) {
128 debugs(20, Important(42), "Store logging disabled");
129 return;
130 }
131
133}
134
135void
137{
138 int tag;
139 for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; ++tag) {
140 storeAppendPrintf(e, "%s %d\n",
141 storeLogTags[tag],
142 storeLogTagsCounts[tag]);
143 }
144}
145
#define SQUIDSBUFPH
Definition: SBuf.h:31
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:32
class SquidConfig Config
Definition: SquidConfig.cc:12
#define SQUIDSTRINGPH
Definition: SquidString.h:21
#define SQUIDSTRINGPRINT(s)
Definition: SquidString.h:22
Http::StatusLine sline
Definition: HttpReply.h:56
String content_type
Definition: HttpReply.h:46
time_t last_modified
Definition: HttpReply.h:42
time_t date
Definition: HttpReply.h:40
time_t expires
Definition: HttpReply.h:44
const SBuf & image() const
int64_t content_length
Definition: Message.h:83
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
Definition: File.h:39
HttpRequestMethod method
Definition: MemObject.h:147
const HttpReply & freshestReply() const
Definition: MemObject.h:68
bool hasUris() const
whether setUris() has been called
Definition: MemObject.cc:70
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:64
char * store
Definition: SquidConfig.h:184
struct SquidConfig::@98 Log
int rotateNumber
Definition: SquidConfig.h:191
sdirno swap_dirn
Definition: Store.h:238
const char * getMD5Text() const
Definition: store.cc:206
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:236
MemObject * mem_obj
Definition: Store.h:221
int64_t contentLen() const
Definition: Store.h:258
char const * termedBuf() const
Definition: SquidString.h:92
size_type size() const
Definition: SquidString.h:73
#define Important(id)
Definition: Messages.h:93
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
@ STORE_LOG_SWAPOUTFAIL
Definition: enums.h:160
void logfileLineEnd(Logfile *lf)
Definition: File.cc:132
void logfileRotate(Logfile *lf, int16_t rotateCount)
Definition: File.cc:101
void logfileLineStart(Logfile *lf)
Definition: File.cc:126
void logfileClose(Logfile *lf)
Definition: File.cc:92
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:114
Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag)
Definition: File.cc:40
void OBJH(StoreEntry *)
Definition: forward.h:44
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:841
static OBJH storeLogTagsHist
Definition: store_log.cc:31
static String str_unknown
Definition: store_log.cc:35
void storeLogClose(void)
Definition: store_log.cc:105
void storeLogOpen(void)
Definition: store_log.cc:123
static void storeLogRegisterWithCacheManager(void)
Definition: store_log.cc:116
void storeLogRotate(void)
Definition: store_log.cc:96
static Logfile * storelog
Definition: store_log.cc:33
static const char * storeLogTags[]
Definition: store_log.cc:22
static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1]
Definition: store_log.cc:30
void storeLog(int tag, const StoreEntry *e)
Definition: store_log.cc:38
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17
#define PRId64
Definition: types.h:104

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors