]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/store_log.cc
Cleanup: zap CVS Id tags
[thirdparty/squid.git] / src / store_log.cc
index 9a2f1c0ea54b8a21771ad8544d6a704e870cd6c7..7392a1c448f2cfe205c0819a55b73c3376af02f0 100644 (file)
@@ -1,32 +1,31 @@
-
 /*
- * $Id: store_log.cc,v 1.8 1999/08/02 06:18:46 wessels Exp $
+ * $Id$
  *
  * DEBUG: section 20    Storage Manager Logging Functions
  * AUTHOR: Duane Wessels
  *
- * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
  * ----------------------------------------------------------
  *
- *  Squid is the result of efforts by numerous individuals from the
- *  Internet community.  Development is led by Duane Wessels of the
- *  National Laboratory for Applied Network Research and funded by the
- *  National Science Foundation.  Squid is Copyrighted (C) 1998 by
- *  Duane Wessels and the University of California San Diego.  Please
- *  see the COPYRIGHT file for full details.  Squid incorporates
- *  software developed and/or copyrighted by other sources.  Please see
- *  the CREDITS file for full details.
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  */
 
 #include "squid.h"
+#include "Store.h"
+#include "MemObject.h"
+#include "HttpReply.h"
+#include "CacheManager.h"
+#include "SquidTime.h"
 
