/** * @file log.c * @ingroup common * * Logging support * * @author Part of CircleMUD * * @par Copyright: * Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University<br> * CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. * * @par * All rights reserved. See license.doc for complete information. * * @package cs * @version 1.0 */ #define __LOG_C__ #include "base.h" #include "log.h" #include "structs.h" #include "utils.h" #include "comm.h" #include "db.h" #include "screen.h" #include "room.h" #include "zone.h" FILE *logfile; /** * Writes an entry to the log file. * @param format the printf-style format specifier string * @return none */ void basic_mud_log(const char *format, ...) { va_list args; va_start(args, format); basic_mud_vlog(format, args); va_end(args); } /** * Writes an entry to the log file. * @param format the printf-style format specifier string * @return none */ void basic_mud_vlog(const char *format, va_list args) { if (logfile == NULL) { printf("SYSERR: Using log() before stream was initialized!"); } else { time_t ct = time(0); char *time_s = asctime(localtime(&ct)); if (format == NULL) { format = "SYSERR: log() received a NULL format."; } time_s[strlen(time_s) - 1] = '\0'; fprintf(logfile, "%-15.15s :: ", time_s + 4); vfprintf(logfile, format, args); fputc('\n', logfile); fflush(logfile); } } /** * Logs when a player is killed by a death trap. * @param ch the character who was killed * @return none */ void log_death_trap(charData_t *ch) { mudlog(BRF, AUTH_WIZARD, TRUE, "%s hit death trap in '%s:%d'", GET_NAME(ch), IN_ROOM(ch)->zone->keyword, IN_ROOM(ch)->number); } /** * Broadcasts a log message to connected immortals, optionally writing an * entry is also written to the log file. * @param type the type of log entry * @param auth the minimum auth level required to received the broadcast * @param file whether the log message should be written to the log file * @param str the printf-style format string * @return none */ void mudlog(int type, int auth, bool file, const char *str, ...) { char buf[MAX_STRING_LENGTH]; descriptorData_t *i = NULL; va_list args; if (str == NULL) return; /* eh, oh well. */ if (file) { va_start(args, str); basic_mud_vlog(str, args); va_end(args); } if (auth < 0) return; va_start(args, str); vsnprintf(buf, sizeof(buf), str, args); va_end(args); /* Iterate over the descriptor list. */ for (i = descriptor_list; i; i = i->next) { if (STATE(i) != CON_PLAYING || IS_NPC(i->character)) continue; if (GET_AUTH(i->character) < auth) continue; if (PLR_FLAGGED(i->character, PLR_WRITING)) continue; if (type > (PRF_FLAGGED(i->character, PRF_LOG1) ? 1 : 0) + (PRF_FLAGGED(i->character, PRF_LOG2) ? 2 : 0)) continue; /* Send the log message to the character. */ send_to_char(i->character, "%s[%s]%s\r\n", CCGRN(i->character, C_NRM), buf, CCNRM(i->character, C_NRM)); } }