Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CF: llevInfo log level



I will apply this patch to the CVS tree if there are no objections.  It
adds a new llevInfo log level and replaces some LOG(llevError) with
LOG(llevInfo).  The result is more efficient debugging with a simple

  break LOG if logLevel == llevError


*** orig/crossfire-0.95.5-cvs1/common/init.c	Tue Jul 13 08:02:41 1999
--- crossfire-0.95.5-cvs1/common/init.c	Thu May 18 11:49:04 2000
***************
*** 38,48 ****
  
  /* Debug level */
  #ifdef DEBUG
    llevDebug,
  #else
!   llevError,
  #endif
  
  0, NULL, 0,    /* dumpvalues, dumparg, daemonmode */
  0, /* argc */
  NULL, /* argv */
--- 38,48 ----
  
  /* Debug level */
  #ifdef DEBUG
    llevDebug,
  #else
!   llevInfo,
  #endif
  
  0, NULL, 0,    /* dumpvalues, dumparg, daemonmode */
  0, /* argc */
  NULL, /* argv */
*** orig/crossfire-0.95.5-cvs1/common/logger.c	Tue Jul 13 08:02:41 1999
--- crossfire-0.95.5-cvs1/common/logger.c	Thu May 18 11:49:23 2000
***************
*** 32,42 ****
  
  /*
   * Logs a message to stderr, or to file, and/or even to socket.
   * Or discards the message if it is of no importanse, and none have
   * asked to hear messages of that logLevel.
!  * logLevels can be logError (always printed), llevDebug, and llevMonster.
   */
  
  void LOG (LogLevel logLevel, char *format, ...)
  {
    char buf[20480];  /* This needs to be really really big - larger
--- 32,44 ----
  
  /*
   * Logs a message to stderr, or to file, and/or even to socket.
   * Or discards the message if it is of no importanse, and none have
   * asked to hear messages of that logLevel.
!  *
!  * See include/logger.h for possible logLevels.  Messages with llevInfo
!  * and llevError are always printed, regardless of debug mode.
   */
  
  void LOG (LogLevel logLevel, char *format, ...)
  {
    char buf[20480];  /* This needs to be really really big - larger
*** orig/crossfire-0.95.5-cvs1/include/logger.h	Tue Jul 13 08:02:52 1999
--- crossfire-0.95.5-cvs1/include/logger.h	Thu May 18 11:08:38 2000
***************
*** 27,35 ****
  
  #ifndef LOGGER_H
  #define LOGGER_H
  
  typedef enum LogLevel {
!   llevError = 0, llevDebug = 1, llevMonster = 2
  } LogLevel;
  
  #endif /* LOGGER_H */
--- 27,35 ----
  
  #ifndef LOGGER_H
  #define LOGGER_H
  
  typedef enum LogLevel {
!   llevError = 0, llevInfo = 1, llevDebug = 2, llevMonster = 3
  } LogLevel;
  
  #endif /* LOGGER_H */
*** orig/crossfire-0.95.5-cvs1/server/init.c	Mon Aug 23 02:26:12 1999
--- crossfire-0.95.5-cvs1/server/init.c	Thu May 18 11:52:31 2000
***************
*** 35,45 ****
  
  void set_logfile(char *val) { settings.logfilename=val; }
  void call_version() { version(NULL); exit(0); }
  void showscores() { display_high_score(NULL,9999,NULL); exit(0); }
  void set_debug() { settings.debug=llevDebug; }
! void unset_debug() { settings.debug=llevError; }
  void set_mondebug() { settings.debug=llevMonster; }
  void set_dumpmon1() {settings.dumpvalues=1; }
  void set_dumpmon2() {settings.dumpvalues=2; }
  void set_dumpmon3() {settings.dumpvalues=3; }
  void set_dumpmon4() {settings.dumpvalues=4; }
--- 35,45 ----
  
  void set_logfile(char *val) { settings.logfilename=val; }
  void call_version() { version(NULL); exit(0); }
  void showscores() { display_high_score(NULL,9999,NULL); exit(0); }
  void set_debug() { settings.debug=llevDebug; }
! void unset_debug() { settings.debug=llevInfo; }
  void set_mondebug() { settings.debug=llevMonster; }
  void set_dumpmon1() {settings.dumpvalues=1; }
  void set_dumpmon2() {settings.dumpvalues=2; }
  void set_dumpmon3() {settings.dumpvalues=3; }
  void set_dumpmon4() {settings.dumpvalues=4; }
***************
*** 471,496 ****
  }
  
  /* Signal handlers: */
  
  void rec_sigsegv(int i) {
!   LOG(llevError,"\nSIGSEGV received.\n");
    fatal_signal(1, 1);
  }
  
  void rec_sigint(int i) {
!   LOG(llevError,"\nSIGINT received.\n");
    fatal_signal(0, 1);
  }
  
  void rec_sighup(int i) {
!   LOG(llevError,"\nSIGHUP received\n");
    fatal_signal(0, 1);
  }
  
  void rec_sigquit(int i) {
!   LOG(llevError,"\nSIGQUIT received\n");
    fatal_signal(1, 1);
  }
  
  void rec_sigpipe(int i) {
  
--- 471,496 ----
  }
  
  /* Signal handlers: */
  
  void rec_sigsegv(int i) {
!   LOG(llevInfo,"\nSIGSEGV received.\n");
    fatal_signal(1, 1);
  }
  
  void rec_sigint(int i) {
!   LOG(llevInfo,"\nSIGINT received.\n");
    fatal_signal(0, 1);
  }
  
  void rec_sighup(int i) {
!   LOG(llevInfo,"\nSIGHUP received\n");
    fatal_signal(0, 1);
  }
  
  void rec_sigquit(int i) {
!   LOG(llevInfo,"\nSIGQUIT received\n");
    fatal_signal(1, 1);
  }
  
  void rec_sigpipe(int i) {
  
***************
*** 500,526 ****
   * doing much good.  However, if it core dumps later on, at least it can
   * be looked at later on, and maybe fix the problem that caused it to
   * dump core.  There is no reason that SIGPIPES should be fatal
   */
  #if 1
!   LOG(llevError,"\nReceived SIGPIPE, ignoring...\n");
    signal(SIGPIPE,rec_sigpipe);/* hocky-pux clears signal handlers */
  #else
!   LOG(llevError,"\nSIGPIPE received, not ignoring...\n");
    fatal_signal(1, 1); /*Might consider to uncomment this line */
  #endif
  }
  
  void rec_sigbus(int i) {
  #ifdef SIGBUS
!   LOG(llevError,"\nSIGBUS received\n");
    fatal_signal(1, 1);
  #endif
  }
  
  void rec_sigterm(int i) {
!   LOG(llevError,"\nSIGTERM received\n");
    fatal_signal(0, 1);
  }
  
  void fatal_signal(int make_core, int close_sockets) {
    if(init_done) {
--- 500,526 ----
   * doing much good.  However, if it core dumps later on, at least it can
   * be looked at later on, and maybe fix the problem that caused it to
   * dump core.  There is no reason that SIGPIPES should be fatal
   */
  #if 1
!   LOG(llevInfo,"\nReceived SIGPIPE, ignoring...\n");
    signal(SIGPIPE,rec_sigpipe);/* hocky-pux clears signal handlers */
  #else
!   LOG(llevInfo,"\nSIGPIPE received, not ignoring...\n");
    fatal_signal(1, 1); /*Might consider to uncomment this line */
  #endif
  }
  
  void rec_sigbus(int i) {
  #ifdef SIGBUS
!   LOG(llevInfo,"\nSIGBUS received\n");
    fatal_signal(1, 1);
  #endif
  }
  
  void rec_sigterm(int i) {
!   LOG(llevInfo,"\nSIGTERM received\n");
    fatal_signal(0, 1);
  }
  
  void fatal_signal(int make_core, int close_sockets) {
    if(init_done) {
*** orig/crossfire-0.95.5-cvs1/socket/loop.c	Tue Jul 13 08:03:06 1999
--- crossfire-0.95.5-cvs1/socket/loop.c	Thu May 18 10:55:20 2000
***************
*** 359,369 ****
  
  #ifdef WATCHDOG
      struct timeval Timeout;
      fd_set readfs;
  
!     LOG(llevError, "Waiting for connections...\n");
  
      do {
  	FD_ZERO(&readfs);
  	FD_SET(init_sockets[0].fd, &readfs);
  	Timeout.tv_sec=60;
--- 359,369 ----
  
  #ifdef WATCHDOG
      struct timeval Timeout;
      fd_set readfs;
  
!     LOG(llevInfo, "Waiting for connections...\n");
  
      do {
  	FD_ZERO(&readfs);
  	FD_SET(init_sockets[0].fd, &readfs);
  	Timeout.tv_sec=60;
***************
*** 372,382 ****
  	}
      while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout)==0);
  #else
      fd_set readfs;
  
!     LOG(llevError, "Waiting for connections...\n");
  
      FD_ZERO(&readfs);
      FD_SET(init_sockets[0].fd, &readfs);
      (void) select(socket_info.max_filedescriptor, &readfs, NULL, NULL, NULL);
  #endif
--- 372,382 ----
  	}
      while (select(socket_info.max_filedescriptor, &readfs, NULL, NULL, &Timeout)==0);
  #else
      fd_set readfs;
  
!     LOG(llevInfo, "Waiting for connections...\n");
  
      FD_ZERO(&readfs);
      FD_SET(init_sockets[0].fd, &readfs);
      (void) select(socket_info.max_filedescriptor, &readfs, NULL, NULL, NULL);
  #endif
*** orig/crossfire-0.95.5-cvs1/socket/lowlevel.c        Mon Apr 26 23:00:30 1999
--- crossfire-0.95.5-cvs1/socket/lowlevel.c     Thu May 18 12:37:50 2000
***************
*** 381,391 ****
      /* If no connections recently, don't both to log anything */
      if (cst_lst.ibytes==0 && cst_lst.obytes==0) return;
  
      /* It really isn't an error, but I really want it logged in all cases */
      /* CSSTAT is put in so scripts can easily find the line */
!     LOG(llevError, "CSSTAT: %.16s tot %d %d %d %d inc %d %d %d %d\n",
        ctime(&now), cst_tot.ibytes, cst_tot.obytes, cst_tot.max_conn,
        now - cst_tot.time_start, cst_lst.ibytes, cst_lst.obytes,
        cst_lst.max_conn, now - cst_lst.time_start);
      cst_lst.ibytes=0;
      cst_lst.obytes=0;
--- 381,391 ----
      /* If no connections recently, don't both to log anything */
      if (cst_lst.ibytes==0 && cst_lst.obytes==0) return;
  
      /* It really isn't an error, but I really want it logged in all cases */
      /* CSSTAT is put in so scripts can easily find the line */
!     LOG(llevInfo, "CSSTAT: %.16s tot %d %d %d %d inc %d %d %d %d\n",
        ctime(&now), cst_tot.ibytes, cst_tot.obytes, cst_tot.max_conn,
        now - cst_tot.time_start, cst_lst.ibytes, cst_lst.obytes,
        cst_lst.max_conn, now - cst_lst.time_start);
      cst_lst.ibytes=0;
      cst_lst.obytes=0;
*** orig/crossfire-0.95.5-cvs1/server/attack.c	Wed Apr  5 06:40:52 2000
--- crossfire-0.95.5-cvs1/server/attack.c	Thu May 18 12:00:44 2000
***************
*** 294,304 ****
      signed char luck=0;
  
      if(op->head!=NULL)
  	op=op->head;
      if(op->name==NULL) {
! 	if(settings.debug) {
  	    dump_object(op);
  	    LOG(llevDebug,"Object without name tried to attack.\n%s\n",errmsg);
  	}
  	if (QUERY_FLAG(op, FLAG_REMOVED) && !QUERY_FLAG(op, FLAG_FREED))
  	    free_object(op);
--- 294,304 ----
      signed char luck=0;
  
      if(op->head!=NULL)
  	op=op->head;
      if(op->name==NULL) {
! 	if(settings.debug >= llevDebug) {
  	    dump_object(op);
  	    LOG(llevDebug,"Object without name tried to attack.\n%s\n",errmsg);
  	}
  	if (QUERY_FLAG(op, FLAG_REMOVED) && !QUERY_FLAG(op, FLAG_FREED))
  	    free_object(op);
***************
*** 325,335 ****
      add_refcount(op_name = op->name);
      if(hitter->head!=NULL)
  	hitter=hitter->head;
  
      if (hitter->name==NULL) {
! 	if(settings.debug) {
  	    dump_object(hitter);
  	    LOG(llevDebug,"Object without name tried to attack.\n%s\n",errmsg);
  	}
  	return 1;
      }
--- 325,335 ----
      add_refcount(op_name = op->name);
      if(hitter->head!=NULL)
  	hitter=hitter->head;
  
      if (hitter->name==NULL) {
! 	if(settings.debug >= llevDebug) {
  	    dump_object(hitter);
  	    LOG(llevDebug,"Object without name tried to attack.\n%s\n",errmsg);
  	}
  	return 1;
      }
***************
*** 734,745 ****
      if(QUERY_FLAG(op,FLAG_WIZ)||!QUERY_FLAG(op,FLAG_ALIVE)||op->stats.hp<0)
  	return 0;
  
      /* If its already dead, or we're the wizard, don't attack it - no point */
      if(hitter->name==NULL) {
! 	if (settings.debug) 
! 	    LOG(llevDebug, "hit_player: hitter has no name\n");
  	return 0;
      }
  
  #ifdef ATTACK_DEBUG
      LOG(llevDebug,"hit player: attacktype %d, dam %d\n", type, dam);
--- 734,744 ----
      if(QUERY_FLAG(op,FLAG_WIZ)||!QUERY_FLAG(op,FLAG_ALIVE)||op->stats.hp<0)
  	return 0;
  
      /* If its already dead, or we're the wizard, don't attack it - no point */
      if(hitter->name==NULL) {
! 	LOG(llevDebug, "hit_player: hitter has no name\n");
  	return 0;
      }
  
  #ifdef ATTACK_DEBUG
      LOG(llevDebug,"hit player: attacktype %d, dam %d\n", type, dam);
*** orig/crossfire-0.95.5-cvs1/server/login.c   Sat Mar 11 08:06:27 2000
--- crossfire-0.95.5-cvs1/server/login.c        Thu May 18 12:20:50 2000
***************
*** 74,84 ****
      }
      check_score(pl->ob);
    }
    LOG(llevError,"\n");
  #else
!   LOG(llevError,"Emergency saves disabled, no save attempted\n");
  #endif
    /* If the game is exiting, remove the player locks */
    if (!flag) {
      for(pl=first_player;pl!=NULL;pl=pl->next) {
        if(pl->ob) {
--- 74,84 ----
      }
      check_score(pl->ob);
    }
    LOG(llevError,"\n");
  #else
!   LOG(llevInfo,"Emergency saves disabled, no save attempted\n");
  #endif
    /* If the game is exiting, remove the player locks */
    if (!flag) {
      for(pl=first_player;pl!=NULL;pl=pl->next) {
        if(pl->ob) {
***************
*** 94,104 ****
   */
  void delete_character(char *name, int new) {
      char buf[MAX_BUF];
  
      sprintf(buf,"%s/%s/%s.pl",settings.localdir,settings.playerdir,name);
!     if(unlink(buf)== -1 && settings.debug)
        perror("crossfire (delete character)");
      if (new) {
        sprintf(buf,"%s/%s/%s",settings.localdir,settings.playerdir,name);
        /* this effectively does an rm -rf on the directory */
        remove_directory(buf);
--- 94,104 ----
   */
  void delete_character(char *name, int new) {
      char buf[MAX_BUF];
  
      sprintf(buf,"%s/%s/%s.pl",settings.localdir,settings.playerdir,name);
!     if(unlink(buf)== -1 && settings.debug >= llevDebug)
        perror("crossfire (delete character)");
      if (new) {
        sprintf(buf,"%s/%s/%s",settings.localdir,settings.playerdir,name);
        /* this effectively does an rm -rf on the directory */
        remove_directory(buf);
*** orig/crossfire-0.95.5-cvs1/server/main.c    Fri Apr  7 05:26:25 2000
--- crossfire-0.95.5-cvs1/server/main.c Thu May 18 12:22:43 2000
***************
*** 754,764 ****
  }
  
  void clean_tmp_files() {
    mapstruct *m;
  
!   LOG(llevError,"Cleaning up...\n");
  
    /* We save the maps - it may not be intuitive why, but if there are unique
     * items, we need to save the map so they get saved off.  Perhaps we should
     * just make a special function that only saves the unique items.
     */
--- 754,764 ----
  }
  
  void clean_tmp_files() {
    mapstruct *m;
  
!   LOG(llevInfo,"Cleaning up...\n");
  
    /* We save the maps - it may not be intuitive why, but if there are unique
     * items, we need to save the map so they get saved off.  Perhaps we should
     * just make a special function that only saves the unique items.
     */
*** orig/crossfire-0.95.5-cvs1/server/monster.c	Wed Apr 12 08:38:04 2000
--- crossfire-0.95.5-cvs1/server/monster.c	Thu May 18 12:01:24 2000
***************
*** 1328,1338 ****
  
    if(npc->msg == NULL || *npc->msg != '@')
      return 0;
    if((msgs = parse_message(npc->msg)) == NULL)
      return 0;
!   if(settings.debug)
      dump_messages(msgs);
    for(i=0; msgs->messages[i]; i++)
      for(j=0; msgs->keywords[i][j]; j++)
        if(msgs->keywords[i][j][0] == '*' || re_cmp(txt,msgs->keywords[i][j])) {
          if (msgs->messages[i] && *msgs->messages[i] != 0)
--- 1328,1338 ----
  
    if(npc->msg == NULL || *npc->msg != '@')
      return 0;
    if((msgs = parse_message(npc->msg)) == NULL)
      return 0;
!   if(settings.debug >= llevDebug)
      dump_messages(msgs);
    for(i=0; msgs->messages[i]; i++)
      for(j=0; msgs->keywords[i][j]; j++)
        if(msgs->keywords[i][j][0] == '*' || re_cmp(txt,msgs->keywords[i][j])) {
          if (msgs->messages[i] && *msgs->messages[i] != 0)
*** orig/crossfire-0.95.5-cvs1/server/player.c	Mon May 15 22:35:14 2000
--- crossfire-0.95.5-cvs1/server/player.c	Thu May 18 12:01:41 2000
***************
*** 750,760 ****
  #ifdef SET_TITLE
      op->contr->own_title[0]='\0';
  #endif /* SET_TITLE */
      if(!QUERY_FLAG(op,FLAG_WAS_WIZ)) {
        sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,op->name,op->name);
!       if(unlink(buf)== -1 && settings.debug)
          perror("crossfire (delete character)");
      }
      play_again(op);
      return 1;
  }
--- 750,760 ----
  #ifdef SET_TITLE
      op->contr->own_title[0]='\0';
  #endif /* SET_TITLE */
      if(!QUERY_FLAG(op,FLAG_WAS_WIZ)) {
        sprintf(buf,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,op->name,op->name);
!       if(unlink(buf)== -1 && settings.debug >= llevDebug)
          perror("crossfire (delete character)");
      }
      play_again(op);
      return 1;
  }
-- 
Jan
-
[you can put yourself on the announcement list only or unsubscribe altogether
by sending an email stating your wishes to ]