3 * $Header: /cvsroot/pgpool/pgpool-II/pool_error.c,v 1.3.2.1 2009/08/22 04:19:49 t-ishii Exp $
5 * pgpool: a language independent connection pool server for PostgreSQL
6 * written by Tatsuo Ishii
8 * Copyright (c) 2003-2008 PgPool Global Development Group
10 * Permission to use, copy, modify, and distribute this software and
11 * its documentation for any purpose and without fee is hereby
12 * granted, provided that the above copyright notice appear in all
13 * copies and that both that copyright notice and this permission
14 * notice appear in supporting documentation, and that the name of the
15 * author not be used in advertising or publicity pertaining to
16 * distribution of the software without specific, written prior
17 * permission. The author makes no representations about the
18 * suitability of this software for any purpose. It is provided "as
19 * is" without express or implied warranty.
21 * pool_error.c: error and debug messages
27 #include <sys/types.h>
33 #define MAXSTRFTIME 128
37 static char *nowsec(void);
39 void pool_error(const char *fmt,...)
46 #ifdef HAVE_SIGPROCMASK
52 POOL_SETMASK2(&BlockSig, &oldmask);
54 if (pool_config->print_timestamp)
56 asprintf(&fmt2, "%s ERROR: pid %d: %s\n", nowsec(), (int)getpid(), fmt);
58 asprintf(&fmt2, "ERROR: pid %d: %s\n", (int)getpid(), fmt);
63 vfprintf(stderr, fmt2, ap);
69 fprintf(stderr, "%s ERROR: pid %d: ", nowsec(), (int)getpid());
71 fprintf(stderr, "ERROR: pid %d: ", (int)getpid());
74 vfprintf(stderr, fmt, ap);
76 fprintf(stderr, "\n");
79 POOL_SETMASK(&oldmask);
82 void pool_debug(const char *fmt,...)
89 #ifdef HAVE_SIGPROCMASK
98 POOL_SETMASK2(&BlockSig, &oldmask);
100 if (pool_config->print_timestamp)
102 asprintf(&fmt2, "%s DEBUG: pid %d: %s\n", nowsec(), (int)getpid(), fmt);
104 asprintf(&fmt2, "DEBUG: pid %d: %s\n", (int)getpid(), fmt);
109 vfprintf(stderr, fmt2, ap);
115 fprintf(stderr, "%s DEBUG: pid %d: ", nowsec(), (int)getpid());
117 fprintf(stderr, "DEBUG: pid %d: ", (int)getpid());
120 vfprintf(stderr, fmt, ap);
122 fprintf(stderr, "\n");
125 POOL_SETMASK(&oldmask);
128 void pool_log(const char *fmt,...)
135 #ifdef HAVE_SIGPROCMASK
141 POOL_SETMASK2(&BlockSig, &oldmask);
143 if (pool_config->print_timestamp)
145 asprintf(&fmt2, "%s LOG: pid %d: %s\n", nowsec(), (int)getpid(), fmt);
147 asprintf(&fmt2, "LOG: pid %d: %s\n", (int)getpid(), fmt);
152 vfprintf(stderr, fmt2, ap);
158 fprintf(stderr, "%s LOG: pid %d: ", nowsec(), (int)getpid());
160 fprintf(stderr, "LOG: pid %d: ", (int)getpid());
163 vfprintf(stderr, fmt, ap);
165 fprintf(stderr, "\n");
168 POOL_SETMASK(&oldmask);
171 static char *nowsec(void)
173 static char strbuf[MAXSTRFTIME];
174 time_t now = time(NULL);
176 strftime(strbuf, MAXSTRFTIME, "%Y-%m-%d %H:%M:%S", localtime(&now));