/* * This code written by Rahl (dwa1844@rit.edu) for Broken Shadows. * * It uses get_curdate from EmberMUD v0.20 or later * The date string is then parsed for '/' and replaces the * '/' with '-', opens a file in the "mm-dd-yy.log" format * in the log directory. Each time this function is called * it checks the current date (actually, the new log file name) * against the current log file name. If they're different, it * opens the new one and closes the old one. * * In effect, this makes 1 log file for each day of the week the * MUD is running. All the events for that day are stored in the * corresponding log file. * * This was inspired by Erwin's comments in the copyover code * that he wished it would make a new log file for each day * as log files could be huge and span many days as the MUD * never made a new one with the copyover code (as long as * there wasn't a crash, shutdown, etc) * * Permission to use this code is given freely as long as my * name stays with it. * - Daniel Anderson */ void log_string( const char *str ) { char *strtime; char logfile[20]; char buf[10]; char temp[20]; int i, j; FILE *log_file; FILE *tempfile; buf[0] = '\0'; temp[0] = '\0'; log_file = NULL; sprintf( buf, "%s", get_curdate() ); for ( i = 0; i < 10; i++ ) { if ( buf[i] == '/' ) buf[i] = '-'; } sprintf( temp, "../log/" ); strcat( temp, buf ); strcat( temp, ".log" ); if ( strcmp( temp, logfile ) ) { tempfile = fopen( temp, "a" ); if ( log_file != NULL ) fclose( log_file ); for ( j = 0; j < 20; j++ ) logfile[j] = temp[j]; log_file = fopen( logfile, "a" ); fclose( tempfile ); } strtime = ctime( ¤t_time ); strtime[strlen(strtime)-1] = '\0'; fprintf( log_file, "%s :: %s\n", strtime, str ); fclose( log_file ); return; } ============================================================================= / ______ _______ ____ _____ ___ __ _ ______ ____ ____ _____ / \ | ____|__ __| _ \ / ____\ / _ \| \ / | ____| / __ \| _ \ / ____\ \ / | |__ | | | |_| | | | |_| | |\/| | |___ | | | | |_| | | / / | ___| | | | ___/| | __| _ | | | | ____| | | | | __/| | ___ \ \ | | | | | | | |___| | | | | | | | |____ | |__| | |\ \| |___| | / / |_| |_| |_| o \_____/|_| |_|_| |_|______|o \____/|_| \_|\_____/ \ \ / ============================================================================ ------------------------------------------------------------------------------ ftp://ftp.game.org/pub/mud FTP.GAME.ORG http://www.game.org/ftpsite/ ------------------------------------------------------------------------------ This file came from FTP.GAME.ORG, the ultimate source for MUD resources. ------------------------------------------------------------------------------