/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) fsyslog.c (Gunther Schadow) 12/19/96"); /* * fsyslog -- fake syslog(3) functionality (though less complete) * * Copyright (c) 1995, 1996 Gunther Schadow */ #include "fsyslog.h" #include #include #include #include #include #include char *logfile = "/tmp/fsyslog.log"; static FILE* logfp = stderr; static int _level = 5; static char* _tag = ""; static char* _facility = ""; static int _flags = 0; void openlog(char *tag, int flags, char *facility) { _tag = tag; _facility = facility; _flags = flags; logfp = fopen(logfile, "a"); if (logfp == NULL) { fprintf(stderr, "%s: %s\n", logfile, strerror(errno)); exit(1); } } #define BUF_SIZE 1024 void syslog(int pri, const char *msg, ...) { va_list ap; char *p; char buf[BUF_SIZE] = ""; time_t tme; time(&tme); strftime(buf, BUF_SIZE, "%b %e %T ", localtime(&tme)); sprintf(buf + strlen(buf), "%s[%d]: ", _tag, (int)getpid()); p = (char *)strstr(msg, "%m"); if(p != NULL) { strncat(buf, msg, p - msg); strcat(buf, (char *)strerror(errno)); strcat(buf, p + 2); } else strcat(buf, msg); va_start(ap, msg); vfprintf(logfp, buf, ap); fputs("\n",logfp); fflush(logfp); } void setlogmask(int l) { _level = l; }