src/log.c File Reference

#include "copyright.h"
#include "config.h"
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include "db.h"
#include "mudconf.h"
#include "externs.h"
#include "flags.h"
#include "powers.h"
#include "alloc.h"
#include "htab.h"
#include "ansi.h"

Include dependency graph for log.c:

Go to the source code of this file.

Functions

char * strip_ansi_r (char *dest, const char *raw, size_t n)
char * normal_to_white_r (char *dest, const char *raw, size_t n)
int start_log (const char *primary, const char *secondary)
void end_log (void)
void log_perror (const char *primary, const char *secondary, const char *extra, const char *failing_object)
void log_text (char *text)
void log_error (int key, char *primary, char *secondary, char *format,...)
void log_printf (char *format,...)
void log_number (int num)
void log_name (dbref target)
void log_name_and_loc (dbref player)
char * OBJTYP (dbref thing)
void log_type_and_name (dbref thing)
void log_type_and_num (dbref thing)

Variables

NAMETAB logdata_nametab []
NAMETAB logoptions_nametab []


Function Documentation

void end_log ( void   ) 

Finish up writing a log entry

Definition at line 157 of file log.c.

References statedata::logging, and mudstate.

00158 {
00159         fprintf(stderr, "\n");
00160         fflush(stderr);
00161         mudstate.logging--;
00162 }

void log_error ( int  key,
char *  primary,
char *  secondary,
char *  format,
  ... 
)

Definition at line 191 of file log.c.

References statedata::buffer, LBUF_SIZE, confdata::log_info, confdata::log_options, LOGOPT_TIMESTAMP, confdata::mud_name, mudconf, mudstate, strip_ansi_r(), and time().

Referenced by accept_new_connection(), bind_signals(), cf_log_notfound(), cf_log_syntax(), cf_set(), cf_status_from_succfail(), cf_string(), do_command(), do_link(), do_unauth_command(), eradicate_broken_fd(), fcache_read(), fork_and_dump(), process_command(), and shutdownsock().

00192 {
00193         char buffer[LBUF_SIZE];
00194         char stripped_buffer[LBUF_SIZE];
00195         va_list ap;
00196 
00197     if(!(key & mudconf.log_options))
00198                 return;
00199 
00200         if(mudconf.log_info & LOGOPT_TIMESTAMP) {
00201                 time_t now;
00202                 struct tm tm;
00203                 time(&now);
00204                 localtime_r(&now, &tm);
00205                 fprintf(stderr, "%d%02d%02d.%02d%02d%02d ",
00206                                 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
00207                                 tm.tm_hour, tm.tm_min, tm.tm_sec);
00208         }
00209 
00210         if(secondary && &secondary) {
00211                 fprintf(stderr, "%s%s %3s/%-5s: ", mudstate.buffer,
00212                                 mudconf.mud_name, primary, secondary);
00213         } else {
00214                 fprintf(stderr, "%s%s %-9s: ", mudstate.buffer,
00215                                 mudconf.mud_name, primary);
00216         }
00217 
00218         va_start(ap, format);
00219         vsnprintf(buffer, LBUF_SIZE, format, ap);
00220         va_end(ap);
00221 
00222         strip_ansi_r(stripped_buffer, buffer, LBUF_SIZE);
00223         fprintf(stderr, "%s\n", stripped_buffer);
00224 }

void log_name ( dbref  target  ) 

Writes the name, db number, and flags of an object to the log. If the object does not own itself, append the name, db number, and flags of the owner.

Definition at line 253 of file log.c.

References free_lbuf, GOD, LBUF_SIZE, confdata::log_info, LOGOPT_FLAGS, LOGOPT_OWNER, mudconf, Owner, strip_ansi_r(), unparse_object(), and unparse_object_numonly().

Referenced by check_connect(), do_boot(), do_fixdb(), do_name(), do_newpassword(), do_pcreate(), do_quota(), do_restart(), do_say(), do_shutdown(), do_toad(), failconn(), and log_name_and_loc().