-static char *storeLogTags[] =
-{
+static const char *storeLogTags[] = {
     "CREATE",
     "SWAPIN",
     "SWAPOUT",
-    "RELEASE"
+    "RELEASE",
+    "SO_FAIL",
 };
 
-static int storelog_fd = -1;
+static int storeLogTagsCounts[STORE_LOG_SWAPOUTFAIL+1];
+static OBJH storeLogTagsHist;
+
+static Logfile *storelog = NULL;
 
 void
 storeLog(int tag, const StoreEntry * e)
 {
-    MemBuf mb;
     MemObject *mem = e->mem_obj;
-    HttpReply *reply;
-    if (storelog_fd < 0)
-       return;
-    if (mem == NULL)
-       return;
-    if (mem->log_url == NULL) {
-       debug(20, 1) ("storeLog: NULL log_url for %s\n", mem->url);
-       storeMemObjectDump(mem);
-       mem->log_url = xstrdup(mem->url);
+    HttpReply const *reply;
+
+    if (NULL == storelog)
+        return;
+
+    storeLogTagsCounts[tag]++;
+    if (mem != NULL) {
+        if (mem->log_url == NULL) {
+            debugs(20, 1, "storeLog: NULL log_url for " << mem->url);
+            mem->dump();
+            mem->log_url = xstrdup(mem->url);
+        }
+
+        reply = e->getReply();
+        /*
+         * XXX Ok, where should we print the dir number here?
+         * Because if we print it before the swap file number, it'll break
+         * the existing log format.
+         */
+        logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s %4d %9d %9d %9d %s %"PRId64"/%"PRId64" %s %s\n",
+                      (int) current_time.tv_sec,
+                      (int) current_time.tv_usec / 1000,
+                      storeLogTags[tag],
+                      e->swap_dirn,
+                      e->swap_filen,
+                      e->getMD5Text(),
+                      reply->sline.status,
+                      (int) reply->date,
+                      (int) reply->last_modified,
+                      (int) reply->expires,
+                      reply->content_type.size() ? reply->content_type.buf() : "unknown",
+                      reply->content_length,
+                      e->contentLen(),
+                      RequestMethodStr(mem->method),
+                      mem->log_url);
+    } else {
+        /* no mem object. Most RELEASE cases */
+        logfilePrintf(storelog, "%9d.%03d %-7s %02d %08X %s   ?         ?         ?         ? ?/? ?/? ? ?\n",
+                      (int) current_time.tv_sec,
+                      (int) current_time.tv_usec / 1000,
+                      storeLogTags[tag],
+                      e->swap_dirn,
+                      e->swap_filen,
+                      e->getMD5Text());
     }
-    memBufDefInit(&mb);
-    reply = mem->reply;
-    memBufPrintf(&mb, "%9d.%03d %-7s %08X %4d %9d %9d %9d %s %d/%d %s %s\n",
-       (int) current_time.tv_sec,
-       (int) current_time.tv_usec / 1000,
-       storeLogTags[tag],
-       e->swap_file_number,
-       reply->sline.status,
-       (int) reply->date,
-       (int) reply->last_modified,
-       (int) reply->expires,
-       strBuf(reply->content_type) ? strBuf(reply->content_type) : "unknown",
-       reply->content_length,
-       (int) (mem->inmem_hi - mem->reply->hdr_sz),
-       RequestMethodStr[mem->method],
-       mem->log_url);
-    file_write_mbuf(storelog_fd, -1, mb, NULL, NULL);
 }
 
 void
 storeLogRotate(void)
 {
-    char *fname = NULL;
-    int i;
-    LOCAL_ARRAY(char, from, MAXPATHLEN);
-    LOCAL_ARRAY(char, to, MAXPATHLEN);
-#ifdef S_ISREG
-    struct stat sb;
-#endif
-
-    if (storelog_fd > -1) {
-       file_close(storelog_fd);
-       storelog_fd = -1;
-    }
-    if ((fname = Config.Log.store) == NULL)
-       return;
-    if (strcmp(fname, "none") == 0)
-       return;
-#ifdef S_ISREG
-    if (stat(fname, &sb) == 0)
-       if (S_ISREG(sb.st_mode) == 0)
-           return;
-#endif
-
-    debug(20, 1) ("storeLogRotate: Rotating.\n");
-
-    /* Rotate numbers 0 through N up one */
-    for (i = Config.Log.rotateNumber; i > 1;) {
-       i--;
-       snprintf(from, MAXPATHLEN, "%s.%d", fname, i - 1);
-       snprintf(to, MAXPATHLEN, "%s.%d", fname, i);
-       xrename(from, to);
-    }
-    /* Rotate the current log to .0 */
-    if (Config.Log.rotateNumber > 0) {
-       snprintf(to, MAXPATHLEN, "%s.%d", fname, 0);
-       xrename(fname, to);
-    }
-    storelog_fd = file_open(fname, O_WRONLY | O_CREAT);
-    if (storelog_fd < 0) {
-       debug(50, 0) ("storeLogRotate: %s: %s\n", fname, xstrerror());
-       debug(20, 1) ("Store logging disabled\n");
-    }
+    if (NULL == storelog)
+        return;
+
+    logfileRotate(storelog);
 }
 
 void
 storeLogClose(void)
 {
-    if (storelog_fd >= 0)
-       file_close(storelog_fd);
+    if (NULL == storelog)
+        return;
+
+    logfileClose(storelog);
+
+    storelog = NULL;
+}
+
+static void
+storeLogRegisterWithCacheManager(void)
+{
+    CacheManager::GetInstance()->
+    registerAction("store_log_tags", "Histogram of store.log tags",
+                   storeLogTagsHist, 0, 1);
 }
 
 void
 storeLogOpen(void)
 {
-    if (strcmp(Config.Log.store, "none") == 0)
-       storelog_fd = -1;
-    else
-       storelog_fd = file_open(Config.Log.store, O_WRONLY | O_CREAT);
-    if (storelog_fd < 0)
-       debug(20, 1) ("Store logging disabled\n");
+    storeLogRegisterWithCacheManager();
+
+    if (Config.Log.store == NULL || strcmp(Config.Log.store, "none") == 0) {
+        debugs(20, 1, "Store logging disabled");
+        return;
+    }
+
+    storelog = logfileOpen(Config.Log.store, 0, 1);
+}
+
+void
+storeLogTagsHist(StoreEntry *e)
+{
+    int tag;
+    for (tag = 0; tag <= STORE_LOG_SWAPOUTFAIL; tag++) {
+        storeAppendPrintf(e, "%s %d\n",
+                          storeLogTags[tag],
+                          storeLogTagsCounts[tag]);
+    }
 }