Wed, 31 Jul 2013 11:35:57 +0200
fixed solaris build
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" |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
43 | #include "../ucx/map.h" |
77 | 44 | #include "../util/atomic.h" |
28 | 45 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
46 | static int is_initialized = 0; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
47 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
48 | static int log_file_fd; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
49 | static int log_level = 0; |
28 | 50 | |
51 | /* | |
52 | * if the log file is uninitialized, output is written to the ui_buffer | |
53 | */ | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
54 | static sbuf_t *ui_buffer = NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
55 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
56 | /* |
77 | 57 | * access log file map |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
58 | */ |
77 | 59 | static UcxMap *access_log_files; // map of LogFile* |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
60 | |
28 | 61 | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
62 | static char *log_date_month[] = { |
28 | 63 | "Jan", |
64 | "Feb", | |
65 | "Mar", | |
66 | "Apr", | |
67 | "May", | |
68 | "Jun", | |
69 | "Jul", | |
70 | "Aug", | |
71 | "Sep", | |
72 | "Oct", | |
73 | "Nov", | |
74 | "Dec" | |
75 | }; | |
76 | ||
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
77 | static char *log_levels[] = { |
28 | 78 | "warning", |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
79 | "config", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
80 | "security", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
81 | "failure", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
82 | "catastrophe", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
83 | "info", |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
84 | "verbose" |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
85 | }; |
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 | static int can_log[] = { |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
88 | 1, // warning |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
89 | 1, // config |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
90 | 1, // security |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
91 | 1, // failure |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
92 | 1, // catastrophe |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
93 | 1, // info |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
94 | 0 // verbose |
28 | 95 | }; |
96 | ||
97 | int init_log_file(LogConfig *cfg) { | |
98 | if(is_initialized) { | |
99 | return 0; | |
100 | } | |
101 | ||
102 | /* open the log file */ | |
103 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; | |
104 | log_file_fd = open(cfg->file, O_WRONLY | O_CREAT | O_APPEND, mode); | |
105 | if(log_file_fd == -1) { | |
106 | return -1; | |
107 | } | |
108 | ||
109 | if(!strcmp(cfg->level, "ERROR")) { | |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
110 | can_log[LOG_WARN] = 0; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
111 | can_log[LOG_INFORM] = 0; |
28 | 112 | } else if(!strcmp(cfg->level, "WARNING")) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
113 | can_log[LOG_INFORM] = 0; |
28 | 114 | } else if(!strcmp(cfg->level, "INFO")) { |
60
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
115 | |
28 | 116 | } |
117 | ||
118 | if(cfg->log_stdout) { | |
119 | // TODO | |
120 | } | |
121 | if(cfg->log_stderr) { | |
122 | // TODO | |
123 | } | |
124 | ||
125 | ||
126 | is_initialized = 1; | |
127 | ||
128 | /* if ui_buffer is not NULL, write it to the log file */ | |
129 | if(ui_buffer) { | |
130 | size_t len = ui_buffer->length; | |
131 | size_t r; | |
132 | while(len > 0) { | |
133 | r = write(log_file_fd, ui_buffer->ptr, ui_buffer->length); | |
134 | len -= r; | |
135 | } | |
136 | ||
137 | sbuf_free(ui_buffer); | |
138 | } | |
139 | ||
140 | return 0; | |
141 | } | |
142 | ||
143 | void log_uninitialized_writeln(char *str, size_t len) { | |
144 | if(ui_buffer == NULL) { | |
145 | ui_buffer = sbuf_new(1024); | |
146 | if(ui_buffer == NULL) { | |
147 | return; /* TODO: critical error, exit */ | |
148 | } | |
149 | } | |
150 | ||
151 | sstr_t s; | |
152 | s.ptr = str; | |
153 | s.length = len; | |
154 | ||
155 | sbuf_append(ui_buffer, s); | |
156 | sbuf_put(ui_buffer, '\n'); | |
157 | } | |
158 | ||
159 | void log_file_writeln(char *str, size_t len) { | |
160 | if(!is_initialized) { | |
161 | log_uninitialized_writeln(str, len); | |
162 | } | |
163 | ||
164 | struct iovec io[] = { | |
165 | { str, len }, | |
166 | { "\n", 1} | |
167 | }; | |
168 | ||
169 | writev(log_file_fd, io, 2); /* TODO: aio */ | |
170 | } | |
171 | ||
172 | sstr_t log_get_prefix(int level) { | |
173 | time_t t = time(NULL); | |
174 | ||
175 | sstr_t d; | |
176 | d.ptr = NULL; | |
177 | d.length = 0; | |
178 | ||
179 | struct tm date; | |
180 | localtime_r(&t, &date); | |
181 | ||
182 | char *buf = malloc(64); | |
183 | int len = snprintf( | |
184 | buf, | |
185 | 64, | |
186 | "[%02d/%s/%d:%02d:%02d:%02d] %s : ", | |
187 | date.tm_mday, | |
188 | log_date_month[date.tm_mon], | |
189 | 1900 + date.tm_year, | |
190 | date.tm_hour, | |
191 | date.tm_min, | |
192 | date.tm_sec, | |
193 | log_levels[level]); | |
194 | ||
195 | if(len > 0) { | |
196 | d.ptr = buf; | |
197 | d.length = len; | |
198 | } | |
199 | ||
200 | return d; | |
201 | } | |
202 | ||
203 | ||
204 | /* | |
205 | * log api functions | |
206 | */ | |
207 | ||
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
208 | int log_ereport(int degree, const char *format, ...) { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
209 | va_list args; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
210 | va_start(args, format); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
211 | int ret = log_ereport_v(degree, format, args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
212 | va_end(args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
213 | return ret; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
214 | } |
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 | 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
|
217 | if(degree > 6) { |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
218 | return 0; |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
219 | } |
feb2f1e115c6
improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
220 | if(degree > 0 && !can_log[degree]) { |
28 | 221 | return 0; |
222 | } | |
223 | ||
224 | sstr_t lmsg; | |
225 | lmsg.ptr = NULL; | |
226 | ||
227 | /* create log message prefix */ | |
228 | sstr_t lpre = log_get_prefix(degree); | |
229 | ||
230 | /* format message */ | |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
231 | int len = vasprintf(&lmsg.ptr, format, args); |
28 | 232 | lmsg.length = len; |
233 | ||
234 | /* create message string */ | |
235 | sstr_t message; | |
236 | message.length = lpre.length + len; | |
237 | message.ptr = malloc(message.length + 1); | |
238 | ||
239 | message = sstrncat(2, message, lpre, lmsg); | |
240 | ||
241 | /* write message to the log file */ | |
242 | log_file_writeln(message.ptr, message.length); | |
243 | ||
244 | /* cleanup */ | |
245 | free(lmsg.ptr); | |
79
f48cea237ec3
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
246 | free(lpre.ptr); |
28 | 247 | free(message.ptr); |
248 | ||
249 | return 0; | |
250 | } | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
251 | |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
252 | 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
|
253 | const char *format, ...) |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
254 | { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
255 | va_list args; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
256 | va_start(args, format); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
257 | 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
|
258 | va_end(args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
259 | return ret; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
260 | } |
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 | 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
|
263 | const char *format, va_list 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 | // TODO: implement |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
266 | return log_ereport(degree, format, args); |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
267 | } |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
79
diff
changeset
|
268 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
269 | |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
270 | 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
|
271 | log_ereport( |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
272 | LOG_CATASTROPHE, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
273 | "assertion failed: %s: %s:%d", |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
274 | file, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
275 | func, |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
276 | line); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
277 | exit(-1); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
278 | } |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
279 | |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
280 | |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
281 | /* |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
282 | * access log |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
283 | * 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
|
284 | * by AddLog safs. |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
285 | */ |
77 | 286 | LogFile* get_access_log_file(sstr_t file) { |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
287 | if(!access_log_files) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
288 | access_log_files = ucx_map_new(4); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
289 | } |
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 | if(file.ptr == NULL || file.length == 0) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
292 | return NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
293 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
294 | |
77 | 295 | 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
|
296 | if(log != NULL) { |
77 | 297 | ws_atomic_inc32(&log->ref); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
298 | return log; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
299 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
300 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
301 | // the log file is not opened |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
302 | // check first if we can open it |
77 | 303 | FILE *out = fopen(file.ptr, "a"); |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
304 | if(out == NULL) { |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
305 | return NULL; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
306 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
307 | |
77 | 308 | // create LogFile object |
309 | log = calloc(1, sizeof(LogFile)); | |
310 | log->file = out; | |
311 | log->ref = 1; | |
45
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 | // add access log to the map |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
314 | ucx_map_sstr_put(access_log_files, file, log); |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
315 | |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
316 | return log; |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
317 | } |
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
318 |