00254 {
00255         char *tp;
00256         char new[LBUF_SIZE];
00257 
00258         if((mudconf.log_info & LOGOPT_FLAGS) != 0)
00259                 tp = unparse_object((dbref) GOD, target, 0);
00260         else
00261                 tp = unparse_object_numonly(target);
00262         strncpy(new, tp, LBUF_SIZE-1);
00263         fprintf(stderr, "%s", strip_ansi_r(new,tp,strlen(tp)));
00264         free_lbuf(tp);
00265         if(((mudconf.log_info & LOGOPT_OWNER) != 0) && (target != Owner(target))) {
00266                 if((mudconf.log_info & LOGOPT_FLAGS) != 0)
00267                         tp = unparse_object((dbref) GOD, Owner(target), 0);
00268                 else
00269                         tp = unparse_object_numonly(Owner(target));
00270                 strncpy(new, tp, LBUF_SIZE-1);
00271                 fprintf(stderr, "[%s]", strip_ansi_r(new,tp,strlen(tp)));
00272                 free_lbuf(tp);
00273         }
00274         return;
00275 }

void log_name_and_loc ( dbref  player  ) 

Log both the name and location of an object

Definition at line 280 of file log.c.

References Has_location, Location, confdata::log_info, log_name(), log_text(), LOGOPT_LOC, and mudconf.

Referenced by check_connect(), do_boot(), do_toad(), eval_boolexp(), process_command(), and report().

00281 {
00282         log_name(player);
00283         if((mudconf.log_info & LOGOPT_LOC) && Has_location(player)) {
00284                 log_text((char *) " in ");
00285                 log_name(Location(player));
00286         }
00287         return;
00288 }

void log_number ( int  num  ) 

Definition at line 243 of file log.c.

Referenced by Log_header_err().

00244 {
00245         fprintf(stderr, "%d", num);
00246 }

void log_perror ( const char *  primary,
const char *  secondary,
const char *  extra,
const char *  failing_object 
)

Write perror message to the log

Definition at line 167 of file log.c.

References log_text(), statedata::logging, mudstate, and start_log().

Referenced by bind_mux_socket(), close_sockets(), dnschild_finish(), dnschild_request(), dump_database_internal(), init_rlimit(), logcache_open(), make_blocking(), make_nonblocking(), network_bind_port(), network_make_blocking(), network_make_nonblocking(), and SaveSpecialObjects().

00169 {
00170         start_log(primary, secondary);
00171         if(extra && *extra) {
00172                 log_text((char *) "(");
00173                 log_text((char *) extra);
00174                 log_text((char *) ") ");
00175         }
00176         perror((char *) failing_object);
00177         fflush(stderr);
00178         mudstate.logging--;
00179 }

void log_printf ( char *  format,
  ... 
)

Definition at line 226 of file log.c.

References LBUF_SIZE, and strip_ansi_r().

Referenced by network_accept_client(), network_init(), and network_initialize_socket().

00227 {
00228         char buffer[LBUF_SIZE];
00229         char stripped_buffer[LBUF_SIZE];
00230         va_list ap;
00231 
00232         va_start(ap, format);
00233         vsnprintf(buffer, LBUF_SIZE, format, ap);
00234         va_end(ap);
00235 
00236         strip_ansi_r(stripped_buffer, buffer, LBUF_SIZE);
00237         fprintf(stderr, "%s\n", stripped_buffer);
00238 }

void log_text ( char *  text  ) 

Write text to log file.

Definition at line 184 of file log.c.

References LBUF_SIZE, and strip_ansi_r().

Referenced by announce_connect(), announce_disconnect(), check_connect(), create_guest(), desc_delhash(), do_boot(), do_fixdb(), do_help(), do_mail_nuke(), do_name(), do_newpassword(), do_pcreate(), do_quota(), do_restart(), do_say(), do_shutdown(), do_toad(), dump_database(), eval_boolexp(), failconn(), helpindex_read(), init_version(), load_game(), Log_header_err(), log_name_and_loc(), log_perror(), Log_pointer_err(), Log_simple_err(), log_type_and_name(), log_type_and_num(), mail_match(), main(), process_command(), and report().

