static	char	*dlog_c = "$Header: dlog.c,v 1.2 89/02/02 18:21:10 aoki Exp $";

#include "log.h"
#include "master.h"

extern	int	Debugfile, Ttyfile, Dblog, Slog;

/*
 * debug and error logger
 */

int	Cline;
char	*Cfile;

dlog(lvl, mess)
long	lvl;
char	*mess;
{
	char	line[256], *ctime();
	long	time(), ct;
	int	len;
	extern	struct	bcommon	Ident;

	if ((lvl & 0xff) < Ident.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("File %s, line %d:", Cfile, Cline));
	strcat(line, mess);
	strcat(line, "\n");
	len = strlen(line);
	if (Debugfile >= 0)
	  write(Debugfile, line, len);
	if (lvl & USER)
	  sendannounce(line);
	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();
}
