]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store_log.cc
3 * $Id: store_log.cc,v 1.7 1999/05/26 17:08:04 wessels Exp $
5 * DEBUG: section 20 Storage Manager Logging Functions
6 * AUTHOR: Duane Wessels
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
15 * Duane Wessels and the University of California San Diego. Please
16 * see the COPYRIGHT file for full details. Squid incorporates
17 * software developed and/or copyrighted by other sources. Please see
18 * the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 static char *storeLogTags
[] =
46 static int storelog_fd
= -1;
49 storeLog(int tag
, const StoreEntry
* e
)
52 MemObject
*mem
= e
->mem_obj
;
58 if (mem
->log_url
== NULL
) {
59 debug(20, 1) ("storeLog: NULL log_url for %s\n", mem
->url
);
60 storeMemObjectDump(mem
);
61 mem
->log_url
= xstrdup(mem
->url
);
65 memBufPrintf(&mb
, "%9d.%03d %-7s %08X %4d %9d %9d %9d %s %d/%d %s %s\n",
66 (int) current_time
.tv_sec
,
67 (int) current_time
.tv_usec
/ 1000,
72 (int) reply
->last_modified
,
74 strBuf(reply
->content_type
) ? strBuf(reply
->content_type
) : "unknown",
75 reply
->content_length
,
76 (int) (mem
->inmem_hi
- mem
->reply
->hdr_sz
),
77 RequestMethodStr
[mem
->method
],
79 file_write_mbuf(storelog_fd
, -1, mb
, NULL
, NULL
);
87 LOCAL_ARRAY(char, from
, MAXPATHLEN
);
88 LOCAL_ARRAY(char, to
, MAXPATHLEN
);
93 if (storelog_fd
> -1) {
94 file_close(storelog_fd
);
97 if ((fname
= Config
.Log
.store
) == NULL
)
99 if (strcmp(fname
, "none") == 0)
102 if (stat(fname
, &sb
) == 0)
103 if (S_ISREG(sb
.st_mode
) == 0)
107 debug(20, 1) ("storeLogRotate: Rotating.\n");
109 /* Rotate numbers 0 through N up one */
110 for (i
= Config
.Log
.rotateNumber
; i
> 1;) {
112 snprintf(from
, MAXPATHLEN
, "%s.%d", fname
, i
- 1);
113 snprintf(to
, MAXPATHLEN
, "%s.%d", fname
, i
);
116 /* Rotate the current log to .0 */
117 if (Config
.Log
.rotateNumber
> 0) {
118 snprintf(to
, MAXPATHLEN
, "%s.%d", fname
, 0);
121 storelog_fd
= file_open(fname
, O_WRONLY
| O_CREAT
);
122 if (storelog_fd
< 0) {
123 debug(50, 0) ("storeLogRotate: %s: %s\n", fname
, xstrerror());
124 debug(20, 1) ("Store logging disabled\n");
131 if (storelog_fd
>= 0)
132 file_close(storelog_fd
);
138 if (strcmp(Config
.Log
.store
, "none") == 0)
141 storelog_fd
= file_open(Config
.Log
.store
, O_WRONLY
| O_CREAT
);
143 debug(20, 1) ("Store logging disabled\n");