00185 {
00186         char new[LBUF_SIZE];
00187         strncpy(new, text, LBUF_SIZE-1);
00188         fprintf(stderr, "%s", strip_ansi_r(new,text,strlen(text)));
00189 }

void log_type_and_name ( dbref  thing  ) 

Definition at line 314 of file log.c.

References Good_obj, log_text(), Name(), and OBJTYP().

Referenced by Log_header_err(), Log_pointer_err(), and Log_simple_err().

00315 {
00316         char nbuf[16];
00317 
00318         log_text(OBJTYP(thing));
00319         sprintf(nbuf, " #%d(", thing);
00320         log_text(nbuf);
00321         if(Good_obj(thing))
00322                 log_text(Name(thing));
00323         log_text((char *) ")");
00324         return;
00325 }

void log_type_and_num ( dbref  thing  ) 

Definition at line 327 of file log.c.

References log_text(), and OBJTYP().

00328 {
00329         char nbuf[16];
00330 
00331         log_text(OBJTYP(thing));
00332         sprintf(nbuf, " #%d", thing);
00333         log_text(nbuf);
00334         return;
00335 }

char* normal_to_white_r ( char *  dest,
const char *  raw,
size_t  n 
)

Definition at line 74 of file log.c.

References ESC_CHAR.

00074                                                                {
00075     char *p = (char *) raw;
00076         char *q = dest;
00077     
00078         while (p && *p && ((q - dest) < n)) {
00079                 if(*p == ESC_CHAR) {
00080                         /*
00081                          * Start of ANSI code. 
00082                          */
00083                         *q++ = *p++;            /*
00084                                                                  * ESC CHAR 
00085                                                                  */
00086                         *q++ = *p++;            /*
00087                                                                  * [ character. 
00088                                                                  */
00089                         if(*p == '0') {
00090                 if((q - dest + 7) < n) {
00091                     memcpy(q, "0m\x1b[37m", 7);
00092                     q += 7;
00093                 }
00094                                 p += 2;
00095                         }
00096                 } else
00097                         *q++ = *p++;
00098         }
00099         *q = '\0';
00100         return dest;
00101 }

char* OBJTYP ( dbref  thing  ) 

Definition at line 293 of file log.c.

References Good_obj, TYPE_EXIT, TYPE_GARBAGE, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, and Typeof.

Referenced by log_type_and_name(), and log_type_and_num().

00294 {
00295         if(!Good_obj(thing)) {
00296                 return (char *) "??OUT-OF-RANGE??";
00297         }
00298         switch (Typeof(thing)) {
00299         case TYPE_PLAYER:
00300                 return (char *) "PLAYER";
00301         case TYPE_THING:
00302                 return (char *) "THING";
00303         case TYPE_ROOM:
00304                 return (char *) "ROOM";
00305         case TYPE_EXIT:
00306                 return (char *) "EXIT";
00307         case TYPE_GARBAGE:
00308                 return (char *) "GARBAGE";
00309         default:
00310                 return (char *) "??ILLEGAL??";
00311         }
00312 }

int start_log ( const char *  primary,
const char *  secondary 
)

See if it's is OK to log something, and if so, start writing the log entry.

Definition at line 107 of file log.c.

References statedata::buffer, confdata::log_info, statedata::logging, LOGOPT_TIMESTAMP, confdata::mud_name, mudconf, mudstate, and time().

Referenced by log_perror().

