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 #undef KEEP_LOGFILES_OPEN
57 #undef DEBUG_OUTPUT_TO_SCREEN
58 #undef CHECK_STAT_ON_NEW_FILES
59 #undef CHECK_ACCESS_ON_NEW_FILES
61 /* =========================================================================
62 External function declarations
63 ========================================================================= */
65 /* setup the internal variables used by the logger (called automatically) */
68 /* Setup the log filename and the loglevel, and the type of log it is. */
69 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype,
72 /* Setup the Level and type of log that will be logged to syslog. */
73 void syslog_setup(enum loglevels loglevel, enum logtypes logtype,
74 int display_options, int facility);
76 /* finish up and close the logs */
79 /* This function sets up the processname */
80 void set_processname(char *processname);
83 void make_log(enum loglevels loglevel, enum logtypes logtype,
85 #ifndef DISABLE_LOGGER
86 make_log_func set_log_location(char *srcfilename, int srclinenumber);
88 /* =========================================================================
90 ========================================================================= */
92 /* A structure containing object level stuff */
93 struct tag_log_file_data {
94 char log_filename[PATH_MAX]; /* Name of file */
95 FILE *log_file; /* FILE pointer to file */
96 enum loglevels log_level; /* Log Level to put in this file */
100 typedef struct tag_log_file_data log_file_data_pair[2];
102 /* A structure containg class level stuff */
103 struct tag_global_log_data {
106 char *temp_src_filename;
107 int temp_src_linenumber;
108 char processname[16];
111 char *log_file_directory; /* Path of directory containing log files */
112 log_file_data_pair **logs;
115 struct what_to_print_array {
117 bool print_processname;
125 /* =========================================================================
126 Internal function declarations
127 ========================================================================= */
129 void generate_message_details(char *message_details_buffer,
130 int message_details_buffer_length,
131 struct tag_log_file_data *log_struct,
132 enum loglevels loglevel, enum logtypes logtype);
134 int get_syslog_equivalent(enum loglevels loglevel);
136 static char *get_command_name(char *commandpath);
138 /* =========================================================================
140 ========================================================================= */
142 /* A populated instance */
144 static log_file_data_pair default_log_file_data_pair = {
146 log_filename: "\0\0\0\0\0\0\0\0",
148 log_level: log_debug,
149 display_options: logoption_pid
152 log_filename: LOGFILEPATH,
154 log_level: log_debug,
155 display_options: logoption_pid
158 static log_file_data_pair logger_log_file_data_pair = {
160 log_filename: "\0\0\0\0\0\0\0\0",
162 log_level: log_warning,
163 display_options: logoption_pid
166 log_filename: LOGFILEPATH,
168 log_level: log_maxdebug,
169 display_options: logoption_pid
172 static log_file_data_pair *log_file_data_array[logtype_end_of_list_marker] =
173 {&default_log_file_data_pair};
175 /* The class (populated) */
176 static struct tag_global_log_data global_log_data = {
177 struct_size: sizeof(struct tag_global_log_data),
178 temp_src_filename: NULL,
179 temp_src_linenumber: 0,
181 facility: logfacility_daemon,
182 log_file_directory: "",
186 /* macro to get access to the array */
187 #define log_file_arr (global_log_data.logs)
189 /* Array to store text to list given a log type */
190 static const char * arr_logtype_strings[] = LOGTYPE_STRING_IDENTIFIERS;
191 static const int num_logtype_strings = COUNT_ARRAY(arr_logtype_strings);
193 /* Array for charachters representing log severity in the log file */
194 static const char arr_loglevel_chars[] = {'S', 'E', 'W', 'N', 'I', 'D'};
195 static const int num_loglevel_chars = COUNT_ARRAY(arr_loglevel_chars);
197 static const char * arr_loglevel_strings[] = LOGLEVEL_STRING_IDENTIFIERS;
198 static const int num_loglevel_strings = COUNT_ARRAY(arr_loglevel_strings);
200 #else /* #ifndef DISABLE_LOGGER */
201 char *disabled_logger_processname=NULL;
202 #endif /* DISABLE_LOGGER */
203 /* =========================================================================
204 Global function definitions
205 ========================================================================= */
207 #ifndef DISABLE_LOGGER
209 /* remember I'm keeping a copy of the actual char * Filename, so you mustn't
210 delete it, until you've finished with the log. Also you're responsible
211 for deleting it when you have finished with it. */
214 if (global_log_data.logs==NULL)
216 /* first check default_log_file_data_pair */
218 /* next clear out the log_file_data_array */
219 memset(log_file_data_array, 0, sizeof(log_file_data_array));
220 /* now set default_log_file_data_pairs */
221 log_file_data_array[logtype_default] = &default_log_file_data_pair;
222 log_file_data_array[logtype_logger] = &logger_log_file_data_pair;
224 /* now setup the global_log_data struct */
225 global_log_data.logs = log_file_data_array;
227 /* make_log_entry(log_debug, logtype_logger, "log_init ran for the first time"); */
230 #endif /* #ifndef DISABLE_LOGGER */
232 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype,
235 #ifndef DISABLE_LOGGER
245 log_file_data_pair *logs;
249 logs = log_file_arr[logtype];
251 LOG(log_info, logtype_logger, "doing log_setup, type %d, level %d, filename \"%s\"", logtype, loglevel, filename);
253 /* LOG(log_extradebug+10, logtype_logger, "checking array for logtype is malloc'd"); */
254 /* has the given logtype already been assigned memory? */
257 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
260 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
265 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
267 log_file_arr[logtype] = logs;
268 (*logs)[1].log_file = NULL;
272 /* I think this checks if we're logging to stdout or not. Probably unused */
273 if ( ((*logs)[1].log_file == stdout) && ((*logs)[1].log_file != NULL) )
275 fclose((*logs)[1].log_file);
276 (*logs)[1].log_file = NULL;
279 /* check if we need to append the given filename to a directory */
280 if (strlen(global_log_data.log_file_directory)>0)
282 lastchar[0] = global_log_data.
283 log_file_directory[strlen(global_log_data.log_file_directory)-1];
285 if (lastchar[0] == '/' || lastchar[0] == '\\' || lastchar[0] == ':')
288 /* this should probably be a platform specific path separator */
296 #ifdef DEBUG_OUTPUT_TO_SCREEN
297 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
298 (*logs)[1].log_filename);
299 #endif /* DEBUG_OUTPUT_TO_SCREEN */
300 if (filename == NULL)
302 strncpy((*logs)[1].log_filename,
303 (*(log_file_arr[0]))[1].log_filename, PATH_MAX);
307 sprintf((*logs)[1].log_filename, "%s%s%s",
308 global_log_data.log_file_directory,
311 (*logs)[1].log_level = loglevel;
312 (*logs)[1].display_options = display_options;
314 #ifdef DEBUG_OUTPUT_TO_SCREEN
315 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
316 (*logs)[1].log_filename);
317 #endif /* DEBUG_OUTPUT_TO_SCREEN */
319 #ifdef CHECK_STAT_ON_NEW_FILES
323 #ifdef DEBUG_OUTPUT_TO_SCREEN
324 printf("about to stat file %s\n", (*logs)[1].log_filename);
326 firstattempt = stat((*logs)[1].log_filename, &statbuf);
328 if (firstattempt == -1)
330 #ifdef DEBUG_OUTPUT_TO_SCREEN
331 printf("about to call Log with %d, %d, %s, %s\n",
332 log_note, logtype_logger,
333 "can't stat Logfile",
334 (*logs)[1].log_filename
338 /* syslog(LOG_INFO, "stat failed"); */
339 LOG(log_warning, logtype_logger, "stat fails on file %s",
340 (*logs)[1].log_filename);
342 if (strlen(global_log_data.log_file_directory)>0)
344 retval = stat(global_log_data.log_file_directory, &statbuf);
347 #ifdef DEBUG_OUTPUT_TO_SCREEN
348 printf("can't stat dir either so I'm giving up\n");
350 LOG(log_severe, logtype_logger, "can't stat directory %s either",
351 global_log_data.log_file_directory);
357 #ifdef CHECK_ACCESS_ON_NEW_FILES
358 access = ((statbuf.st_uid == uid)?(statbuf.st_mode & S_IWUSR):0) +
359 ((statbuf.st_gid == gid)?(statbuf.st_mode & S_IWGRP):0) +
360 (statbuf.st_mode & S_IWOTH);
364 #ifdef DEBUG_OUTPUT_TO_SCREEN
365 printf("failing with %d, %d, %s, %s\n", log_note, logtype_logger,
366 "can't access Logfile %s", (*logs)[1].log_filename);
369 LOG(log_note, logtype_logger, "can't access file %s",
370 (*logs)[1].log_filename);
373 #endif /* CHECK_ACCESS_ON_NEW_FILES */
374 #endif /* CHECK_STAT_ON_NEW_FILES */
375 #ifdef KEEP_LOGFILES_OPEN
376 if ((*logs)[1].log_file!=NULL)
377 fclose((*logs)[1].log_file);
379 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
380 if ((*logs)[1].log_file == NULL)
382 LOG(log_severe, logtype_logger, "can't open Logfile %s",
383 (*logs)[1].log_filename
389 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
390 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
391 (*logs)[1].log_filename, (*logs)[1].log_file, (*logs)[1].log_level);
392 LOG(log_debug, logtype_logger, "log_setup[%d] done", logtype);
394 #endif /* DISABLE_LOGGER */
399 void syslog_setup(enum loglevels loglevel, enum logtypes logtype,
400 int display_options, int facility)
402 #ifndef DISABLE_LOGGER
403 log_file_data_pair *logs;
407 logs = log_file_arr[logtype];
409 LOG(log_info, logtype_logger, "doing syslog_setup, type %d, level %d", logtype, loglevel);
413 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
416 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
420 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
421 log_file_arr[logtype] = logs;
425 (*logs)[0].log_file = NULL;
426 (*logs)[0].log_filename[0] = 0;
427 (*logs)[0].log_level = loglevel;
428 (*logs)[0].display_options = display_options;
429 global_log_data.facility = facility;
431 openlog(global_log_data.processname, (*logs)[0].display_options,
432 global_log_data.facility);
434 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
435 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
436 (*logs)[0].log_filename, (*logs)[0].log_file, (*logs)[0].log_level);
437 LOG(log_debug, logtype_logger, "syslog_setup[%d] done", logtype);
438 #else /* DISABLE_LOGGER */
439 /* behave like a normal openlog call */
440 openlog(disabled_logger_processname, display_options, facility);
441 #endif /* DISABLE_LOGGER */
446 #ifndef DISABLE_LOGGER
447 log_file_data_pair *logs;
450 LOG(log_info, logtype_logger, "log_close called");
452 for(n=(sizeof(log_file_arr)-1);n>0;n--)
454 logs = log_file_arr[n];
455 #ifdef KEEP_LOGFILES_OPEN
456 if ((*logs)[1].log_file!=NULL)
457 fclose((*logs)[1].log_file);
458 #endif /* KEEP_LOGFILES_OPEN */
461 LOG(log_debug, logtype_logger, "freeing log entry at %d", n);
462 #ifdef DEBUG_OUTPUT_TO_SCREEN
463 printf("Freeing log_data %d, stored at %p\n", n, logs);
464 printf("\t(filename) %s\t(type) %s\n", (*logs)[1].log_filename,
465 ((n<num_logtype_strings)?arr_logtype_strings[n]:""));
466 #endif /* DEBUG_OUTPUT_TO_SCREEN */
469 log_file_arr[n] = NULL;
471 #ifdef DEBUG_OUTPUT_TO_SCREEN
472 printf("Freeing log_data %d, stored at %p\n", n, log_file_arr[n]);
473 printf("\t(filename) %s\t(type) %s\n",
474 (*(log_file_arr[n]))[1].log_filename,
475 ((n<num_logtype_strings)?arr_logtype_strings[n]:"")
477 #endif /* DEBUG_OUTPUT_TO_SCREEN */
478 #endif /* DISABLE_LOGGER */
480 LOG(log_debug, logtype_logger, "log_close done");
485 /* This function sets up the processname */
486 void set_processname(char *processname)
488 #ifndef DISABLE_LOGGER
489 /* strncpy(global_log_data.processname, GetCommandName(processname), 15); */
490 strncpy(global_log_data.processname, processname, 15);
491 global_log_data.processname[15] = 0;
492 #else /* DISABLE_LOGGER */
493 disabled_logger_processname = processname;
494 #endif /* DISABLE_LOGGER */
497 #ifndef DISABLE_LOGGER
498 /* This is called by the macro so set the location of the caller of Log */
499 make_log_func set_log_location(char *srcfilename, int srclinenumber)
501 #ifdef DEBUG_OUTPUT_TO_SCREEN
502 printf("Setting Log Location\n");
504 global_log_data.temp_src_filename = srcfilename;
505 global_log_data.temp_src_linenumber = srclinenumber;
507 return make_log_entry;
509 #endif /* DISABLE_LOGGER */
511 /* -------------------------------------------------------------------------
512 MakeLog has 1 main flaws:
513 The message in its entirity, must fit into the tempbuffer.
514 So it must be shorter than MAXLOGSIZE
515 ------------------------------------------------------------------------- */
516 void make_log_entry(enum loglevels loglevel, enum logtypes logtype,
520 char log_buffer[MAXLOGSIZE];
521 #ifndef DISABLE_LOGGER
522 char log_details_buffer[MAXLOGSIZE];
524 log_file_data_pair *logs;
528 logs = log_file_arr[logtype];
532 logs = log_file_arr[logtype_default];
534 #ifdef DEBUG_OUTPUT_TO_SCREEN
535 printf("Making Log\n");
538 #endif /* DISABLE_LOGGER */
540 /* Initialise the Messages */
541 va_start(args, message);
543 vsnprintf(log_buffer, sizeof(log_buffer), message, args);
545 /* Finished with args for now */
548 #ifdef DISABLE_LOGGER
549 syslog(get_syslog_equivalent(loglevel), "%s", log_buffer);
550 #else /* DISABLE_LOGGER */
553 /* check if sysloglevel is high enough */
554 if ((*logs)[0].log_level>=loglevel)
556 int sysloglevel = get_syslog_equivalent(loglevel);
558 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
559 &(*logs)[0], loglevel, logtype);
561 #ifdef DEBUG_OUTPUT_TO_SCREEN
562 printf("About to log %s %s\n", log_details_buffer, log_buffer);
563 printf("about to do syslog\n");
564 printf("done onw syslog\n");
566 syslog(sysloglevel, "%s: %s", log_details_buffer, log_buffer);
568 syslog(sysloglevel, "%s:%s: %s", log_levelString,
569 log_typeString, LogBuffer);
575 #ifdef DEBUG_OUTPUT_TO_SCREEN
576 printf("about to do the filelog\n");
578 /* check if log_level is high enough */
579 if ((*logs)[1].log_level>=loglevel) {
581 #ifdef DEBUG_OUTPUT_TO_SCREEN
582 printf("Open the Log, FILE* is %p\n", (*logs)[1].log_file);
584 /* if log isn't open, open it */
585 if ((*logs)[1].log_file==NULL) {
586 #ifdef DEBUG_OUTPUT_TO_SCREEN
587 printf("Opening the Log, filename is %s\n", (*logs)[1].log_filename);
589 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
590 if ((*logs)[1].log_file == NULL)
592 (*logs)[1].log_file = stdout;
593 LOG(log_severe, logtype_logger, "can't open Logfile %s",
594 (*logs)[1].log_filename
599 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
600 &(*logs)[1], loglevel, logtype);
602 #ifdef DEBUG_OUTPUT_TO_SCREEN
603 printf("Files open, lets log\n");
604 printf("FILE* is %p\n", (*logs)[1].log_file);
605 printf("%s: %s\n", log_details_buffer, log_buffer);
608 fprintf((*logs)[1].log_file, "%s: %s\n", log_details_buffer, log_buffer);
610 #ifndef KEEP_LOGFILES_OPEN
611 if ((*logs)[1].log_file != stdout)
613 #ifdef DEBUG_OUTPUT_TO_SCREEN
614 printf("Closing %s\n", (*logs)[1].log_filename);
616 fclose((*logs)[1].log_file);
617 (*logs)[1].log_file = NULL;
618 #ifdef DEBUG_OUTPUT_TO_SCREEN
626 global_log_data.temp_src_filename = NULL;
627 global_log_data.temp_src_linenumber = 0;
628 #endif /* DISABLE_LOGGER */
631 #ifndef DISABLE_LOGGER
632 void load_proccessname_from_proc()
634 pid_t pid = getpid();
635 char buffer[PATH_MAX];
640 sprintf(buffer, "/proc/%d/stat", pid);
641 statfile = fopen(buffer, "rt");
642 fgets(buffer, PATH_MAX-1, statfile);
645 ptr = (char *)strrchr(buffer, ')');
647 memset(procname, 0, sizeof procname);
648 sscanf(buffer, "%d (%15c", &pid, procname); /* comm[16] in kernel */
650 set_processname(procname);
653 /* =========================================================================
654 Internal function definitions
655 ========================================================================= */
657 static char *get_command_name(char *commandpath)
660 #ifdef DEBUG_OUTPUT_TO_SCREEN
661 printf("getting command name %s\n",commandpath);
663 ptr = (char *)strrchr(commandpath, '/');
669 #ifdef DEBUG_OUTPUT_TO_SCREEN
670 printf("Concluded %s\n", ptr);
675 void workout_what_to_print(struct what_to_print_array *what_to_print,
676 struct tag_log_file_data *log_struct)
678 /* is this a syslog entry? */
679 if (log_struct->log_filename[0]==0)
681 what_to_print->print_datetime = false;
682 what_to_print->print_processname = false;
683 what_to_print->print_pid = false;
687 what_to_print->print_datetime = true;
688 what_to_print->print_processname = true;
690 /* pid is dealt with at the syslog level if we're syslogging */
691 what_to_print->print_pid =
692 (((log_struct->display_options & logoption_pid) == 0)?false:true);
695 what_to_print->print_srcfile =
696 (((log_struct->display_options & logoption_nfile) == 0)?true:false);
697 what_to_print->print_srcline =
698 (((log_struct->display_options & logoption_nline) == 0)?true:false);
700 what_to_print->print_errlevel = true;
701 what_to_print->print_errtype = true;
704 void generate_message_details(char *message_details_buffer,
705 int message_details_buffer_length,
706 struct tag_log_file_data *log_struct,
707 enum loglevels loglevel, enum logtypes logtype)
710 char processinfo[64];
712 char *ptr = message_details_buffer;
714 int len = message_details_buffer_length;
716 char log_buffer[MAXLOGSIZE];
717 const char *logtype_string;
719 char loglevel_string[12]; /* max int size is 2 billion, or 10 digits */
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 const char *null = "";
919 int sourcenum, typenum, levelnum;
920 log_file_data_pair *logs = log_file_arr[logtype_default];
923 LOG(log_extradebug, logtype_logger, "Attempting setuplog: %s %s %s %s",
924 logsource, logtype, loglevel, filename);
926 LOG(log_info, logtype_logger, "setuplog is parsing logtype:%s, loglevel:%s, filename:%s",
927 logtype, loglevel, filename);
931 LOG(log_note, logtype_logger, "no logsource given, default is assumed");
936 for(typenum=0;typenum<num_logtype_strings;typenum++)
938 if (strcasecmp(logtype, arr_logtype_strings[typenum])==0)
941 if (typenum>=num_logtype_strings)
943 LOG(log_warning, logtype_logger, "%s is not a valid log type", logtype);
949 LOG(log_note, logtype_logger, "no loglevel given, severe is assumed");
954 for(levelnum=0;levelnum<num_loglevel_strings;levelnum++)
956 if (strcasecmp(loglevel, arr_loglevel_strings[levelnum])==0)
959 if (levelnum>=num_loglevel_strings)
961 LOG(log_warning, logtype_logger, "%s is not a valid log level", loglevel);
966 if ((typenum>=num_logtype_strings) || (levelnum>=num_loglevel_strings))
968 LOG(log_warning, logtype_logger, "sanity check failed: (%s:%d), (%s:%d)",
969 logtype, typenum, loglevel, levelnum);
973 /* now match the order of the text string with the actual enum value (10 times) */
976 /* is this a syslog setup or a filelog setup */
977 if (filename==NULL) /* must be syslog */
979 LOG(log_debug6, logtype_logger, "calling syslog_setup(%d, %d, ...)", levelnum, typenum);
980 syslog_setup(levelnum, typenum,
981 (*logs)[0].display_options,
982 global_log_data.facility);
984 else /* this must be a filelog */
986 LOG(log_debug6, logtype_logger, "calling log_setup(%s, %d, %d, ...)", filename, levelnum, typenum);
987 log_setup(filename, levelnum, typenum,
988 (*logs)[0].display_options);
991 #endif /* DISABLE_LOGGER */