static	char	*dlog_c = "$Header: /general/TFA/unclassified/src/utils/postgres-v3r1/src/utils/error/RCS/dlog.c,v 1.10 1992/01/29 16:43:50 postgres Exp $";

#include "utils/log.h"
#include "support/master.h"
#ifdef sgi
#include <time.h>
#endif
extern int	Debugfile, Ttyfile, Dblog, Slog;
extern short	DebugLvl;	/* set by -d option */

/*
 * debug and error logger
 */

int	Cline;
char	*Cfile;

dlog(lvl, mess)
long	lvl;
char	*mess;
{
	char	line[256];
#ifndef sgi
	char    *ctime(); 
#endif
	long	time(), ct;
	int	len;

	if ((lvl & 0xff) < DebugLvl)
	  return;
	line[0] = '\0';
	if (lvl & PTIME) {
		/* put time into buffer */
		time(&ct);
		strcpy(line, ctime(&ct)+4);
		line[16] = '\0';
	}
	if (lvl & POS)
	  strcat(line, form((int) "File %s, line %d:", Cfile, Cline));
	strcat(line, mess);
	strcat(line, "\n");
	len = strlen(line);
	if (Debugfile >= 0)
	  write(Debugfile, line, len);
	if ((lvl & TERM) && Ttyfile >= 0)
	  write(Ttyfile, line, len);
	if ((lvl & DBLOG) && Dblog >= 0)
	  write(Dblog, line, len);
	if ((lvl & SLOG) && Slog >= 0)
	  write(Slog, line, len);
	if (lvl & ABORT)
	  abort();
}
