1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * http_log.c: Dealing with the logs and errors
25 #include "apr_general.h" /* for signal stuff */
26 #include "apr_strings.h"
27 #include "apr_errno.h"
28 #include "apr_thread_proc.h"
30 #include "apr_signal.h"
31 #include "apr_portable.h"
32 #include "apr_base64.h"
34 #define APR_WANT_STDIO
35 #define APR_WANT_STRFUNC
44 #if APR_HAVE_PROCESS_H
45 #include <process.h> /* for getpid() on Win32 */
48 #include "ap_config.h"
50 #include "http_config.h"
51 #include "http_core.h"
53 #include "http_main.h"
54 #include "util_time.h"
58 #include <sys/syscall.h>
59 #include <sys/types.h>
62 /* we know core's module_index is 0 */
63 #undef APLOG_MODULE_INDEX
64 #define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
72 APR_HOOK_LINK(error_log)
73 APR_HOOK_LINK(generate_log_id)
76 int AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
80 static const TRANS facilities[] = {
83 {"authpriv",LOG_AUTHPRIV},
89 {"daemon", LOG_DAEMON},
107 {"syslog", LOG_SYSLOG},
116 {"local0", LOG_LOCAL0},
119 {"local1", LOG_LOCAL1},
122 {"local2", LOG_LOCAL2},
125 {"local3", LOG_LOCAL3},
128 {"local4", LOG_LOCAL4},
131 {"local5", LOG_LOCAL5},
134 {"local6", LOG_LOCAL6},
137 {"local7", LOG_LOCAL7},
143 static const TRANS priorities[] = {
144 {"emerg", APLOG_EMERG},
145 {"alert", APLOG_ALERT},
146 {"crit", APLOG_CRIT},
147 {"error", APLOG_ERR},
148 {"warn", APLOG_WARNING},
149 {"notice", APLOG_NOTICE},
150 {"info", APLOG_INFO},
151 {"debug", APLOG_DEBUG},
152 {"trace1", APLOG_TRACE1},
153 {"trace2", APLOG_TRACE2},
154 {"trace3", APLOG_TRACE3},
155 {"trace4", APLOG_TRACE4},
156 {"trace5", APLOG_TRACE5},
157 {"trace6", APLOG_TRACE6},
158 {"trace7", APLOG_TRACE7},
159 {"trace8", APLOG_TRACE8},
163 static apr_pool_t *stderr_pool = NULL;
165 static apr_file_t *stderr_log = NULL;
167 /* track pipe handles to close in child process */
168 typedef struct read_handle_t {
169 struct read_handle_t *next;
173 static read_handle_t *read_handles;
176 * @brief The piped logging structure.
178 * Piped logs are used to move functionality out of the main server.
179 * For example, log rotation is done with piped logs.
182 /** The pool to use for the piped log */
184 /** The pipe between the server and the logging process */
185 apr_file_t *read_fd, *write_fd;
186 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
187 /** The name of the program the logging process is running */
189 /** The pid of the logging process */
191 /** How to reinvoke program when it must be replaced */
192 apr_cmdtype_e cmdtype;
196 AP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl)
201 AP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl)
206 /* remember to close this handle in the child process
208 * On Win32 this makes zero sense, because we don't
209 * take the parent process's child procs.
210 * If the win32 parent instead passed each and every
211 * logger write handle from itself down to the child,
212 * and the parent manages all aspects of keeping the
213 * reliable pipe log children alive, this would still
214 * make no sense :) Cripple it on Win32.
216 static void close_handle_in_child(apr_pool_t *p, apr_file_t *f)
219 read_handle_t *new_handle;
221 new_handle = apr_pcalloc(p, sizeof(read_handle_t));
222 new_handle->next = read_handles;
223 new_handle->handle = f;
224 read_handles = new_handle;
228 void ap_logs_child_init(apr_pool_t *p, server_rec *s)
230 read_handle_t *cur = read_handles;
233 apr_file_close(cur->handle);
238 AP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p)
240 apr_file_open_stderr(&stderr_log, p);
243 AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
246 apr_file_t *stderr_file;
248 char *filename = ap_server_root_relative(p, fname);
250 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
251 APR_EBADPATH, NULL, APLOGNO(00085) "Invalid -E error log file %s",
255 if ((rc = apr_file_open(&stderr_file, filename,
256 APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE,
257 APR_OS_DEFAULT, p)) != APR_SUCCESS) {
258 ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00086)
259 "%s: could not open error log file %s.",
260 ap_server_argv0, fname);
264 /* This is safe provided we revert it when we are finished.
265 * We don't manager the callers pool!
269 if ((rc = apr_file_open_stderr(&stderr_log, stderr_pool))
271 apr_file_flush(stderr_log);
272 if ((rc = apr_file_dup2(stderr_log, stderr_file, stderr_pool))
274 apr_file_close(stderr_file);
276 * You might ponder why stderr_pool should survive?
277 * The trouble is, stderr_pool may have s_main->error_log,
278 * so we aren't in a position to destory stderr_pool until
279 * the next recycle. There's also an apparent bug which
280 * is not; if some folk decided to call this function before
281 * the core open error logs hook, this pool won't survive.
282 * Neither does the stderr logger, so this isn't a problem.
286 /* Revert, see above */
287 if (stderr_pool == p)
290 if (rc != APR_SUCCESS) {
291 ap_log_error(APLOG_MARK, APLOG_CRIT, rc, NULL, APLOGNO(00087)
292 "unable to replace stderr with error log file");
297 static void log_child_errfn(apr_pool_t *pool, apr_status_t err,
298 const char *description)
300 ap_log_error(APLOG_MARK, APLOG_ERR, err, NULL, APLOGNO(00088)
304 /* Create a child process running PROGNAME with a pipe connected to
305 * the childs stdin. The write-end of the pipe will be placed in
306 * *FPIN on successful return. If dummy_stderr is non-zero, the
307 * stderr for the child will be the same as the stdout of the parent.
308 * Otherwise the child will inherit the stderr from the parent. */
309 static int log_child(apr_pool_t *p, const char *progname,
310 apr_file_t **fpin, apr_cmdtype_e cmdtype,
313 /* Child process code for 'ErrorLog "|..."';
314 * may want a common framework for this, since I expect it will
315 * be common for other foo-loggers to want this sort of thing...
318 apr_procattr_t *procattr;
322 if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
323 && ((rc = apr_procattr_dir_set(procattr,
324 ap_server_root)) == APR_SUCCESS)
325 && ((rc = apr_procattr_cmdtype_set(procattr, cmdtype)) == APR_SUCCESS)
326 && ((rc = apr_procattr_io_set(procattr,
329 APR_NO_PIPE)) == APR_SUCCESS)
330 && ((rc = apr_procattr_error_check_set(procattr, 1)) == APR_SUCCESS)
331 && ((rc = apr_procattr_child_errfn_set(procattr, log_child_errfn))
335 apr_tokenize_to_argv(progname, &args, p);
336 procnew = (apr_proc_t *)apr_pcalloc(p, sizeof(*procnew));
339 if ((rc = apr_file_open_stdout(&errfile, p)) == APR_SUCCESS)
340 rc = apr_procattr_child_err_set(procattr, errfile, NULL);
343 rc = apr_proc_create(procnew, args[0], (const char * const *)args,
346 if (rc == APR_SUCCESS) {
347 apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
348 (*fpin) = procnew->in;
349 /* read handle to pipe not kept open, so no need to call
350 * close_handle_in_child()
358 /* Open the error log for the given server_rec. If IS_MAIN is
359 * non-zero, s is the main server. */
360 static int open_error_log(server_rec *s, int is_main, apr_pool_t *p)
365 if (*s->error_fname == '|') {
366 apr_file_t *dummy = NULL;
367 apr_cmdtype_e cmdtype = APR_PROGRAM_ENV;
368 fname = s->error_fname + 1;
370 /* In 2.4 favor PROGRAM_ENV, accept "||prog" syntax for compatibility
371 * and "|$cmd" to override the default.
372 * Any 2.2 backport would continue to favor SHELLCMD_ENV so there
373 * accept "||prog" to override, and "|$cmd" to ease conversion.
378 cmdtype = APR_SHELLCMD_ENV;
382 /* Spawn a new child logger. If this is the main server_rec,
383 * the new child must use a dummy stderr since the current
384 * stderr might be a pipe to the old logger. Otherwise, the
385 * child inherits the parents stderr. */
386 rc = log_child(p, fname, &dummy, cmdtype, is_main);
387 if (rc != APR_SUCCESS) {
388 ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00089)
389 "Couldn't start ErrorLog process '%s'.",
394 s->error_log = dummy;
398 else if (!strncasecmp(s->error_fname, "syslog", 6)) {
399 if ((fname = strchr(s->error_fname, ':'))) {
403 for (fac = facilities; fac->t_name; fac++) {
404 if (!strcasecmp(fname, fac->t_name)) {
405 openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
413 openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
420 fname = ap_server_root_relative(p, s->error_fname);
422 ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, APLOGNO(00090)
423 "%s: Invalid error log path %s.",
424 ap_server_argv0, s->error_fname);
427 if ((rc = apr_file_open(&s->error_log, fname,
428 APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE,
429 APR_OS_DEFAULT, p)) != APR_SUCCESS) {
430 ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00091)
431 "%s: could not open error log file %s.",
432 ap_server_argv0, fname);
440 int ap_open_logs(apr_pool_t *pconf, apr_pool_t *p /* plog */,
441 apr_pool_t *ptemp, server_rec *s_main)
443 apr_pool_t *stderr_p;
444 server_rec *virt, *q;
448 /* Register to throw away the read_handles list when we
449 * cleanup plog. Upon fork() for the apache children,
450 * this read_handles list is closed so only the parent
451 * can relaunch a lost log child. These read handles
452 * are always closed on exec.
453 * We won't care what happens to our stderr log child
454 * between log phases, so we don't mind losing stderr's
455 * read_handle a little bit early.
457 apr_pool_cleanup_register(p, &read_handles, ap_pool_cleanup_set_null,
458 apr_pool_cleanup_null);
460 /* HERE we need a stdout log that outlives plog.
461 * We *presume* the parent of plog is a process
462 * or global pool which spans server restarts.
463 * Create our stderr_pool as a child of the plog's
466 apr_pool_create(&stderr_p, apr_pool_parent_get(p));
467 apr_pool_tag(stderr_p, "stderr_pool");
469 if (open_error_log(s_main, 1, stderr_p) != OK) {
474 if (s_main->error_log) {
477 /* Replace existing stderr with new log. */
478 apr_file_flush(s_main->error_log);
479 rv = apr_file_dup2(stderr_log, s_main->error_log, stderr_p);
480 if (rv != APR_SUCCESS) {
481 ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s_main, APLOGNO(00092)
482 "unable to replace stderr with error_log");
485 /* We are done with stderr_pool, close it, killing
486 * the previous generation's stderr logger
489 apr_pool_destroy(stderr_pool);
490 stderr_pool = stderr_p;
493 * Now that we have dup'ed s_main->error_log to stderr_log
494 * close it and set s_main->error_log to stderr_log. This avoids
495 * this fd being inherited by the next piped logger who would
496 * keep open the writing end of the pipe that this one uses
497 * as stdin. This in turn would prevent the piped logger from
500 apr_file_close(s_main->error_log);
501 s_main->error_log = stderr_log;
504 /* note that stderr may still need to be replaced with something
505 * because it points to the old error log, or back to the tty
507 * XXX: This is BS - /dev/null is non-portable
508 * errno-as-apr_status_t is also non-portable
512 #define NULL_DEVICE "nul"
514 #define NULL_DEVICE "/dev/null"
517 if (replace_stderr && freopen(NULL_DEVICE, "w", stderr) == NULL) {
518 ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main, APLOGNO(00093)
519 "unable to replace stderr with %s", NULL_DEVICE);
522 for (virt = s_main->next; virt; virt = virt->next) {
523 if (virt->error_fname) {
524 for (q=s_main; q != virt; q = q->next) {
525 if (q->error_fname != NULL
526 && strcmp(q->error_fname, virt->error_fname) == 0) {
532 if (open_error_log(virt, 0, p) != OK) {
537 virt->error_log = q->error_log;
541 virt->error_log = s_main->error_log;
547 AP_DECLARE(void) ap_error_log2stderr(server_rec *s) {
548 apr_file_t *errfile = NULL;
550 apr_file_open_stderr(&errfile, s->process->pool);
551 if (s->error_log != NULL) {
552 apr_file_dup2(s->error_log, errfile, s->process->pool);
556 static int cpystrn(char *buf, const char *arg, int buflen)
561 end = apr_cpystrn(buf, arg, buflen);
566 static int log_remote_address(const ap_errorlog_info *info, const char *arg,
567 char *buf, int buflen)
569 if (info->r && !(arg && *arg == 'c'))
570 return apr_snprintf(buf, buflen, "%s:%d", info->r->useragent_ip,
571 info->r->useragent_addr ? info->r->useragent_addr->port : 0);
573 return apr_snprintf(buf, buflen, "%s:%d", info->c->client_ip,
574 info->c->client_addr ? info->c->client_addr->port : 0);
579 static int log_local_address(const ap_errorlog_info *info, const char *arg,
580 char *buf, int buflen)
583 return apr_snprintf(buf, buflen, "%s:%d", info->c->local_ip,
584 info->c->local_addr->port);
589 static int log_pid(const ap_errorlog_info *info, const char *arg,
590 char *buf, int buflen)
592 pid_t pid = getpid();
593 return apr_snprintf(buf, buflen, "%" APR_PID_T_FMT, pid);
596 static int log_tid(const ap_errorlog_info *info, const char *arg,
597 char *buf, int buflen)
603 if (arg && *arg == 'g') {
604 pid_t tid = syscall(SYS_gettid);
607 return apr_snprintf(buf, buflen, "%"APR_PID_T_FMT, tid);
611 if (ap_mpm_query(AP_MPMQ_IS_THREADED, &result) == APR_SUCCESS
612 && result != AP_MPMQ_NOT_SUPPORTED)
614 apr_os_thread_t tid = apr_os_thread_current();
615 return apr_snprintf(buf, buflen, "%pT", &tid);
621 static int log_ctime(const ap_errorlog_info *info, const char *arg,
622 char *buf, int buflen)
624 int time_len = buflen;
625 int option = AP_CTIME_OPTION_NONE;
627 while (arg && *arg) {
629 case 'u': option |= AP_CTIME_OPTION_USEC;
631 case 'c': option |= AP_CTIME_OPTION_COMPACT;
637 ap_recent_ctime_ex(buf, apr_time_now(), option, &time_len);
639 /* ap_recent_ctime_ex includes the trailing \0 in time_len */
643 static int log_loglevel(const ap_errorlog_info *info, const char *arg,
644 char *buf, int buflen)
649 return cpystrn(buf, priorities[info->level].t_name, buflen);
652 static int log_log_id(const ap_errorlog_info *info, const char *arg,
653 char *buf, int buflen)
656 * C: log conn log_id if available,
657 * c: log conn log id if available and not a once-per-request log line
658 * else: log request log id if available
660 if (arg && !strcasecmp(arg, "c")) {
661 if (info->c && (*arg != 'C' || !info->r)) {
662 return cpystrn(buf, info->c->log_id, buflen);
665 else if (info->rmain) {
666 return cpystrn(buf, info->rmain->log_id, buflen);
671 static int log_keepalives(const ap_errorlog_info *info, const char *arg,
672 char *buf, int buflen)
677 return apr_snprintf(buf, buflen, "%d", info->c->keepalives);
680 static int log_module_name(const ap_errorlog_info *info, const char *arg,
681 char *buf, int buflen)
683 return cpystrn(buf, ap_find_module_short_name(info->module_index), buflen);
686 static int log_file_line(const ap_errorlog_info *info, const char *arg,
687 char *buf, int buflen)
689 if (info->file == NULL) {
693 const char *file = info->file;
694 #if defined(_OSD_POSIX) || defined(WIN32) || defined(__MVS__)
696 char *e = strrchr(file, '/');
699 e = strrchr(file, '\\');
703 /* In OSD/POSIX, the compiler returns for __FILE__
704 * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
705 * (it even returns an absolute path for sources in
706 * the current directory). Here we try to strip this
707 * down to the basename.
709 if (e != NULL && e[1] != '\0') {
710 apr_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
711 e = &tmp[strlen(tmp)-1];
717 #else /* _OSD_POSIX || WIN32 */
719 /* On Unix, __FILE__ may be an absolute path in a
721 if (file[0] == '/' && (p = ap_strrchr_c(file, '/')) != NULL) {
724 #endif /*_OSD_POSIX || WIN32 */
725 return apr_snprintf(buf, buflen, "%s(%d)", file, info->line);
729 static int log_apr_status(const ap_errorlog_info *info, const char *arg,
730 char *buf, int buflen)
732 apr_status_t status = info->status;
737 if (status < APR_OS_START_EAIERR) {
738 len = apr_snprintf(buf, buflen, "(%d)", status);
740 else if (status < APR_OS_START_SYSERR) {
741 len = apr_snprintf(buf, buflen, "(EAI %d)",
742 status - APR_OS_START_EAIERR);
744 else if (status < 100000 + APR_OS_START_SYSERR) {
745 len = apr_snprintf(buf, buflen, "(OS %d)",
746 status - APR_OS_START_SYSERR);
749 len = apr_snprintf(buf, buflen, "(os 0x%08x)",
750 status - APR_OS_START_SYSERR);
752 apr_strerror(status, buf + len, buflen - len);
753 len += strlen(buf + len);
757 static int log_server_name(const ap_errorlog_info *info, const char *arg,
758 char *buf, int buflen)
761 return cpystrn(buf, ap_get_server_name((request_rec *)info->r), buflen);
766 static int log_virtual_host(const ap_errorlog_info *info, const char *arg,
767 char *buf, int buflen)
770 return cpystrn(buf, info->s->server_hostname, buflen);
776 static int log_table_entry(const apr_table_t *table, const char *name,
777 char *buf, int buflen)
779 #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
781 char scratch[MAX_STRING_LEN];
783 if ((value = apr_table_get(table, name)) != NULL) {
784 ap_escape_errorlog_item(scratch, value, MAX_STRING_LEN);
785 return cpystrn(buf, scratch, buflen);
790 return cpystrn(buf, apr_table_get(table, name), buflen);
794 static int log_header(const ap_errorlog_info *info, const char *arg,
795 char *buf, int buflen)
798 return log_table_entry(info->r->headers_in, arg, buf, buflen);
803 static int log_note(const ap_errorlog_info *info, const char *arg,
804 char *buf, int buflen)
806 /* XXX: maybe escaping the entry is not necessary for notes? */
808 return log_table_entry(info->r->notes, arg, buf, buflen);
813 static int log_env_var(const ap_errorlog_info *info, const char *arg,
814 char *buf, int buflen)
817 return log_table_entry(info->r->subprocess_env, arg, buf, buflen);
822 static int core_generate_log_id(const conn_rec *c, const request_rec *r,
823 const char **idstring)
825 apr_uint64_t id, tmp;
830 if (r && r->request_time) {
831 id = (apr_uint64_t)r->request_time;
834 id = (apr_uint64_t)apr_time_now();
838 if (sizeof(pid_t) > 2) {
854 apr_uintptr_t tmp2 = (apr_uintptr_t)c->current_thread;
861 len = apr_base64_encode_len(sizeof(id)); /* includes trailing \0 */
862 encoded = apr_palloc(r ? r->pool : c->pool, len);
863 apr_base64_encode(encoded, (char *)&id, sizeof(id));
865 /* Skip the last char, it is always '=' */
866 encoded[len - 2] = '\0';
873 static void add_log_id(const conn_rec *c, const request_rec *r)
876 /* need to cast const away */
878 id = &((request_rec *)r)->log_id;
881 id = &((conn_rec *)c)->log_id;
884 ap_run_generate_log_id(c, r, id);
887 AP_DECLARE(void) ap_register_log_hooks(apr_pool_t *p)
889 ap_hook_generate_log_id(core_generate_log_id, NULL, NULL,
890 APR_HOOK_REALLY_LAST);
892 ap_register_errorlog_handler(p, "a", log_remote_address, 0);
893 ap_register_errorlog_handler(p, "A", log_local_address, 0);
894 ap_register_errorlog_handler(p, "e", log_env_var, 0);
895 ap_register_errorlog_handler(p, "E", log_apr_status, 0);
896 ap_register_errorlog_handler(p, "F", log_file_line, 0);
897 ap_register_errorlog_handler(p, "i", log_header, 0);
898 ap_register_errorlog_handler(p, "k", log_keepalives, 0);
899 ap_register_errorlog_handler(p, "l", log_loglevel, 0);
900 ap_register_errorlog_handler(p, "L", log_log_id, 0);
901 ap_register_errorlog_handler(p, "m", log_module_name, 0);
902 ap_register_errorlog_handler(p, "n", log_note, 0);
903 ap_register_errorlog_handler(p, "P", log_pid, 0);
904 ap_register_errorlog_handler(p, "t", log_ctime, 0);
905 ap_register_errorlog_handler(p, "T", log_tid, 0);
906 ap_register_errorlog_handler(p, "v", log_virtual_host, 0);
907 ap_register_errorlog_handler(p, "V", log_server_name, 0);
911 * This is used if no error log format is defined and during startup.
912 * It automatically omits the timestamp if logging to syslog.
914 static int do_errorlog_default(const ap_errorlog_info *info, char *buf,
915 int buflen, int *errstr_start, int *errstr_end,
916 const char *errstr_fmt, va_list args)
921 #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
922 char scratch[MAX_STRING_LEN];
925 if (!info->using_syslog && !info->startup) {
927 len += log_ctime(info, "u", buf + len, buflen - len);
932 if (!info->startup) {
934 len += log_module_name(info, NULL, buf + len, buflen - len);
936 len += log_loglevel(info, NULL, buf + len, buflen - len);
937 len += cpystrn(buf + len, "] [pid ", buflen - len);
939 len += log_pid(info, NULL, buf + len, buflen - len);
942 len += cpystrn(buf + len, ":tid ", buflen - len);
943 item_len = log_tid(info, NULL, buf + len, buflen - len);
953 if (info->level >= APLOG_DEBUG) {
954 item_len = log_file_line(info, NULL, buf + len, buflen - len);
957 len += cpystrn(buf + len, ": ", buflen - len);
962 item_len = log_apr_status(info, NULL, buf + len, buflen - len);
965 len += cpystrn(buf + len, ": ", buflen - len);
970 * useragent_ip/client_ip can be client or backend server. If we have
971 * a scoreboard handle, it is likely a client.
974 len += apr_snprintf(buf + len, buflen - len,
975 info->r->connection->sbh ? "[client %s:%d] " : "[remote %s:%d] ",
976 info->r->useragent_ip,
977 info->r->useragent_addr ? info->r->useragent_addr->port : 0);
980 len += apr_snprintf(buf + len, buflen - len,
981 info->c->sbh ? "[client %s:%d] " : "[remote %s:%d] ",
983 info->c->client_addr ? info->c->client_addr->port : 0);
986 /* the actual error message */
988 #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
989 if (apr_vsnprintf(scratch, MAX_STRING_LEN, errstr_fmt, args)) {
990 len += ap_escape_errorlog_item(buf + len, scratch,
995 len += apr_vsnprintf(buf + len, buflen - len, errstr_fmt, args);
1000 len += cpystrn(buf + len, ", referer: ", buflen - len);
1001 item_len = log_header(info, "Referer", buf + len, buflen - len);
1010 static int do_errorlog_format(apr_array_header_t *fmt, ap_errorlog_info *info,
1011 char *buf, int buflen, int *errstr_start,
1012 int *errstr_end, const char *err_fmt, va_list args)
1014 #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
1015 char scratch[MAX_STRING_LEN];
1019 int field_start = 0;
1021 ap_errorlog_format_item *items = (ap_errorlog_format_item *)fmt->elts;
1023 AP_DEBUG_ASSERT(fmt->nelts > 0);
1024 for (i = 0; i < fmt->nelts; ++i) {
1025 ap_errorlog_format_item *item = &items[i];
1026 if (item->flags & AP_ERRORLOG_FLAG_FIELD_SEP) {
1035 if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) {
1036 /* the actual error message */
1037 *errstr_start = len;
1038 #ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
1039 if (apr_vsnprintf(scratch, MAX_STRING_LEN, err_fmt, args)) {
1040 len += ap_escape_errorlog_item(buf + len, scratch,
1045 len += apr_vsnprintf(buf + len, buflen - len, err_fmt, args);
1049 else if (skipping) {
1052 else if (info->level != -1 && (int)item->min_loglevel > info->level) {
1057 int item_len = (*item->func)(info, item->arg, buf + len,
1060 if (item->flags & AP_ERRORLOG_FLAG_REQUIRED) {
1061 /* required item is empty. skip whole line */
1065 else if (item->flags & AP_ERRORLOG_FLAG_NULL_AS_HYPHEN) {
1081 static void write_logline(char *errstr, apr_size_t len, apr_file_t *logf,
1084 /* NULL if we are logging to syslog */
1086 /* Truncate for the terminator (as apr_snprintf does) */
1087 if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR)) {
1088 len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
1090 strcpy(errstr + len, APR_EOL_STR);
1091 apr_file_puts(errstr, logf);
1092 apr_file_flush(logf);
1096 syslog(level < LOG_PRIMASK ? level : APLOG_DEBUG, "%.*s",
1102 static void log_error_core(const char *file, int line, int module_index,
1104 apr_status_t status, const server_rec *s,
1106 const request_rec *r, apr_pool_t *pool,
1107 const char *fmt, va_list args)
1109 char errstr[MAX_STRING_LEN];
1110 apr_file_t *logf = NULL;
1111 int level_and_mask = level & APLOG_LEVELMASK;
1112 const request_rec *rmain = NULL;
1113 core_server_config *sconf = NULL;
1114 ap_errorlog_info info;
1116 /* do we need to log once-per-req or once-per-conn info? */
1117 int log_conn_info = 0, log_req_info = 0;
1118 apr_array_header_t **lines = NULL;
1120 int line_number = 0;
1123 AP_DEBUG_ASSERT(r->connection != NULL);
1129 * If we are doing stderr logging (startup), don't log messages that are
1130 * above the default server log level unless it is a startup/shutdown
1134 if ((level_and_mask != APLOG_NOTICE)
1135 && (level_and_mask > ap_default_loglevel)) {
1143 int configured_level = r ? ap_get_request_module_loglevel(r, module_index) :
1144 c ? ap_get_conn_server_module_loglevel(c, s, module_index) :
1145 ap_get_server_module_loglevel(s, module_index);
1148 * If we are doing normal logging, don't log messages that are
1149 * above the module's log level unless it is a startup/shutdown notice
1151 if ((level_and_mask != APLOG_NOTICE)
1152 && (level_and_mask > configured_level)) {
1156 logf = s->error_log;
1160 * If we are doing syslog logging, don't log messages that are
1161 * above the module's log level (including a startup/shutdown notice)
1163 if (level_and_mask > configured_level) {
1168 /* the faked server_rec from mod_cgid does not have s->module_config */
1169 if (s->module_config) {
1170 sconf = ap_get_core_module_config(s->module_config);
1171 if (c && !c->log_id) {
1172 add_log_id(c, NULL);
1173 if (sconf->error_log_conn && sconf->error_log_conn->nelts > 0)
1182 if (!rmain->log_id) {
1183 /* XXX: do we need separate log ids for subrequests? */
1184 if (sconf->error_log_req && sconf->error_log_req->nelts > 0)
1187 * XXX: potential optimization: only create log id if %L is
1188 * XXX: actually used
1190 add_log_id(c, rmain);
1202 info.using_syslog = (logf == NULL);
1203 info.startup = ((level & APLOG_STARTUP) == APLOG_STARTUP);
1207 apr_array_header_t *log_format;
1208 int len = 0, errstr_start = 0, errstr_end = 0;
1209 /* XXX: potential optimization: format common prefixes only once */
1210 if (log_conn_info) {
1211 /* once-per-connection info */
1212 if (line_number == 0) {
1213 lines = (apr_array_header_t **)sconf->error_log_conn->elts;
1217 info.module_index = APLOG_NO_MODULE;
1220 log_format = lines[line_number++];
1222 if (line_number == sconf->error_log_conn->nelts) {
1223 /* this is the last line of once-per-connection info */
1228 else if (log_req_info) {
1229 /* once-per-request info */
1230 if (line_number == 0) {
1231 lines = (apr_array_header_t **)sconf->error_log_req->elts;
1235 info.module_index = APLOG_NO_MODULE;
1238 log_format = lines[line_number++];
1240 if (line_number == sconf->error_log_req->nelts) {
1241 /* this is the last line of once-per-request info */
1247 /* the actual error message */
1250 info.level = level_and_mask;
1251 info.module_index = module_index;
1254 info.status = status;
1255 log_format = sconf ? sconf->error_log_format : NULL;
1260 * prepare and log one line
1263 if (log_format && !info.startup) {
1264 len += do_errorlog_format(log_format, &info, errstr + len,
1265 MAX_STRING_LEN - len,
1266 &errstr_start, &errstr_end, fmt, args);
1269 len += do_errorlog_default(&info, errstr + len, MAX_STRING_LEN - len,
1270 &errstr_start, &errstr_end, fmt, args);
1275 * Don't log empty lines. This can happen with once-per-conn/req
1276 * info if an item with AP_ERRORLOG_FLAG_REQUIRED is NULL.
1280 write_logline(errstr, len, logf, level_and_mask);
1284 * We don't call the error_log hook for per-request/per-conn
1285 * lines, and we only pass the actual log message, not the
1286 * prefix and suffix.
1288 errstr[errstr_end] = '\0';
1289 ap_run_error_log(&info, errstr + errstr_start);
1296 /* For internal calls to log_error_core with self-composed arg lists */
1297 static void log_error_va_glue(const char *file, int line, int module_index,
1298 int level, apr_status_t status,
1299 const server_rec *s, const conn_rec *c,
1300 const request_rec *r, apr_pool_t *pool,
1301 const char *fmt, ...)
1305 va_start(args, fmt);
1306 log_error_core(file, line, module_index, level, status, s, c, r, pool,
1311 AP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
1312 int level, apr_status_t status,
1313 const server_rec *s, const char *fmt, ...)
1317 va_start(args, fmt);
1318 log_error_core(file, line, module_index, level, status, s, NULL, NULL,
1323 AP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
1324 int level, apr_status_t status, apr_pool_t *p,
1325 const char *fmt, ...)
1329 va_start(args, fmt);
1330 log_error_core(file, line, module_index, level, status, NULL, NULL, NULL,
1335 AP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
1336 int level, apr_status_t status,
1337 const request_rec *r, const char *fmt, ...)
1341 va_start(args, fmt);
1342 log_error_core(file, line, module_index, level, status, r->server, NULL, r,
1346 * IF APLOG_TOCLIENT is set,
1347 * AND the error level is 'warning' or more severe,
1348 * AND there isn't already error text associated with this request,
1349 * THEN make the message text available to ErrorDocument and
1350 * other error processors.
1354 if ((level & APLOG_TOCLIENT)
1355 && ((level & APLOG_LEVELMASK) <= APLOG_WARNING)
1356 && (apr_table_get(r->notes, "error-notes") == NULL)) {
1357 apr_table_setn(r->notes, "error-notes",
1358 ap_escape_html(r->pool, apr_pvsprintf(r->pool, fmt,
1364 AP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
1365 int level, apr_status_t status,
1366 const conn_rec *c, const server_rec *s,
1367 const char *fmt, ...)
1371 va_start(args, fmt);
1372 log_error_core(file, line, module_index, level, status, s, c,
1373 NULL, NULL, fmt, args);
1377 AP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
1378 int level, apr_status_t status,
1379 const conn_rec *c, const char *fmt, ...)
1383 va_start(args, fmt);
1384 log_error_core(file, line, module_index, level, status, c->base_server, c,
1385 NULL, NULL, fmt, args);
1389 #define BYTES_LOGGED_PER_LINE 16
1390 #define LOG_BYTES_BUFFER_SIZE (BYTES_LOGGED_PER_LINE * 3 + 2)
1392 static void fmt_data(unsigned char *buf, const void *vdata, apr_size_t len, apr_size_t *off)
1394 const unsigned char *data = (const unsigned char *)vdata;
1395 unsigned char *chars;
1397 apr_size_t this_time = 0;
1399 memset(buf, ' ', LOG_BYTES_BUFFER_SIZE - 1);
1400 buf[LOG_BYTES_BUFFER_SIZE - 1] = '\0';
1402 chars = buf; /* start character dump here */
1403 hex = buf + BYTES_LOGGED_PER_LINE + 1; /* start hex dump here */
1404 while (*off < len && this_time < BYTES_LOGGED_PER_LINE) {
1405 unsigned char c = data[*off];
1408 && c != '\\') { /* backslash will be escaped later, which throws
1409 * off the formatting
1417 if ((c >> 4) >= 10) {
1418 *hex = 'a' + ((c >> 4) - 10);
1421 *hex = '0' + (c >> 4);
1424 if ((c & 0x0F) >= 10) {
1425 *(hex + 1) = 'a' + ((c & 0x0F) - 10);
1428 *(hex + 1) = '0' + (c & 0x0F);
1438 static void log_data_core(const char *file, int line, int module_index,
1439 int level, const server_rec *s,
1440 const conn_rec *c, const request_rec *r,
1441 const char *label, const void *data, apr_size_t len,
1444 unsigned char buf[LOG_BYTES_BUFFER_SIZE];
1448 if (!(flags & AP_LOG_DATA_SHOW_OFFSET)) {
1452 if (len > 0xffff) { /* bug in caller? */
1457 log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
1458 c, r, NULL, "%s (%" APR_SIZE_T_FMT " bytes)",
1464 if (flags & AP_LOG_DATA_SHOW_OFFSET) {
1465 apr_snprintf(prefix, sizeof prefix, "%04x: ", (unsigned int)off);
1467 fmt_data(buf, data, len, &off);
1468 log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
1469 c, r, NULL, "%s%s", prefix, buf);
1473 AP_DECLARE(void) ap_log_data_(const char *file, int line,
1474 int module_index, int level,
1475 const server_rec *s, const char *label,
1476 const void *data, apr_size_t len,
1479 log_data_core(file, line, module_index, level, s, NULL, NULL, label,
1483 AP_DECLARE(void) ap_log_rdata_(const char *file, int line,
1484 int module_index, int level,
1485 const request_rec *r, const char *label,
1486 const void *data, apr_size_t len,
1489 log_data_core(file, line, module_index, level, r->server, NULL, r, label,
1493 AP_DECLARE(void) ap_log_cdata_(const char *file, int line,
1494 int module_index, int level,
1495 const conn_rec *c, const char *label,
1496 const void *data, apr_size_t len,
1499 log_data_core(file, line, module_index, level, c->base_server, c, NULL,
1500 label, data, len, flags);
1503 AP_DECLARE(void) ap_log_csdata_(const char *file, int line, int module_index,
1504 int level, const conn_rec *c, const server_rec *s,
1505 const char *label, const void *data,
1506 apr_size_t len, unsigned int flags)
1508 log_data_core(file, line, module_index, level, s, c, NULL, label, data,
1512 AP_DECLARE(void) ap_log_command_line(apr_pool_t *plog, server_rec *s)
1515 process_rec *process = s->process;
1519 /* Piece together the command line from the pieces
1520 * in process->argv, with spaces in between.
1522 for (i = 0; i < process->argc; i++) {
1523 len_needed += strlen(process->argv[i]) + 1;
1526 result = (char *) apr_palloc(plog, len_needed);
1529 for (i = 0; i < process->argc; i++) {
1530 strcat(result, process->argv[i]);
1531 if ((i+1)< process->argc) {
1532 strcat(result, " ");
1535 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(00094)
1536 "Command line: '%s'", result);
1539 AP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *rel_fname)
1542 const char *fname = ap_server_root_relative(p, rel_fname);
1544 if (fname != NULL) {
1545 rv = apr_file_remove(fname, p);
1546 if (rv != APR_SUCCESS) {
1547 ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(00095)
1548 "failed to remove PID file %s", fname);
1551 ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(00096)
1552 "removed PID file %s (pid=%" APR_PID_T_FMT ")",
1558 AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
1560 apr_file_t *pid_file = NULL;
1562 static pid_t saved_pid = -1;
1571 fname = ap_server_root_relative(p, filename);
1573 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
1574 NULL, APLOGNO(00097) "Invalid PID file path %s, ignoring.", filename);
1579 if (mypid != saved_pid
1580 && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
1581 /* AP_SIG_GRACEFUL and HUP call this on each restart.
1582 * Only warn on first time through for this pid.
1584 * XXX: Could just write first time through too, although
1585 * that may screw up scripts written to do something
1586 * based on the last modification time of the pid file.
1588 ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, p, APLOGNO(00098)
1589 "pid file %s overwritten -- Unclean "
1590 "shutdown of previous Apache run?",
1594 if ((rv = apr_file_open(&pid_file, fname,
1595 APR_WRITE | APR_CREATE | APR_TRUNCATE,
1596 APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p))
1598 ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099)
1599 "could not create %s", fname);
1600 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100)
1601 "%s: could not log pid to file %s",
1602 ap_server_argv0, fname);
1605 apr_file_printf(pid_file, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
1606 apr_file_close(pid_file);
1610 AP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
1613 const apr_size_t BUFFER_SIZE = sizeof(long) * 3 + 2; /* see apr_ltoa */
1614 apr_file_t *pid_file = NULL;
1618 apr_size_t bytes_read;
1621 return APR_EGENERAL;
1624 fname = ap_server_root_relative(p, filename);
1626 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
1627 NULL, APLOGNO(00101) "Invalid PID file path %s, ignoring.", filename);
1628 return APR_EGENERAL;
1631 rv = apr_file_open(&pid_file, fname, APR_READ, APR_OS_DEFAULT, p);
1632 if (rv != APR_SUCCESS) {
1636 buf = apr_palloc(p, BUFFER_SIZE);
1638 rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
1639 if (rv != APR_SUCCESS && rv != APR_EOF) {
1643 /* If we fill the buffer, we're probably reading a corrupt pid file.
1644 * To be nice, let's also ensure the first char is a digit. */
1645 if (bytes_read == 0 || bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
1646 return APR_EGENERAL;
1649 buf[bytes_read] = '\0';
1650 *mypid = strtol(buf, &endptr, 10);
1652 apr_file_close(pid_file);
1656 AP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile,
1659 char time_str[APR_CTIME_LEN];
1661 apr_ctime(time_str, apr_time_now());
1662 ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(00102)
1663 "[%s] file %s, line %d, assertion \"%s\" failed",
1664 time_str, szFile, nLine, szExp);
1668 /* unix assert does an abort leading to a core dump */
1673 /* piped log support */
1675 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
1676 /* forward declaration */
1677 static void piped_log_maintenance(int reason, void *data, apr_wait_t status);
1679 /* Spawn the piped logger process pl->program. */
1680 static apr_status_t piped_log_spawn(piped_log *pl)
1682 apr_procattr_t *procattr;
1683 apr_proc_t *procnew = NULL;
1684 apr_status_t status;
1686 if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
1687 ((status = apr_procattr_dir_set(procattr, ap_server_root))
1689 ((status = apr_procattr_cmdtype_set(procattr, pl->cmdtype))
1691 ((status = apr_procattr_child_in_set(procattr,
1695 ((status = apr_procattr_child_errfn_set(procattr, log_child_errfn))
1697 ((status = apr_procattr_error_check_set(procattr, 1)) != APR_SUCCESS)) {
1698 /* Something bad happened, give up and go away. */
1699 ap_log_error(APLOG_MARK, APLOG_STARTUP, status, NULL, APLOGNO(00103)
1700 "piped_log_spawn: unable to setup child process '%s'",
1706 apr_tokenize_to_argv(pl->program, &args, pl->p);
1707 procnew = apr_pcalloc(pl->p, sizeof(apr_proc_t));
1708 status = apr_proc_create(procnew, args[0], (const char * const *) args,
1709 NULL, procattr, pl->p);
1711 if (status == APR_SUCCESS) {
1713 /* procnew->in was dup2'd from pl->write_fd;
1714 * since the original fd is still valid, close the copy to
1716 apr_file_close(procnew->in);
1718 apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
1719 pl->write_fd, pl->p);
1720 close_handle_in_child(pl->p, pl->read_fd);
1723 /* Something bad happened, give up and go away. */
1724 ap_log_error(APLOG_MARK, APLOG_STARTUP, status, NULL, APLOGNO(00104)
1725 "unable to start piped log program '%s'",
1734 static void piped_log_maintenance(int reason, void *data, apr_wait_t status)
1736 piped_log *pl = data;
1741 case APR_OC_REASON_DEATH:
1742 case APR_OC_REASON_LOST:
1743 pl->pid = NULL; /* in case we don't get it going again, this
1744 * tells other logic not to try to kill it
1746 apr_proc_other_child_unregister(pl);
1747 rv = ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state);
1748 if (rv != APR_SUCCESS) {
1749 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00105)
1750 "can't query MPM state; not restarting "
1751 "piped log program '%s'",
1754 else if (mpm_state != AP_MPMQ_STOPPING) {
1755 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00106)
1756 "piped log program '%s' failed unexpectedly",
1758 if ((rv = piped_log_spawn(pl)) != APR_SUCCESS) {
1759 /* what can we do? This could be the error log we're having
1760 * problems opening up... */
1761 ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, NULL, APLOGNO(00107)
1762 "piped_log_maintenance: unable to respawn '%s'",
1768 case APR_OC_REASON_UNWRITABLE:
1769 /* We should not kill off the pipe here, since it may only be full.
1770 * If it really is locked, we should kill it off manually. */
1773 case APR_OC_REASON_RESTART:
1774 if (pl->pid != NULL) {
1775 apr_proc_kill(pl->pid, SIGTERM);
1780 case APR_OC_REASON_UNREGISTER:
1786 static apr_status_t piped_log_cleanup_for_exec(void *data)
1788 piped_log *pl = data;
1790 apr_file_close(pl->read_fd);
1791 apr_file_close(pl->write_fd);
1796 static apr_status_t piped_log_cleanup(void *data)
1798 piped_log *pl = data;
1800 if (pl->pid != NULL) {
1801 apr_proc_kill(pl->pid, SIGTERM);
1803 return piped_log_cleanup_for_exec(data);
1807 AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
1808 const char *program,
1809 apr_cmdtype_e cmdtype)
1813 pl = apr_palloc(p, sizeof (*pl));
1815 pl->program = apr_pstrdup(p, program);
1817 pl->cmdtype = cmdtype;
1818 if (apr_file_pipe_create_ex(&pl->read_fd,
1820 APR_FULL_BLOCK, p) != APR_SUCCESS) {
1823 apr_pool_cleanup_register(p, pl, piped_log_cleanup,
1824 piped_log_cleanup_for_exec);
1825 if (piped_log_spawn(pl) != APR_SUCCESS) {
1826 apr_pool_cleanup_kill(p, pl, piped_log_cleanup);
1827 apr_file_close(pl->read_fd);
1828 apr_file_close(pl->write_fd);
1834 #else /* !AP_HAVE_RELIABLE_PIPED_LOGS */
1836 static apr_status_t piped_log_cleanup(void *data)
1838 piped_log *pl = data;
1840 apr_file_close(pl->write_fd);
1844 AP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
1845 const char *program,
1846 apr_cmdtype_e cmdtype)
1849 apr_file_t *dummy = NULL;
1852 rc = log_child(p, program, &dummy, cmdtype, 0);
1853 if (rc != APR_SUCCESS) {
1854 ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00108)
1855 "Couldn't start piped log process '%s'.",
1856 (program == NULL) ? "NULL" : program);
1860 pl = apr_palloc(p, sizeof (*pl));
1863 pl->write_fd = dummy;
1864 apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);
1871 AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p,
1872 const char *program)
1874 apr_cmdtype_e cmdtype = APR_PROGRAM_ENV;
1876 /* In 2.4 favor PROGRAM_ENV, accept "||prog" syntax for compatibility
1877 * and "|$cmd" to override the default.
1878 * Any 2.2 backport would continue to favor SHELLCMD_ENV so there
1879 * accept "||prog" to override, and "|$cmd" to ease conversion.
1881 if (*program == '|')
1883 if (*program == '$') {
1884 cmdtype = APR_SHELLCMD_ENV;
1888 return ap_open_piped_log_ex(p, program, cmdtype);
1891 AP_DECLARE(void) ap_close_piped_log(piped_log *pl)
1893 apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
1896 AP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val)
1898 char *err = "Log level keyword must be one of emerg/alert/crit/error/warn/"
1899 "notice/info/debug/trace1/.../trace8";
1905 while (priorities[i].t_name != NULL) {
1906 if (!strcasecmp(str, priorities[i].t_name)) {
1907 *val = priorities[i].t_val;
1915 AP_IMPLEMENT_HOOK_VOID(error_log,
1916 (const ap_errorlog_info *info, const char *errstr),
1919 AP_IMPLEMENT_HOOK_RUN_FIRST(int, generate_log_id,
1920 (const conn_rec *c, const request_rec *r,
1922 (c, r, id), DECLINED)