src/logfile.h File Reference

Go to the source code of this file.

Data Structures

struct  logfile_t
struct  logging_t

Enumerations

enum  logstate_t { LOG_STATE_ENABLED = 0, LOG_STATE_DISABLED }

Functions

void logfile_init (void)
void logfile_shutdown (void)
char * logfile_add (char *, char *, char *)
int logfile_del (char *)
void flushlogs ()


Enumeration Type Documentation

enum logstate_t

Enumerator:
LOG_STATE_ENABLED 
LOG_STATE_DISABLED 

Definition at line 25 of file logfile.h.

00026 {
00027   LOG_STATE_ENABLED = 0,
00028   LOG_STATE_DISABLED
00029 } logstate_t;


Function Documentation

void flushlogs (  ) 

Definition at line 335 of file logfile.c.

References flushlog(), nlogfiles, and timer_get_timestamp().

Referenced by fatal(), logfile_5minutely(), logfile_cycle(), logfile_minutely(), and logfile_shutdown().

00336 {
00337   char *ts;
00338   int i;
00339 
00340   ts = timer_get_timestamp();
00341   for (i = 0; i < nlogfiles; i++) {
00342     flushlog(&logfiles[i], ts);
00343   }
00344 }

char* logfile_add ( char *  ,
char *  ,
char *   
)

Definition at line 158 of file logfile.c.

References logfile_t::chname, logfile_t::filename, logfile_t::fp, logfile_t::last_msg, LOG_ALL, logfile_del(), logfile_t::mask, and nlogfiles.

Referenced by logfile_init().

00159 {
00160   FILE *fp;
00161   logfile_t *log;
00162 
00163   /* Get rid of any duplicates. */
00164   logfile_del(fname);
00165 
00166   /* Test the filename. */
00167   fp = fopen(fname, "a");
00168   if (!fp) return("");
00169   
00170   logfiles = realloc(logfiles, (nlogfiles + 1) * sizeof(*logfiles));
00171       
00172   log = &logfiles[nlogfiles++];
00173   memset(log, 0, sizeof(*log));
00174   log->filename = strdup(fname);
00175   log->chname = strdup(chan);
00176   log->last_msg = strdup("");
00177   log->mask = LOG_ALL;
00178   log->fp = fp;
00179 
00180   return (log->filename);
00181 }

int logfile_del ( char *   ) 

Definition at line 183 of file logfile.c.

References logfile_t::filename, flushlog(), logfile_t::fp, logfile_t::last_msg, nlogfiles, NULL, and timer_get_timestamp().

Referenced by logfile_add(), and logfile_cycle().

00184 {
00185   logfile_t *log;
00186   int i;
00187 
00188   log = NULL;
00189   for (i = 0; i < nlogfiles; i++) {
00190     log = &logfiles[i];
00191     if (!strcmp(log->filename, filename)) break;
00192     log = NULL;
00193   }
00194 
00195   if (log == NULL) return(-1);
00196     
00197   if (log->fp) {
00198     flushlog(log, timer_get_timestamp());
00199     fclose(log->fp);
00200   }
00201 
00202   if (log->last_msg) free(log->last_msg);
00203   if (log->filename) free(log->filename);
00204 
00205   if (nlogfiles == 1) {
00206     free(logfiles);
00207     logfiles = NULL;
00208   } else {    
00209     memmove(logfiles + i, logfiles + i + 1, (nlogfiles - i - 1) * sizeof(logfile_t));
00210     logfiles = realloc(logfiles, (nlogfiles - 1) * sizeof(logfile_t));
00211   }
00212 
00213   nlogfiles--;
00214 
00215   return(0);
00216 }

void logfile_init ( void   ) 

Definition at line 54 of file logfile.c.

References bind_add_simple(), config_get_root(), config_get_str(), config_lookup_section(), logfile_5minutely(), logfile_add(), logfile_minutely(), NULL, on_putlog(), and script_create_commands().

Referenced by core_init().

00055 {
00056   void *root, *node;
00057   char *filename, *chname, *mask;
00058   int i;
00059 
00060   script_create_commands(log_script_cmds);
00061   bind_add_simple("log", NULL, NULL, on_putlog);
00062   bind_add_simple("event", NULL, "minutely", logfile_minutely);
00063   bind_add_simple("event", NULL, "5minutely", logfile_5minutely);
00064 
00065   root = config_get_root("eggdrop");
00066   node = config_lookup_section(root, "eggdrop.logging.logfiles", 0, NULL);
00067   for (i = 0; ; i++) {
00068     config_get_str(&filename, node, "logfile", i, "filename", 0, NULL);
00069     config_get_str(&chname, node, "logfile", i, "channel", 0, NULL);
00070     config_get_str(&mask, node, "logfile", i, "mask", 0, NULL);
00071     if (!filename || !chname || !mask) break;
00072     logfile_add(mask, chname, filename);
00073   }
00074 }

void logfile_shutdown ( void   ) 

Definition at line 76 of file logfile.c.

References bind_rem_simple(), config_get_root(), config_lookup_section(), config_set_str(), flushlogs(), logfile_5minutely(), logfile_minutely(), nlogfiles, NULL, on_putlog(), and script_delete_commands().

Referenced by core_shutdown_or_restart().

00077 {
00078   void *root, *node;
00079   int i;
00080 
00081   flushlogs();
00082   
00083   root = config_get_root("eggdrop");
00084   node = config_lookup_section(root, "eggdrop.logging.logfiles", 0, NULL);
00085   for (i = 0; i < nlogfiles; i++) {
00086     config_set_str(logfiles[i].filename, node, "logfile", i, "filename", 0, NULL);
00087     config_set_str(logfiles[i].chname, node, "logfile", i, "channel", 0, NULL);
00088     config_set_str("*", node, "logfile", i, "mask", 0, NULL);
00089   }
00090 
00091   bind_rem_simple("log", NULL, NULL, on_putlog);
00092   bind_rem_simple("event", NULL, "minutely", logfile_minutely);
00093   bind_rem_simple("event", NULL, "5minutely", logfile_5minutely);
00094   script_delete_commands(log_script_cmds);
00095 }


Generated on Sun Nov 30 18:43:37 2008 for eggdrop1.9 by  doxygen 1.5.6