Fri, 23 Oct 2015 17:28:09 +0200
implemented range requests
28 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
41
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
28 | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
41
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
29 | #ifdef __gnu_linux__ |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
30 | #define _GNU_SOURCE |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
31 | #endif |
bb7a1f5a8b48
added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
32
diff
changeset
|
32 | |
28 | 33 | #include <stdio.h> |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | #include <unistd.h> | |
37 | #include <aio.h> | |
38 | #include <time.h> | |
39 | ||
40 | #include "log.h" | |
41 | #include "../util/strbuf.h" | |
32
ebba53de8b18
added solaris 10 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
28
diff
changeset
|
42 | #include "../util/io.h" |
77 | 43 | #include "../util/atomic.h" |
28 | 44 | |
91 | 45 | #include <ucx/map.h> |
46 | ||
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
47 | static int is_initialized = 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
48 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
49 | static int log_file_fd; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
50 | static int log_level = 0; |
28 | 51 | |
52 | /* | |
53 | * if the log file is uninitialized, output is written to the ui_buffer | |
54 | */ | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
55 | static sbuf_t *ui_buffer = NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
56 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
57 | /* |
77 | 58 | * access log file map |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
59 | */ |
77 | 60 | static UcxMap *access_log_files; // map of LogFile* |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
61 | |
28 | 62 | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
63 | static char *log_date_month[] = { |
28 | 64 | "Jan", |
65 | "Feb", | |
66 | "Mar", | |
67 | "Apr", | |
68 | "May", | |
69 | "Jun", | |
70 | "Jul", | |
71 | "Aug", | |
72 | "Sep", | |
73 | "Oct", | |
74 | "Nov", | |
75 | "Dec" | |
76 | }; | |
77 | ||
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
78 | static char *log_levels[] = { |
28 | 79 | "warning", |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
80 | "config", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
81 | "security", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
82 | "failure", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
83 | "catastrophe", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
84 | "info", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
85 | "verbose" |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
86 | }; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
87 | |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
88 | static int can_log[] = { |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
89 | 1, // warning |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
90 | 1, // config |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
91 | 1, // security |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
92 | 1, // failure |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
93 | 1, // catastrophe |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
94 | 1, // info |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
95 | 0 // verbose |
28 | 96 | }; |
97 | ||
98 | int init_log_file(LogConfig *cfg) { | |
99 | if(is_initialized) { | |
100 | return 0; | |
101 | } | |
102 | ||
103 | /* open the log file */ | |
104 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; | |
105 | log_file_fd = open(cfg->file, O_WRONLY | O_CREAT | O_APPEND, mode); | |
106 | if(log_file_fd == -1) { | |
107 | return -1; | |
108 | } | |
109 | ||
110 | if(!strcmp(cfg->level, "ERROR")) { | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
111 | can_log[LOG_WARN] = 0; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
112 | can_log[LOG_INFORM] = 0; |
28 | 113 | } else if(!strcmp(cfg->level, "WARNING")) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
114 | can_log[LOG_INFORM] = 0; |
28 | 115 | } else if(!strcmp(cfg->level, "INFO")) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
116 | |
28 | 117 | } |
118 | ||
119 | if(cfg->log_stdout) { | |
120 | // TODO | |
121 | } | |
122 | if(cfg->log_stderr) { | |
123 | // TODO | |
124 | } | |
125 | ||
126 | ||
127 | is_initialized = 1; | |
128 | ||
129 | /* if ui_buffer is not NULL, write it to the log file */ | |
130 | if(ui_buffer) { | |
131 | size_t len = ui_buffer->length; | |
132 | size_t r; | |
133 | while(len > 0) { | |
134 | r = write(log_file_fd, ui_buffer->ptr, ui_buffer->length); | |
135 | len -= r; | |
136 | } | |
137 | ||
138 | sbuf_free(ui_buffer); | |
139 | } | |
140 | ||
141 | return 0; | |
142 | } | |
143 | ||
144 | void log_uninitialized_writeln(char *str, size_t len) { | |
145 | if(ui_buffer == NULL) { | |
146 | ui_buffer = sbuf_new(1024); | |
147 | if(ui_buffer == NULL) { | |
148 | return; /* TODO: critical error, exit */ | |
149 | } | |
150 | } | |
151 | ||
152 | sstr_t s; | |
153 | s.ptr = str; | |
154 | s.length = len; | |
155 | ||
156 | sbuf_append(ui_buffer, s); | |
157 | sbuf_put(ui_buffer, '\n'); | |
158 | } | |
159 | ||
160 | void log_file_writeln(char *str, size_t len) { | |
161 | if(!is_initialized) { | |
162 | log_uninitialized_writeln(str, len); | |
163 | } | |
164 | ||
165 | struct iovec io[] = { | |
166 | { str, len }, | |
167 | { "\n", 1} | |
168 | }; | |
169 | ||
170 | writev(log_file_fd, io, 2); /* TODO: aio */ | |
171 | } | |
172 | ||
173 | sstr_t log_get_prefix(int level) { | |
174 | time_t t = time(NULL); | |
175 | ||
176 | sstr_t d; | |
177 | d.ptr = NULL; | |
178 | d.length = 0; | |
179 | ||
180 | struct tm date; | |
181 | localtime_r(&t, &date); | |
182 | ||
183 | char *buf = malloc(64); | |
184 | int len = snprintf( | |
185 | buf, | |
186 | 64, | |
187 | "[%02d/%s/%d:%02d:%02d:%02d] %s : ", | |
188 | date.tm_mday, | |
189 | log_date_month[date.tm_mon], | |
190 | 1900 + date.tm_year, | |
191 | date.tm_hour, | |
192 | date.tm_min, | |
193 | date.tm_sec, | |
194 | log_levels[level]); | |
195 | ||
196 | if(len > 0) { | |
197 | d.ptr = buf; | |
198 | d.length = len; | |
199 | } | |
200 | ||
201 | return d; | |
202 | } | |
203 | ||
204 | ||
205 | /* | |
206 | * log api functions | |
207 | */ | |
208 | ||
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
209 | int log_ereport(int degree, const char *format, ...) { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
210 | va_list args; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
211 | va_start(args, format); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
212 | int ret = log_ereport_v(degree, format, args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
213 | va_end(args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
214 | return ret; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
215 | } |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
216 | |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
217 | int log_ereport_v(int degree, const char *format, va_list args) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
218 | if(degree > 6) { |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
219 | return 0; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
220 | } |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
221 | if(degree > 0 && !can_log[degree]) { |
28 | 222 | return 0; |
223 | } | |
224 | ||
225 | sstr_t lmsg; | |
226 | lmsg.ptr = NULL; | |
227 | ||
228 | /* create log message prefix */ | |
229 | sstr_t lpre = log_get_prefix(degree); | |
230 | ||
231 | /* format message */ | |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
232 | int len = vasprintf(&lmsg.ptr, format, args); |
28 | 233 | lmsg.length = len; |
234 | ||
235 | /* create message string */ | |
99 | 236 | sstr_t message = sstrcat(2, lpre, lmsg); |
28 | 237 | |
238 | /* write message to the log file */ | |
239 | log_file_writeln(message.ptr, message.length); | |
240 | ||
241 | /* cleanup */ | |
242 | free(lmsg.ptr); | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
243 | free(lpre.ptr); |
28 | 244 | free(message.ptr); |
245 | ||
246 | return 0; | |
247 | } | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
248 | |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
249 | int log_error(int degree, const char *func, Session *sn, Request *rq, |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
250 | const char *format, ...) |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
251 | { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
252 | va_list args; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
253 | va_start(args, format); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
254 | int ret = log_error_v(degree, func, sn, rq, format, args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
255 | va_end(args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
256 | return ret; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
257 | } |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
258 | |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
259 | int log_error_v(int degree, const char *func, Session *sn, Request *rq, |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
260 | const char *format, va_list args) |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
261 | { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
262 | // TODO: implement |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
263 | return log_ereport(degree, format, args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
264 | } |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
265 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
266 | |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
267 | void ws_log_assert(const char *file, const char *func, int line) { |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
268 | log_ereport( |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
269 | LOG_CATASTROPHE, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
270 | "assertion failed: %s: %s:%d", |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
271 | file, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
272 | func, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
273 | line); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
274 | exit(-1); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
275 | } |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
276 | |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
277 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
278 | /* |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
279 | * access log |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
280 | * This source file only manages access log files. IO is performed directly |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
281 | * by AddLog safs. |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
282 | */ |
77 | 283 | LogFile* get_access_log_file(sstr_t file) { |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
284 | if(!access_log_files) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
285 | access_log_files = ucx_map_new(4); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
286 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
287 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
288 | if(file.ptr == NULL || file.length == 0) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
289 | return NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
290 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
291 | |
77 | 292 | LogFile *log = ucx_map_sstr_get(access_log_files, file); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
293 | if(log != NULL) { |
77 | 294 | ws_atomic_inc32(&log->ref); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
295 | return log; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
296 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
297 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
298 | // the log file is not opened |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
299 | // check first if we can open it |
77 | 300 | FILE *out = fopen(file.ptr, "a"); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
301 | if(out == NULL) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
302 | return NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
303 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
304 | |
77 | 305 | // create LogFile object |
306 | log = calloc(1, sizeof(LogFile)); | |
307 | log->file = out; | |
308 | log->ref = 1; | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
309 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
310 | // add access log to the map |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
311 | ucx_map_sstr_put(access_log_files, file, log); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
312 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
313 | return log; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
314 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
315 |