5 /* =========================================================================
7 logger.c is part of the utils section in the libatalk library,
8 which is part of the netatalk project.
10 logger.c was written by Simon Bazley (sibaz@sibaz.com)
12 I believe libatalk is released under the L/GPL licence.
14 Just incase, it is, thats the licence I'm applying to this file.
18 ==========================================================================
20 Logger.c is intended as an alternative to syslog for logging
22 ---------------------------------------------------------------
24 The initial plan is to create a structure for general information needed
27 Initally I'll hard code the neccesary stuff to start a log, this should
28 probably be moved elsewhere when some code is written to read the log
29 file locations from the config files.
31 As a more longterm idea, I'll code this so that the data struct can be
32 duplicated to allow multiple concurrent log files, although this is
33 probably a recipe for wasted resources.
35 ========================================================================= */
43 #include <sys/types.h>
48 #include <atalk/boolean.h>
49 #include <atalk/logger.h>
51 #define COUNT_ARRAY(array) (sizeof((array))/sizeof((array)[0]))
52 #define NUMOF COUNT_ARRAY
53 #define KEEP_LOGFILES_OPEN
57 #undef DEBUG_OUTPUT_TO_SCREEN
58 #undef CHECK_STAT_ON_NEW_FILES
59 #undef CHECK_ACCESS_ON_NEW_FILES
60 #define OPEN_LOGS_AS_UID 0
62 /* =========================================================================
63 External function declarations
64 ========================================================================= */
66 /* setup the internal variables used by the logger (called automatically) */
69 /* Setup the log filename and the loglevel, and the type of log it is. */
70 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype,
73 /* Setup the Level and type of log that will be logged to syslog. */
74 void syslog_setup(enum loglevels loglevel, enum logtypes logtype,
75 int display_options, int facility);
77 /* finish up and close the logs */
80 /* This function sets up the processname */
81 void set_processname(char *processname);
84 void make_log(enum loglevels loglevel, enum logtypes logtype,
86 #ifndef DISABLE_LOGGER
87 make_log_func set_log_location(char *srcfilename, int srclinenumber);
89 /* =========================================================================
91 ========================================================================= */
93 /* A structure containing object level stuff */
94 struct tag_log_file_data {
95 char log_filename[PATH_MAX]; /* Name of file */
96 FILE *log_file; /* FILE pointer to file */
97 enum loglevels log_level; /* Log Level to put in this file */
101 typedef struct tag_log_file_data log_file_data_pair[2];
103 /* A structure containg class level stuff */
104 struct tag_global_log_data {
107 char *temp_src_filename;
108 int temp_src_linenumber;
109 char processname[16];
112 char *log_file_directory; /* Path of directory containing log files */
113 log_file_data_pair **logs;
116 struct what_to_print_array {
118 bool print_processname;
126 /* =========================================================================
127 Internal function declarations
128 ========================================================================= */
130 void generate_message_details(char *message_details_buffer,
131 int message_details_buffer_length,
132 struct tag_log_file_data *log_struct,
133 enum loglevels loglevel, enum logtypes logtype);
135 int get_syslog_equivalent(enum loglevels loglevel);
137 /* =========================================================================
139 ========================================================================= */
141 /* A populated instance */
143 static log_file_data_pair default_log_file_data_pair = {
145 /*log_filename:*/ "\0\0\0\0\0\0\0\0",
147 /*log_level:*/ log_debug,
148 /*display_options:*/ logoption_pid
151 /*log_filename:*/ LOGFILEPATH,
153 /*log_level:*/ log_debug,
154 /*display_options:*/ logoption_pid
157 static log_file_data_pair logger_log_file_data_pair = {
159 /*log_filename:*/ "\0\0\0\0\0\0\0\0",
161 /*log_level:*/ log_warning,
162 /*display_options:*/ logoption_pid
165 /*log_filename:*/ LOGFILEPATH,
167 /*log_level:*/ log_maxdebug,
168 /*display_options:*/ logoption_pid
171 static log_file_data_pair *log_file_data_array[logtype_end_of_list_marker] =
172 {&default_log_file_data_pair};
174 /* The class (populated) */
175 static struct tag_global_log_data global_log_data = {
176 /*struct_size:*/ sizeof(struct tag_global_log_data),
177 /*temp_src_filename:*/ NULL,
178 /*temp_src_linenumber:*/ 0,
180 /*facility:*/ logfacility_daemon,
181 /*log_file_directory:*/ "",
185 /* macro to get access to the array */
186 #define log_file_arr (global_log_data.logs)
188 /* Array to store text to list given a log type */
189 static const char * arr_logtype_strings[] = LOGTYPE_STRING_IDENTIFIERS;
190 static const int num_logtype_strings = COUNT_ARRAY(arr_logtype_strings);
192 /* Array for charachters representing log severity in the log file */
193 static const char arr_loglevel_chars[] = {'S', 'E', 'W', 'N', 'I', 'D'};
194 static const int num_loglevel_chars = COUNT_ARRAY(arr_loglevel_chars);
196 static const char * arr_loglevel_strings[] = LOGLEVEL_STRING_IDENTIFIERS;
197 static const int num_loglevel_strings = COUNT_ARRAY(arr_loglevel_strings);
199 #else /* #ifndef DISABLE_LOGGER */
200 char *disabled_logger_processname=NULL;
201 #endif /* DISABLE_LOGGER */
202 /* =========================================================================
203 Global function definitions
204 ========================================================================= */
206 #ifndef DISABLE_LOGGER
208 /* remember I'm keeping a copy of the actual char * Filename, so you mustn't
209 delete it, until you've finished with the log. Also you're responsible
210 for deleting it when you have finished with it. */
213 if (global_log_data.logs==NULL)
215 /* first check default_log_file_data_pair */
217 /* next clear out the log_file_data_array */
218 memset(log_file_data_array, 0, sizeof(log_file_data_array));
219 /* now set default_log_file_data_pairs */
220 log_file_data_array[logtype_default] = &default_log_file_data_pair;
221 log_file_data_array[logtype_logger] = &logger_log_file_data_pair;
223 /* now setup the global_log_data struct */
224 global_log_data.logs = log_file_data_array;
226 /* make_log_entry(log_debug, logtype_logger, "log_init ran for the first time"); */
229 #endif /* #ifndef DISABLE_LOGGER */
231 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype,
234 #ifndef DISABLE_LOGGER
238 log_file_data_pair *logs;
242 logs = log_file_arr[logtype];
244 LOG(log_info, logtype_logger, "doing log_setup, type %d, level %d, filename \"%s\"", logtype, loglevel, filename);
246 /* LOG(log_extradebug+10, logtype_logger, "checking array for logtype is malloc'd"); */
247 /* has the given logtype already been assigned memory? */
250 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
253 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
258 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
260 log_file_arr[logtype] = logs;
261 (*logs)[1].log_file = NULL;
265 /* I think this checks if we're logging to stdout or not. Probably unused */
266 if ( ((*logs)[1].log_file == stdout) && ((*logs)[1].log_file != NULL) )
268 fclose((*logs)[1].log_file);
269 (*logs)[1].log_file = NULL;
272 /* check if we need to append the given filename to a directory */
273 if (strlen(global_log_data.log_file_directory)>0)
275 lastchar[0] = global_log_data.
276 log_file_directory[strlen(global_log_data.log_file_directory)-1];
278 if (lastchar[0] == '/' || lastchar[0] == '\\' || lastchar[0] == ':')
281 /* this should probably be a platform specific path separator */
289 #ifdef DEBUG_OUTPUT_TO_SCREEN
290 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
291 (*logs)[1].log_filename);
292 #endif /* DEBUG_OUTPUT_TO_SCREEN */
293 if (filename == NULL)
295 strncpy((*logs)[1].log_filename,
296 (*(log_file_arr[0]))[1].log_filename, PATH_MAX);
300 sprintf((*logs)[1].log_filename, "%s%s%s",
301 global_log_data.log_file_directory,
304 (*logs)[1].log_level = loglevel;
305 (*logs)[1].display_options = display_options;
307 #ifdef DEBUG_OUTPUT_TO_SCREEN
308 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
309 (*logs)[1].log_filename);
310 #endif /* DEBUG_OUTPUT_TO_SCREEN */
312 #ifdef CHECK_STAT_ON_NEW_FILES
316 #ifdef DEBUG_OUTPUT_TO_SCREEN
317 printf("about to stat file %s\n", (*logs)[1].log_filename);
319 firstattempt = stat((*logs)[1].log_filename, &statbuf);
321 if (firstattempt == -1)
323 #ifdef DEBUG_OUTPUT_TO_SCREEN
324 printf("about to call Log with %d, %d, %s, %s\n",
325 log_note, logtype_logger,
326 "can't stat Logfile",
327 (*logs)[1].log_filename
331 /* syslog(LOG_INFO, "stat failed"); */
332 LOG(log_warning, logtype_logger, "stat fails on file %s",
333 (*logs)[1].log_filename);
335 if (strlen(global_log_data.log_file_directory)>0)
337 retval = stat(global_log_data.log_file_directory, &statbuf);
340 #ifdef DEBUG_OUTPUT_TO_SCREEN
341 printf("can't stat dir either so I'm giving up\n");
343 LOG(log_severe, logtype_logger, "can't stat directory %s either",
344 global_log_data.log_file_directory);
350 #ifdef CHECK_ACCESS_ON_NEW_FILES
351 access = ((statbuf.st_uid == uid)?(statbuf.st_mode & S_IWUSR):0) +
352 ((statbuf.st_gid == gid)?(statbuf.st_mode & S_IWGRP):0) +
353 (statbuf.st_mode & S_IWOTH);
357 #ifdef DEBUG_OUTPUT_TO_SCREEN
358 printf("failing with %d, %d, %s, %s\n", log_note, logtype_logger,
359 "can't access Logfile %s", (*logs)[1].log_filename);
362 LOG(log_note, logtype_logger, "can't access file %s",
363 (*logs)[1].log_filename);
366 #endif /* CHECK_ACCESS_ON_NEW_FILES */
367 #endif /* CHECK_STAT_ON_NEW_FILES */
369 #ifdef KEEP_LOGFILES_OPEN
370 if ((*logs)[1].log_file!=NULL)
371 fclose((*logs)[1].log_file);
373 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
374 if ((*logs)[1].log_file == NULL)
376 LOG(log_severe, logtype_logger, "can't open Logfile %s",
377 (*logs)[1].log_filename
384 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
385 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
386 (*logs)[1].log_filename, (*logs)[1].log_file, (*logs)[1].log_level);
387 LOG(log_debug, logtype_logger, "log_setup[%d] done", logtype);
389 #endif /* DISABLE_LOGGER */
394 void syslog_setup(enum loglevels loglevel, enum logtypes logtype,
395 int display_options, int facility)
397 #ifndef DISABLE_LOGGER
398 log_file_data_pair *logs;
402 logs = log_file_arr[logtype];
404 LOG(log_info, logtype_logger, "doing syslog_setup, type %d, level %d", logtype, loglevel);
408 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
411 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
415 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
416 log_file_arr[logtype] = logs;
420 (*logs)[0].log_file = NULL;
421 (*logs)[0].log_filename[0] = 0;
422 (*logs)[0].log_level = loglevel;
423 (*logs)[0].display_options = display_options;
424 global_log_data.facility = facility;
426 openlog(global_log_data.processname, (*logs)[0].display_options,
427 global_log_data.facility);
429 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
430 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
431 (*logs)[0].log_filename, (*logs)[0].log_file, (*logs)[0].log_level);
432 LOG(log_debug, logtype_logger, "syslog_setup[%d] done", logtype);
433 #else /* DISABLE_LOGGER */
434 /* behave like a normal openlog call */
435 openlog(disabled_logger_processname, display_options, facility);
436 #endif /* DISABLE_LOGGER */
441 #ifndef DISABLE_LOGGER
442 log_file_data_pair *logs;
445 LOG(log_info, logtype_logger, "log_close called");
447 for(n=(sizeof(log_file_arr)-1);n>0;n--)
449 logs = log_file_arr[n];
450 #ifdef KEEP_LOGFILES_OPEN
451 if ((*logs)[1].log_file!=NULL)
452 fclose((*logs)[1].log_file);
453 #endif /* KEEP_LOGFILES_OPEN */
456 LOG(log_debug, logtype_logger, "freeing log entry at %d", n);
457 #ifdef DEBUG_OUTPUT_TO_SCREEN
458 printf("Freeing log_data %d, stored at %p\n", n, logs);
459 printf("\t(filename) %s\t(type) %s\n", (*logs)[1].log_filename,
460 ((n<num_logtype_strings)?arr_logtype_strings[n]:""));
461 #endif /* DEBUG_OUTPUT_TO_SCREEN */
464 log_file_arr[n] = NULL;
466 #ifdef DEBUG_OUTPUT_TO_SCREEN
467 printf("Freeing log_data %d, stored at %p\n", n, log_file_arr[n]);
468 printf("\t(filename) %s\t(type) %s\n",
469 (*(log_file_arr[n]))[1].log_filename,
470 ((n<num_logtype_strings)?arr_logtype_strings[n]:"")
472 #endif /* DEBUG_OUTPUT_TO_SCREEN */
473 #endif /* DISABLE_LOGGER */
475 LOG(log_debug, logtype_logger, "log_close done");
480 /* This function sets up the processname */
481 void set_processname(char *processname)
483 #ifndef DISABLE_LOGGER
484 /* strncpy(global_log_data.processname, GetCommandName(processname), 15); */
485 strncpy(global_log_data.processname, processname, 15);
486 global_log_data.processname[15] = 0;
487 #else /* DISABLE_LOGGER */
488 disabled_logger_processname = processname;
489 #endif /* DISABLE_LOGGER */
492 #ifndef DISABLE_LOGGER
493 /* This is called by the macro so set the location of the caller of Log */
494 make_log_func set_log_location(char *srcfilename, int srclinenumber)
496 #ifdef DEBUG_OUTPUT_TO_SCREEN
497 printf("Setting Log Location\n");
499 global_log_data.temp_src_filename = srcfilename;
500 global_log_data.temp_src_linenumber = srclinenumber;
502 return make_log_entry;
504 #endif /* DISABLE_LOGGER */
506 /* -------------------------------------------------------------------------
507 MakeLog has 1 main flaws:
508 The message in its entirity, must fit into the tempbuffer.
509 So it must be shorter than MAXLOGSIZE
510 ------------------------------------------------------------------------- */
511 void make_log_entry(enum loglevels loglevel, enum logtypes logtype,
515 char log_buffer[MAXLOGSIZE];
516 #ifndef DISABLE_LOGGER
517 char log_details_buffer[MAXLOGSIZE];
518 #ifdef OPEN_LOGS_AS_UID
521 log_file_data_pair *logs;
525 logs = log_file_arr[logtype];
529 logs = log_file_arr[logtype_default];
531 #ifdef DEBUG_OUTPUT_TO_SCREEN
532 printf("Making Log\n");
535 #endif /* DISABLE_LOGGER */
537 /* Initialise the Messages */
538 va_start(args, message);
540 vsnprintf(log_buffer, sizeof(log_buffer), message, args);
542 /* Finished with args for now */
545 #ifdef DISABLE_LOGGER
546 syslog(get_syslog_equivalent(loglevel), "%s", log_buffer);
547 #else /* DISABLE_LOGGER */
550 /* check if sysloglevel is high enough */
551 if ((*logs)[0].log_level>=loglevel)
553 int sysloglevel = get_syslog_equivalent(loglevel);
555 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
556 &(*logs)[0], loglevel, logtype);
558 #ifdef DEBUG_OUTPUT_TO_SCREEN
559 printf("About to log %s %s\n", log_details_buffer, log_buffer);
560 printf("about to do syslog\n");
561 printf("done onw syslog\n");
563 syslog(sysloglevel, "%s: %s", log_details_buffer, log_buffer);
565 syslog(sysloglevel, "%s:%s: %s", log_levelString,
566 log_typeString, LogBuffer);
572 #ifdef DEBUG_OUTPUT_TO_SCREEN
573 printf("about to do the filelog\n");
575 /* check if log_level is high enough */
576 if ((*logs)[1].log_level>=loglevel) {
578 #ifdef DEBUG_OUTPUT_TO_SCREEN
579 printf("Open the Log, FILE* is %p\n", (*logs)[1].log_file);
581 /* if log isn't open, open it */
582 if ((*logs)[1].log_file==NULL) {
583 #ifdef DEBUG_OUTPUT_TO_SCREEN
584 printf("Opening the Log, filename is %s\n", (*logs)[1].log_filename);
586 #ifdef OPEN_LOGS_AS_UID
587 process_uid = getuid();
588 setuid(OPEN_LOGS_AS_UID);
590 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
591 #ifdef OPEN_LOGS_AS_UID
594 if ((*logs)[1].log_file == NULL)
596 (*logs)[1].log_file = stdout;
597 LOG(log_severe, logtype_logger, "can't open Logfile %s",
598 (*logs)[1].log_filename
603 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
604 &(*logs)[1], loglevel, logtype);
606 #ifdef DEBUG_OUTPUT_TO_SCREEN
607 printf("Files open, lets log\n");
608 printf("FILE* is %p\n", (*logs)[1].log_file);
609 printf("%s: %s\n", log_details_buffer, log_buffer);
612 fprintf((*logs)[1].log_file, "%s: %s\n", log_details_buffer, log_buffer);
614 #ifndef KEEP_LOGFILES_OPEN
615 if ((*logs)[1].log_file != stdout)
617 #ifdef DEBUG_OUTPUT_TO_SCREEN
618 printf("Closing %s\n", (*logs)[1].log_filename);
620 fclose((*logs)[1].log_file);
621 (*logs)[1].log_file = NULL;
622 #ifdef DEBUG_OUTPUT_TO_SCREEN
626 #else // KEEP_LOGFILES_OPEN
627 fflush((*logs)[1].log_file);
628 #endif // KEEP_LOGFILES_OPEN
632 global_log_data.temp_src_filename = NULL;
633 global_log_data.temp_src_linenumber = 0;
634 #endif /* DISABLE_LOGGER */
637 #ifndef DISABLE_LOGGER
638 void load_proccessname_from_proc()
640 pid_t pid = getpid();
641 char buffer[PATH_MAX];
646 sprintf(buffer, "/proc/%d/stat", pid);
647 statfile = fopen(buffer, "rt");
648 fgets(buffer, PATH_MAX-1, statfile);
651 ptr = (char *)strrchr(buffer, ')');
653 memset(procname, 0, sizeof procname);
654 sscanf(buffer, "%d (%15c", &pid, procname); /* comm[16] in kernel */
656 set_processname(procname);
659 /* =========================================================================
660 Internal function definitions
661 ========================================================================= */
664 static char *get_command_name(char *commandpath)
667 #ifdef DEBUG_OUTPUT_TO_SCREEN
668 printf("getting command name %s\n",commandpath);
670 ptr = (char *)strrchr(commandpath, '/');
676 #ifdef DEBUG_OUTPUT_TO_SCREEN
677 printf("Concluded %s\n", ptr);
683 void workout_what_to_print(struct what_to_print_array *what_to_print,
684 struct tag_log_file_data *log_struct)
686 /* is this a syslog entry? */
687 if (log_struct->log_filename[0]==0)
689 what_to_print->print_datetime = false;
690 what_to_print->print_processname = false;
691 what_to_print->print_pid = false;
695 what_to_print->print_datetime = true;
696 what_to_print->print_processname = true;
698 /* pid is dealt with at the syslog level if we're syslogging */
699 what_to_print->print_pid =
700 (((log_struct->display_options & logoption_pid) == 0)?false:true);
703 what_to_print->print_srcfile =
704 (((log_struct->display_options & logoption_nfile) == 0)?true:false);
705 what_to_print->print_srcline =
706 (((log_struct->display_options & logoption_nline) == 0)?true:false);
708 what_to_print->print_errlevel = true;
709 what_to_print->print_errtype = true;
712 void generate_message_details(char *message_details_buffer,
713 int message_details_buffer_length,
714 struct tag_log_file_data *log_struct,
715 enum loglevels loglevel, enum logtypes logtype)
717 char *ptr = message_details_buffer;
719 int len = message_details_buffer_length;
721 struct what_to_print_array what_to_print;
723 workout_what_to_print(&what_to_print, log_struct);
725 #ifdef DEBUG_OUTPUT_TO_SCREEN
726 printf("Making MessageDetails\n");
735 if (what_to_print.print_datetime)
740 /* some people might prefer localtime() to gmtime() */
741 strftime(ptr, len, "%b %d %H:%M:%S", localtime(&thetime));
742 #ifdef DEBUG_OUTPUT_TO_SCREEN
743 printf("date is %s\n", ptr);
746 templen = strlen(ptr);
748 if (what_to_print.print_processname || what_to_print.print_pid)
749 strncat(ptr, " ", len);
751 strncat(ptr, ":", len);
763 if (what_to_print.print_processname)
765 strncpy(ptr, global_log_data.processname, len);
767 templen = strlen(ptr);
772 if (what_to_print.print_pid)
774 pid_t pid = getpid();
776 sprintf(ptr, "[%d]", pid);
778 templen = strlen(ptr);
783 if (what_to_print.print_srcfile || what_to_print.print_srcline)
785 char sprintf_buffer[8];
788 sprintf_buffer[0] = '[';
789 if (what_to_print.print_srcfile)
791 strcpy(&sprintf_buffer[1], "%s");
792 buff_ptr = &sprintf_buffer[3];
794 if (what_to_print.print_srcfile && what_to_print.print_srcline)
796 strcpy(&sprintf_buffer[3], ":");
797 buff_ptr = &sprintf_buffer[4];
799 if (what_to_print.print_srcline)
801 strcpy(buff_ptr, "%d");
802 buff_ptr = &buff_ptr[2];
804 strcpy(buff_ptr, "]");
807 ok sprintf string is ready, now is the 1st parameter src or linenumber
809 if (what_to_print.print_srcfile)
811 sprintf(ptr, sprintf_buffer,
812 global_log_data.temp_src_filename,
813 global_log_data.temp_src_linenumber);
817 sprintf(ptr, sprintf_buffer, global_log_data.temp_src_linenumber);
820 #ifdef DEBUG_OUTPUT_TO_SCREEN
821 printf("Process info is %s\n", ptr);
824 templen = strlen(ptr);
830 if (what_to_print.print_processname || what_to_print.print_pid ||
831 what_to_print.print_srcfile || what_to_print.print_srcline)
833 strncat(ptr, ": ", len);
839 loglevel_string[0] = 0;
840 ptr = loglevel_string;
843 if (what_to_print.print_errlevel)
845 if ((loglevel/10) >= (num_loglevel_chars-1))
847 sprintf(ptr, "%c%d", arr_loglevel_chars[num_loglevel_chars-1],
852 sprintf(ptr, "%c", arr_loglevel_chars[loglevel/10]);
855 templen = strlen(ptr);
860 if (what_to_print.print_errtype)
862 const char *logtype_string;
864 /* get string represnetation of the Log Type */
865 if (logtype<num_logtype_strings)
866 logtype_string = arr_logtype_strings[logtype];
870 if (what_to_print.print_errlevel)
872 strncat(ptr, ":", len);
876 sprintf(ptr, "%s", logtype_string);
879 message_details_buffer[message_details_buffer_length-1] = 0;
881 #ifdef DEBUG_OUTPUT_TO_SCREEN
882 printf("Message Details are %s\n", message_details_buffer);
885 #endif /* DISABLE_LOGGER */
887 int get_syslog_equivalent(enum loglevels loglevel)
891 /* The question is we know how bad it is for us,
892 but how should that translate in the syslogs? */
897 case 2: /* warning */
901 case 4: /* information */
908 /* void setuplog(char *logsource, char *logtype, char *loglevel, char *filename) */
909 void setuplog(char *logtype, char *loglevel, char *filename)
911 #ifndef DISABLE_LOGGER
912 /* -[un]setuplog <logtype> <loglevel> [<filename>]*/
914 This should be rewritten so that somehow logsource is assumed and everything
915 can be taken from default if needs be.
917 /* const char* sources[] = {"syslog", "filelog"}; */
918 int typenum, levelnum;
919 log_file_data_pair *logs = log_file_arr[logtype_default];
922 LOG(log_extradebug, logtype_logger, "Attempting setuplog: %s %s %s %s",
923 logsource, logtype, loglevel, filename);
925 LOG(log_info, logtype_logger, "setuplog is parsing logtype:%s, loglevel:%s, filename:%s",
926 logtype, loglevel, filename);
930 LOG(log_note, logtype_logger, "no logsource given, default is assumed");
935 for(typenum=0;typenum<num_logtype_strings;typenum++)
937 if (strcasecmp(logtype, arr_logtype_strings[typenum])==0)
940 if (typenum>=num_logtype_strings)
942 LOG(log_warning, logtype_logger, "%s is not a valid log type", logtype);
948 LOG(log_note, logtype_logger, "no loglevel given, severe is assumed");
953 for(levelnum=0;levelnum<num_loglevel_strings;levelnum++)
955 if (strcasecmp(loglevel, arr_loglevel_strings[levelnum])==0)
958 if (levelnum>=num_loglevel_strings)
960 LOG(log_warning, logtype_logger, "%s is not a valid log level", loglevel);
965 if ((typenum>=num_logtype_strings) || (levelnum>=num_loglevel_strings))
967 LOG(log_warning, logtype_logger, "sanity check failed: (%s:%d), (%s:%d)",
968 logtype, typenum, loglevel, levelnum);
972 /* now match the order of the text string with the actual enum value (10 times) */
975 /* is this a syslog setup or a filelog setup */
976 if (filename==NULL) /* must be syslog */
978 LOG(log_debug6, logtype_logger, "calling syslog_setup(%d, %d, ...)", levelnum, typenum);
979 syslog_setup(levelnum, typenum,
980 (*logs)[0].display_options,
981 global_log_data.facility);
983 else /* this must be a filelog */
985 LOG(log_debug6, logtype_logger, "calling log_setup(%s, %d, %d, ...)", filename, levelnum, typenum);
986 log_setup(filename, levelnum, typenum,
987 (*logs)[0].display_options);
990 #endif /* DISABLE_LOGGER */