> I'm trying to make it so that the mud logs all the info to a file, instead > of to the screen. > The ported version for win95 just printed the log command to the screen. > Information :- using vc4.0 in win95. Compiles fine (no warnings). Credit > is also given to Christopher M. Ryan whose has helped me by suggesting > these changes which I added. > > Thanks to those who can help. > > What i've done is this. > > in utils.c > ------------ > > void log(char *str) > // Added the use of LOGGING stuff to a SYSLOG file. > { > time_t ct; > char *tmstr; > /*added here*/ FILE *log; this FILE* log needs to be located outside of the function. (i.e. above void log(... ect. > > ct = time(0); > tmstr = asctime(localtime(&ct)); > *(tmstr + strlen(tmstr) - 1) = '\0'; > /*added here*/ fprintf(log, "%-19.19s :: %s\n", tmstr, str); > // fprintf(stderr, "%-19.19s :: %s\n", tmstr, str); > } > > Then in comm.c > ----------------------- > <snip> > extern FILE* log; > <snip> > > int main(int argc, char **argv) > { > int port; > char buf[512]; > int pos = 1; > char *dir; > > port = DFLT_PORT; > dir = DFLT_DIR; > > // Open the Log File to log all information. > /*Added this in .. This is where I get an error (the if statement (first > line) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > */ if ( (log = fopen("circle.log","w")) == NULL) { > printf ("creating new log file\n"); > } if log == NULL then the file wasn't opened.with w it will always overight you might want to make it so it appends or add some special handling. that way if the mud crashes and you have something to restart it you still have the log with the crash. > else { > printf ("overwriting old file\n"); > } > > while ((pos < argc) && (*(argv[pos]) == '-')) { > switch (*(argv[pos] + 1)) { > case 'd': > <etc.etc> > /*now at the end of main */ > <sinp snip> > } else { > sprintf(buf, "Running game on port %d.", port); > log(buf); > init_game(port); > } > > return 0; This return means exit the program. so you need to put the below code above the return. Don't worry about this mistake i do this quite often when editing code this large ;) > > /ADDED THIS IN TO CLOSE THE FILE ALSO*/ > // Must close the file when finished. > fclose(log); > } should be above the return like mentioned above. I hope this helps. Thanks for the credit too :) Christopher M. Ryan drizzt@visi.net http://www.visi.net/~drizzt/index.html +-----------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://cspo.queensu.ca/~fletcher/Circle/list_faq.html | +-----------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/18/00 PST