MOO-cows Mailing List Archive

[Prev][Next][Index][Thread]

Logging to a file, instead of to stderr



Here you go.
Example:  ./moo -l mymoo.log mymoo.db mymoo.db.new 4283
Um... i believe it works in emergency mode too, though my testing wasn't 
as robust in that area.

No warranty is expressed or implied by this hunk of code.  If it works 
for you, great.  If not, well, ask me real nice, and we'll talk.

Ryan Brown
rbrown@tfs.net
----------------------CUT HERE------------------------
diff -c3 MOO-1.8.0p2/log.c MOO-1.8.0p2/log.c
*** MOO-1.8.0p2/log.c	Thu Feb  8 01:00:50 1996
--- MOO-1.8.0p2/log.c	Wed Mar 20 13:15:27 1996
***************
*** 30,45 ****
--- 30,59 ----
  #include "streams.h"
  #include "utils.h"
  
+     extern int		log_external_file;
+     extern char        *external_log;
+ 
  static void
  do_log(const char *fmt, va_list args, const char *prefix)
  {
      time_t	now = time(0);
      char       *nowstr = ctime(&now);
+     FILE       *fp;
  
      nowstr[19] = '\0';	/* kill the year and newline at the end */
+ if (log_external_file) {
+     fp = fopen(external_log, "a");
+     if (fp) {
+     	fprintf(fp, "%s: %s", nowstr+4,prefix); /* skip the day of the week */
+     	vfprintf(fp, fmt, args);
+     	fclose(fp);
+     	}
+     }
+ else {
      fprintf(stderr, "%s: %s", nowstr + 4, prefix); /* skip the day of week */
      vfprintf(stderr, fmt, args);
      fflush(stderr);
+     }
  }
  
  void
diff -c3 MOO-1.8.0p2/server.c MOO-1.8.0p2/server.c
*** MOO-1.8.0p2/server.c	Tue Mar 19 01:10:11 1996
--- MOO-1.8.0p2/server.c	Wed Mar 20 13:17:40 1996
***************
*** 54,59 ****
--- 54,61 ----
  static const char      *shutdown_message = 0;	/* shut down if non-zero */
  static int		in_emergency_mode = 0;
  static Var		checkpointed_connections;
+ int			log_external_file = 0;
+ char		       *external_log;
  
  typedef enum {
      CHKPT_OFF, CHKPT_TIMER, CHKPT_SIGNAL, CHKPT_FUNC
***************
*** 1193,1198 ****
--- 1195,1207 ----
  	  case 'e':		/* Emergency wizard mode */
  	    emergency = 1;
  	    break;
+ 	  case 'l':
+ 	    log_external_file = 1;
+ 	    external_log = mymalloc(strlen(argv[1])+1, M_STRING);
+ 	    strcpy(external_log, argv[1]);
+ 	    argc--;
+ 	    argv++;
+ 	    break;
  	  default:
  	    argc = 0;		/* Provoke usage message below */
  	}
***************
*** 1210,1215 ****
--- 1219,1226 ----
      if (!db_initialize(&argc, &argv)
  	||  !network_initialize(argc, argv, &desc)) {
  	errlog("Usage: %s %s %s\n",
+ 		this_program, db_usage_string(), network_usage_string());
+ 	errlog("       %s -l <logfile> %s %s\n",
  		this_program, db_usage_string(), network_usage_string());
  	exit(1);
      }



Follow-Ups:

Home | Subject Index | Thread Index