00108 {
00109         struct tm *tp;
00110         time_t now;
00111 
00112         mudstate.logging++;
00113         switch (mudstate.logging) {
00114         case 1:
00115         case 2:
00116 
00117                 /*
00118                  * Format the timestamp 
00119                  */
00120 
00121                 if((mudconf.log_info & LOGOPT_TIMESTAMP) != 0) {
00122                         time((time_t *) (&now));
00123                         tp = localtime((time_t *) (&now));
00124                         sprintf(mudstate.buffer, "%d%02d%02d.%02d%02d%02d ",
00125                                         tp->tm_year + 1900, tp->tm_mon + 1, tp->tm_mday,
00126                                         tp->tm_hour, tp->tm_min, tp->tm_sec);
00127                 } else {
00128                         mudstate.buffer[0] = '\0';
00129                 }
00130 
00131                 /*
00132                  * Write the header to the log 
00133                  */
00134 
00135                 if(secondary && *secondary)
00136                         fprintf(stderr, "%s%s %3s/%-5s: ", mudstate.buffer,
00137                                         mudconf.mud_name, primary, secondary);
00138                 else
00139                         fprintf(stderr, "%s%s %-9s: ", mudstate.buffer,
00140                                         mudconf.mud_name, primary);
00141                 /*
00142                  * If a recursive call, log it and return indicating no log 
00143                  */
00144 
00145                 if(mudstate.logging == 1)
00146                         return 1;
00147                 fprintf(stderr, "Recursive logging request.\r\n");
00148         default:
00149                 mudstate.logging--;
00150         }
00151         return 0;
00152 }

char* strip_ansi_r ( char *  dest,
const char *  raw,
size_t  n 
)

Definition at line 53 of file log.c.

References ESC_CHAR.

Referenced by decompile_powers(), do_channelwho(), do_create(), do_decomp(), do_name(), fun_center(), fun_columns(), fun_edit(), fun_ljust(), fun_mid(), fun_rjust(), fun_stripansi(), fun_strlen(), fun_strtrunc(), log_error(), log_name(), log_printf(), log_text(), Name(), ok_name(), PureName(), queue_string(), and s_Name().

00054 {
00055         char *p = (char *) raw;
00056         char *q = dest;
00057 
00058         while (p && *p && ((q - dest) < n)) {
00059                 if(*p == ESC_CHAR) {
00060                         /*
00061                          * Start of ANSI code. Skip to end. 
00062                          */
00063                         while (*p && !isalpha(*p))
00064                                 p++;
00065                         if(*p)
00066                                 p++;
00067                 } else
00068                         *q++ = *p++;
00069         }
00070         *q = '\0';
00071         return dest;
00072 }


Variable Documentation

NAMETAB logdata_nametab[]

Initial value:

 {
        {(char *) "flags", 1, 0, LOGOPT_FLAGS},
        {(char *) "location", 1, 0, LOGOPT_LOC},
        {(char *) "owner", 1, 0, LOGOPT_OWNER},
        {(char *) "timestamp", 1, 0, LOGOPT_TIMESTAMP},
        {NULL, 0, 0, 0}
}

Definition at line 24 of file log.c.

NAMETAB logoptions_nametab[]

Initial value:

 {
        {(char *) "accounting", 2, 0, LOG_ACCOUNTING},
        {(char *) "all_commands", 2, 0, LOG_ALLCOMMANDS},
        {(char *) "suspect_commands", 2, 0, LOG_SUSPECTCMDS},
        {(char *) "bad_commands", 2, 0, LOG_BADCOMMANDS},
        {(char *) "buffer_alloc", 3, 0, LOG_ALLOCATE},
        {(char *) "bugs", 3, 0, LOG_BUGS},
        {(char *) "checkpoints", 2, 0, LOG_DBSAVES},
        {(char *) "config_changes", 2, 0, LOG_CONFIGMODS},
        {(char *) "create", 2, 0, LOG_PCREATES},
        {(char *) "killing", 1, 0, LOG_KILLS},
        {(char *) "logins", 1, 0, LOG_LOGIN},
        {(char *) "network", 1, 0, LOG_NET},
        {(char *) "problems", 1, 0, LOG_PROBLEMS},
        {(char *) "security", 2, 0, LOG_SECURITY},
        {(char *) "shouts", 2, 0, LOG_SHOUTS},
        {(char *) "startup", 2, 0, LOG_STARTUP},
        {(char *) "wizard", 1, 0, LOG_WIZARD},
        {NULL, 0, 0, 0}
}

Definition at line 32 of file log.c.


Generated on Mon May 28 04:25:45 2007 for BattletechMUX by  doxygen 1.4.7