MudOSa4DGD/
MudOSa4DGD/bin/
MudOSa4DGD/data/
MudOSa4DGD/doc/
MudOSa4DGD/doc/driver/
MudOSa4DGD/doc/efun/bitstrings/
MudOSa4DGD/doc/efun/command/
MudOSa4DGD/doc/efun/communication/
MudOSa4DGD/doc/efun/heart_beat/
MudOSa4DGD/doc/efun/interactive/
MudOSa4DGD/doc/efun/inventory/
MudOSa4DGD/doc/efun/living/
MudOSa4DGD/doc/efun/mappings/
MudOSa4DGD/doc/efun/strings/
MudOSa4DGD/doc/efun/uid/
MudOSa4DGD/doc/funs/
MudOSa4DGD/doc/language/
MudOSa4DGD/mudlib/dgd/doc/
MudOSa4DGD/mudlib/dgd/lib/include/dgd/
MudOSa4DGD/mudlib/dgd/lib/std/
MudOSa4DGD/mudlib/dgd/lib/sys/
MudOSa4DGD/mudlib/dgd/log/
MudOSa4DGD/mudlib/log/
MudOSa4DGD/mudlib/std/include/
MudOSa4DGD/mudlib/std/obj/
/*
 * log_file.c
 *
 * SFUN: Log a message to file
 *
 * (C) Frank Schmidt, Jesus@NorseMUD
 *
 */

#include <std.h>

/* max filesizes for logfiles */
#define MAX_LOG_SIZE      200000
#define MAX_ENTER_LOG    1000000


static int log_file(string file, string what) {
  int maxlog, nr;
  string pre;

  /* wrong file? */
  if (!file || !strlen(file))
    return 0;

  /* absolute path, or not? */
  if (file[0] != '/') {
    /* parse the path into domains and playerdirs */
    string pfile, domain;
    pfile = file_name();
    if (sscanf(pfile, DOMAIN_DIR+"%s/%*s", domain) == 2)
      file = DOMAIN_DIR+domain+LOCAL_LOG_DIR+file;
    else if (sscanf(pfile, PLAYER_DIR+"%s/%*s", domain) == 2)
      file = PLAYER_DIR+domain+LOCAL_LOG_DIR+file;
    else
      /* set default path for log_file */
      file = LOG_DIR + file;
  }

  /*D_LOGWATCH->logwatch(file, what); */

  if (file == LOG_DIR+"ENTER")
    maxlog = MAX_ENTER_LOG;
  else
    maxlog = MAX_LOG_SIZE;

  /* save exceeded log file, and start fresh? */
  if (file_size(file) > maxlog) {
    rename_file(file, file+".old");
  }

  pre = short_ctime(time()) + " ";
  if (nr=GLOBAL->log_file(file, what))
    pre = "Last message repeated "+(string)nr+" times.\n" + pre;
  if (nr != -1)
    /* append <what> message to logfile */
    return write_file(file, pre + what);
  return 1;
}