store_log.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 "format/Token.h"
13 #include "HttpReply.h"
14 #include "log/File.h"
15 #include "MemObject.h"
16 #include "mgr/Registration.h"
17 #include "SquidConfig.h"
18 #include "SquidTime.h"
19 #include "Store.h"
20 #include "store_log.h"
21 
22 static const char *storeLogTags[] = {
23  "CREATE",
24  "SWAPIN",
25  "SWAPOUT",
26  "RELEASE",
27  "SO_FAIL",
28 };
29 
32 
33 static Logfile *storelog = NULL;
34 
36 
37 void
38 storeLog(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 (NULL == storelog)
47  return;
48 
49  ++storeLogTagsCounts[tag];
50  if (mem != NULL) {
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  */
57 
58  String ctype=(reply->content_type.size() ? reply->content_type.termedBuf() : str_unknown);
59 
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,
64  storeLogTags[tag],
65  e->swap_dirn,
66  e->swap_filen,
67  e->getMD5Text(),
68  reply->sline.status(),
69  (int) reply->date,
70  (int) reply->last_modified,
71  (int) reply->expires,
72  SQUIDSTRINGPRINT(ctype),
73  reply->content_length,
74  e->contentLen(),
75  SQUIDSBUFPRINT(mem->method.image()),
76  mem->logUri());
77  logfileLineEnd(storelog);
78  } else {
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,
84  storeLogTags[tag],
85  e->swap_dirn,
86  e->swap_filen,
87  e->getMD5Text());
88  logfileLineEnd(storelog);
89  }
90 }
91 
92 void
94 {
95  if (NULL == storelog)
96  return;
97 
99 }
100 
101 void
103 {
104  if (NULL == storelog)
105  return;
106 
107  logfileClose(storelog);
108 
109  storelog = NULL;
110 }
111 
112 static void
114 {
115  Mgr::RegisterAction("store_log_tags", "Histogram of store.log tags",
116  storeLogTagsHist, 0, 1);
117 }
118 
119 void
121 {
123 
124  if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
125  debugs(20, DBG_IMPORTANT, "Store logging disabled");
126  return;
127  }
128 
129  storelog = logfileOpen(Config.Log.store, 0, 1);
130 }
131 
132 void
134 {
135  int tag;
136  for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; ++tag) {
137  storeAppendPrintf(e, "%s %d\n",
138  storeLogTags[tag],
139  storeLogTagsCounts[tag]);
140  }
141 }
142 
sdirno swap_dirn
Definition: Store.h:179
#define SQUIDSTRINGPH
Definition: SquidString.h:20
#define SQUIDSTRINGPRINT(s)
Definition: SquidString.h:21
void logfilePrintf(Logfile *lf, const char *fmt,...)
Definition: File.cc:112
Definition: File.h:38
virtual int64_t contentLen() const
Definition: store.cc:1734
void storeLog(int tag, const StoreEntry *e)
Definition: store_log.cc:38
#define PRId64
Definition: types.h:110
static void storeLogRegisterWithCacheManager(void)
Definition: store_log.cc:113
sfileno swap_filen
unique ID inside a cache_dir for swapped out entries; -1 for others
Definition: Store.h:177
void OBJH(StoreEntry *)
Definition: forward.h:44
static String str_unknown
Definition: store_log.cc:35
const char * logUri() const
client request URI used for logging; storeId() by default
Definition: MemObject.cc:65
struct timeval current_time
Definition: stub_time.cc:15
size_type size() const
Definition: SquidString.h:71
void logfileLineEnd(Logfile *lf)
Definition: File.cc:140
char * store
Definition: SquidConfig.h:174
Logfile * logfileOpen(const char *path, size_t bufsz, int fatal_flag)
Definition: File.cc:38
int64_t content_length
Definition: Message.h:83
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
HttpRequestMethod method
Definition: MemObject.h:100
#define DBG_IMPORTANT
Definition: Debug.h:45
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
Definition: Registration.cc:16
struct SquidConfig::@103 Log
String content_type
Definition: HttpReply.h:50
virtual HttpReply const * getReply() const
Definition: store.cc:1742
static const char * storeLogTags[]
Definition: store_log.cc:22
time_t last_modified
Definition: HttpReply.h:46
void logfileClose(Logfile *lf)
Definition: File.cc:90
char const * termedBuf() const
Definition: SquidString.h:90
Http::StatusLine sline
Definition: HttpReply.h:60
MemObject * mem_obj
Definition: Store.h:162
time_t date
Definition: HttpReply.h:44
static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1]
Definition: store_log.cc:30
bool SIGHDLR int STUB void int
Definition: stub_tools.cc:68
virtual const char * getMD5Text() const
Definition: store.cc:181
const SBuf & image() const
void storeLogOpen(void)
Definition: store_log.cc:120
void logfileRotate(Logfile *lf, int16_t rotateCount)
Definition: File.cc:99
int rotateNumber
Definition: SquidConfig.h:180
time_t expires
Definition: HttpReply.h:48
void storeLogRotate(void)
Definition: store_log.cc:93
#define SQUIDSBUFPH
Definition: SBuf.h:32
void logfileLineStart(Logfile *lf)
Definition: File.cc:134
void storeLogClose(void)
Definition: store_log.cc:102
#define SQUIDSBUFPRINT(s)
Definition: SBuf.h:33
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:904
static OBJH storeLogTagsHist
Definition: store_log.cc:31
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors