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 static char *get_command_name(char *commandpath);
139 /* =========================================================================
141 ========================================================================= */
143 /* A populated instance */
145 static log_file_data_pair default_log_file_data_pair = {
147 /*log_filename:*/ "\0\0\0\0\0\0\0\0",
149 /*log_level:*/ log_debug,
150 /*display_options:*/ logoption_pid
153 /*log_filename:*/ LOGFILEPATH,
155 /*log_level:*/ log_debug,
156 /*display_options:*/ logoption_pid
159 static log_file_data_pair logger_log_file_data_pair = {
161 /*log_filename:*/ "\0\0\0\0\0\0\0\0",
163 /*log_level:*/ log_warning,
164 /*display_options:*/ logoption_pid
167 /*log_filename:*/ LOGFILEPATH,
169 /*log_level:*/ log_maxdebug,
170 /*display_options:*/ logoption_pid
173 static log_file_data_pair *log_file_data_array[logtype_end_of_list_marker] =
174 {&default_log_file_data_pair};
176 /* The class (populated) */
177 static struct tag_global_log_data global_log_data = {
178 /*struct_size:*/ sizeof(struct tag_global_log_data),
179 /*temp_src_filename:*/ NULL,
180 /*temp_src_linenumber:*/ 0,
182 /*facility:*/ logfacility_daemon,
183 /*log_file_directory:*/ "",
187 /* macro to get access to the array */
188 #define log_file_arr (global_log_data.logs)
190 /* Array to store text to list given a log type */
191 static const char * arr_logtype_strings[] = LOGTYPE_STRING_IDENTIFIERS;
192 static const int num_logtype_strings = COUNT_ARRAY(arr_logtype_strings);
194 /* Array for charachters representing log severity in the log file */
195 static const char arr_loglevel_chars[] = {'S', 'E', 'W', 'N', 'I', 'D'};
196 static const int num_loglevel_chars = COUNT_ARRAY(arr_loglevel_chars);
198 static const char * arr_loglevel_strings[] = LOGLEVEL_STRING_IDENTIFIERS;
199 static const int num_loglevel_strings = COUNT_ARRAY(arr_loglevel_strings);
201 #else /* #ifndef DISABLE_LOGGER */
202 char *disabled_logger_processname=NULL;
203 #endif /* DISABLE_LOGGER */
204 /* =========================================================================
205 Global function definitions
206 ========================================================================= */
208 #ifndef DISABLE_LOGGER
210 /* remember I'm keeping a copy of the actual char * Filename, so you mustn't
211 delete it, until you've finished with the log. Also you're responsible
212 for deleting it when you have finished with it. */
215 if (global_log_data.logs==NULL)
217 /* first check default_log_file_data_pair */
219 /* next clear out the log_file_data_array */
220 memset(log_file_data_array, 0, sizeof(log_file_data_array));
221 /* now set default_log_file_data_pairs */
222 log_file_data_array[logtype_default] = &default_log_file_data_pair;
223 log_file_data_array[logtype_logger] = &logger_log_file_data_pair;
225 /* now setup the global_log_data struct */
226 global_log_data.logs = log_file_data_array;
228 /* make_log_entry(log_debug, logtype_logger, "log_init ran for the first time"); */
231 #endif /* #ifndef DISABLE_LOGGER */
233 bool log_setup(char *filename, enum loglevels loglevel, enum logtypes logtype,
236 #ifndef DISABLE_LOGGER
238 #ifdef CHECK_STAT_ON_NEW_FILES
248 log_file_data_pair *logs;
252 logs = log_file_arr[logtype];
254 LOG(log_info, logtype_logger, "doing log_setup, type %d, level %d, filename \"%s\"", logtype, loglevel, filename);
256 /* LOG(log_extradebug+10, logtype_logger, "checking array for logtype is malloc'd"); */
257 /* has the given logtype already been assigned memory? */
260 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
263 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
268 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
270 log_file_arr[logtype] = logs;
271 (*logs)[1].log_file = NULL;
275 /* I think this checks if we're logging to stdout or not. Probably unused */
276 if ( ((*logs)[1].log_file == stdout) && ((*logs)[1].log_file != NULL) )
278 fclose((*logs)[1].log_file);
279 (*logs)[1].log_file = NULL;
282 /* check if we need to append the given filename to a directory */
283 if (strlen(global_log_data.log_file_directory)>0)
285 lastchar[0] = global_log_data.
286 log_file_directory[strlen(global_log_data.log_file_directory)-1];
288 if (lastchar[0] == '/' || lastchar[0] == '\\' || lastchar[0] == ':')
291 /* this should probably be a platform specific path separator */
299 #ifdef DEBUG_OUTPUT_TO_SCREEN
300 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
301 (*logs)[1].log_filename);
302 #endif /* DEBUG_OUTPUT_TO_SCREEN */
303 if (filename == NULL)
305 strncpy((*logs)[1].log_filename,
306 (*(log_file_arr[0]))[1].log_filename, PATH_MAX);
310 sprintf((*logs)[1].log_filename, "%s%s%s",
311 global_log_data.log_file_directory,
314 (*logs)[1].log_level = loglevel;
315 (*logs)[1].display_options = display_options;
317 #ifdef DEBUG_OUTPUT_TO_SCREEN
318 printf("filename is %s stored at location %p\n", (*logs)[1].log_filename,
319 (*logs)[1].log_filename);
320 #endif /* DEBUG_OUTPUT_TO_SCREEN */
322 #ifdef CHECK_STAT_ON_NEW_FILES
326 #ifdef DEBUG_OUTPUT_TO_SCREEN
327 printf("about to stat file %s\n", (*logs)[1].log_filename);
329 firstattempt = stat((*logs)[1].log_filename, &statbuf);
331 if (firstattempt == -1)
333 #ifdef DEBUG_OUTPUT_TO_SCREEN
334 printf("about to call Log with %d, %d, %s, %s\n",
335 log_note, logtype_logger,
336 "can't stat Logfile",
337 (*logs)[1].log_filename
341 /* syslog(LOG_INFO, "stat failed"); */
342 LOG(log_warning, logtype_logger, "stat fails on file %s",
343 (*logs)[1].log_filename);
345 if (strlen(global_log_data.log_file_directory)>0)
347 retval = stat(global_log_data.log_file_directory, &statbuf);
350 #ifdef DEBUG_OUTPUT_TO_SCREEN
351 printf("can't stat dir either so I'm giving up\n");
353 LOG(log_severe, logtype_logger, "can't stat directory %s either",
354 global_log_data.log_file_directory);
360 #ifdef CHECK_ACCESS_ON_NEW_FILES
361 access = ((statbuf.st_uid == uid)?(statbuf.st_mode & S_IWUSR):0) +
362 ((statbuf.st_gid == gid)?(statbuf.st_mode & S_IWGRP):0) +
363 (statbuf.st_mode & S_IWOTH);
367 #ifdef DEBUG_OUTPUT_TO_SCREEN
368 printf("failing with %d, %d, %s, %s\n", log_note, logtype_logger,
369 "can't access Logfile %s", (*logs)[1].log_filename);
372 LOG(log_note, logtype_logger, "can't access file %s",
373 (*logs)[1].log_filename);
376 #endif /* CHECK_ACCESS_ON_NEW_FILES */
377 #endif /* CHECK_STAT_ON_NEW_FILES */
379 #ifdef KEEP_LOGFILES_OPEN
380 if ((*logs)[1].log_file!=NULL)
381 fclose((*logs)[1].log_file);
383 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
384 if ((*logs)[1].log_file == NULL)
386 LOG(log_severe, logtype_logger, "can't open Logfile %s",
387 (*logs)[1].log_filename
394 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
395 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
396 (*logs)[1].log_filename, (*logs)[1].log_file, (*logs)[1].log_level);
397 LOG(log_debug, logtype_logger, "log_setup[%d] done", logtype);
399 #endif /* DISABLE_LOGGER */
404 void syslog_setup(enum loglevels loglevel, enum logtypes logtype,
405 int display_options, int facility)
407 #ifndef DISABLE_LOGGER
408 log_file_data_pair *logs;
412 logs = log_file_arr[logtype];
414 LOG(log_info, logtype_logger, "doing syslog_setup, type %d, level %d", logtype, loglevel);
418 logs = (log_file_data_pair *)malloc(sizeof(log_file_data_pair));
421 LOG(log_severe, logtype_logger, "can't calloc in log_setup");
425 memcpy(logs, log_file_arr[logtype_default], sizeof(log_file_data_pair));
426 log_file_arr[logtype] = logs;
430 (*logs)[0].log_file = NULL;
431 (*logs)[0].log_filename[0] = 0;
432 (*logs)[0].log_level = loglevel;
433 (*logs)[0].display_options = display_options;
434 global_log_data.facility = facility;
436 openlog(global_log_data.processname, (*logs)[0].display_options,
437 global_log_data.facility);
439 LOG(log_debug7, logtype_logger, "log_file_arr[%d] now contains: "
440 "{log_filename:%s, log_file:%p, log_level: %d}", logtype,
441 (*logs)[0].log_filename, (*logs)[0].log_file, (*logs)[0].log_level);
442 LOG(log_debug, logtype_logger, "syslog_setup[%d] done", logtype);
443 #else /* DISABLE_LOGGER */
444 /* behave like a normal openlog call */
445 openlog(disabled_logger_processname, display_options, facility);
446 #endif /* DISABLE_LOGGER */
451 #ifndef DISABLE_LOGGER
452 log_file_data_pair *logs;
455 LOG(log_info, logtype_logger, "log_close called");
457 for(n=(sizeof(log_file_arr)-1);n>0;n--)
459 logs = log_file_arr[n];
460 #ifdef KEEP_LOGFILES_OPEN
461 if ((*logs)[1].log_file!=NULL)
462 fclose((*logs)[1].log_file);
463 #endif /* KEEP_LOGFILES_OPEN */
466 LOG(log_debug, logtype_logger, "freeing log entry at %d", n);
467 #ifdef DEBUG_OUTPUT_TO_SCREEN
468 printf("Freeing log_data %d, stored at %p\n", n, logs);
469 printf("\t(filename) %s\t(type) %s\n", (*logs)[1].log_filename,
470 ((n<num_logtype_strings)?arr_logtype_strings[n]:""));
471 #endif /* DEBUG_OUTPUT_TO_SCREEN */
474 log_file_arr[n] = NULL;
476 #ifdef DEBUG_OUTPUT_TO_SCREEN
477 printf("Freeing log_data %d, stored at %p\n", n, log_file_arr[n]);
478 printf("\t(filename) %s\t(type) %s\n",
479 (*(log_file_arr[n]))[1].log_filename,
480 ((n<num_logtype_strings)?arr_logtype_strings[n]:"")
482 #endif /* DEBUG_OUTPUT_TO_SCREEN */
483 #endif /* DISABLE_LOGGER */
485 LOG(log_debug, logtype_logger, "log_close done");
490 /* This function sets up the processname */
491 void set_processname(char *processname)
493 #ifndef DISABLE_LOGGER
494 /* strncpy(global_log_data.processname, GetCommandName(processname), 15); */
495 strncpy(global_log_data.processname, processname, 15);
496 global_log_data.processname[15] = 0;
497 #else /* DISABLE_LOGGER */
498 disabled_logger_processname = processname;
499 #endif /* DISABLE_LOGGER */
502 #ifndef DISABLE_LOGGER
503 /* This is called by the macro so set the location of the caller of Log */
504 make_log_func set_log_location(char *srcfilename, int srclinenumber)
506 #ifdef DEBUG_OUTPUT_TO_SCREEN
507 printf("Setting Log Location\n");
509 global_log_data.temp_src_filename = srcfilename;
510 global_log_data.temp_src_linenumber = srclinenumber;
512 return make_log_entry;
514 #endif /* DISABLE_LOGGER */
516 /* -------------------------------------------------------------------------
517 MakeLog has 1 main flaws:
518 The message in its entirity, must fit into the tempbuffer.
519 So it must be shorter than MAXLOGSIZE
520 ------------------------------------------------------------------------- */
521 void make_log_entry(enum loglevels loglevel, enum logtypes logtype,
525 char log_buffer[MAXLOGSIZE];
526 #ifndef DISABLE_LOGGER
527 char log_details_buffer[MAXLOGSIZE];
528 #ifdef OPEN_LOGS_AS_UID
531 log_file_data_pair *logs;
535 logs = log_file_arr[logtype];
539 logs = log_file_arr[logtype_default];
541 #ifdef DEBUG_OUTPUT_TO_SCREEN
542 printf("Making Log\n");
545 #endif /* DISABLE_LOGGER */
547 /* Initialise the Messages */
548 va_start(args, message);
550 vsnprintf(log_buffer, sizeof(log_buffer), message, args);
552 /* Finished with args for now */
555 #ifdef DISABLE_LOGGER
556 syslog(get_syslog_equivalent(loglevel), "%s", log_buffer);
557 #else /* DISABLE_LOGGER */
560 /* check if sysloglevel is high enough */
561 if ((*logs)[0].log_level>=loglevel)
563 int sysloglevel = get_syslog_equivalent(loglevel);
565 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
566 &(*logs)[0], loglevel, logtype);
568 #ifdef DEBUG_OUTPUT_TO_SCREEN
569 printf("About to log %s %s\n", log_details_buffer, log_buffer);
570 printf("about to do syslog\n");
571 printf("done onw syslog\n");
573 syslog(sysloglevel, "%s: %s", log_details_buffer, log_buffer);
575 syslog(sysloglevel, "%s:%s: %s", log_levelString,
576 log_typeString, LogBuffer);
582 #ifdef DEBUG_OUTPUT_TO_SCREEN
583 printf("about to do the filelog\n");
585 /* check if log_level is high enough */
586 if ((*logs)[1].log_level>=loglevel) {
588 #ifdef DEBUG_OUTPUT_TO_SCREEN
589 printf("Open the Log, FILE* is %p\n", (*logs)[1].log_file);
591 /* if log isn't open, open it */
592 if ((*logs)[1].log_file==NULL) {
593 #ifdef DEBUG_OUTPUT_TO_SCREEN
594 printf("Opening the Log, filename is %s\n", (*logs)[1].log_filename);
596 #ifdef OPEN_LOGS_AS_UID
597 process_uid = getuid();
598 setuid(OPEN_LOGS_AS_UID);
600 (*logs)[1].log_file = fopen((*logs)[1].log_filename, "at");
601 #ifdef OPEN_LOGS_AS_UID
604 if ((*logs)[1].log_file == NULL)
606 (*logs)[1].log_file = stdout;
607 LOG(log_severe, logtype_logger, "can't open Logfile %s",
608 (*logs)[1].log_filename
613 generate_message_details(log_details_buffer, sizeof(log_details_buffer),
614 &(*logs)[1], loglevel, logtype);
616 #ifdef DEBUG_OUTPUT_TO_SCREEN
617 printf("Files open, lets log\n");
618 printf("FILE* is %p\n", (*logs)[1].log_file);
619 printf("%s: %s\n", log_details_buffer, log_buffer);
622 fprintf((*logs)[1].log_file, "%s: %s\n", log_details_buffer, log_buffer);
624 #ifndef KEEP_LOGFILES_OPEN
625 if ((*logs)[1].log_file != stdout)
627 #ifdef DEBUG_OUTPUT_TO_SCREEN
628 printf("Closing %s\n", (*logs)[1].log_filename);
630 fclose((*logs)[1].log_file);
631 (*logs)[1].log_file = NULL;
632 #ifdef DEBUG_OUTPUT_TO_SCREEN
636 #else // KEEP_LOGFILES_OPEN
637 fflush((*logs)[1].log_file);
638 #endif // KEEP_LOGFILES_OPEN
642 global_log_data.temp_src_filename = NULL;
643 global_log_data.temp_src_linenumber = 0;
644 #endif /* DISABLE_LOGGER */
647 #ifndef DISABLE_LOGGER
648 void load_proccessname_from_proc()
650 pid_t pid = getpid();
651 char buffer[PATH_MAX];
656 sprintf(buffer, "/proc/%d/stat", pid);
657 statfile = fopen(buffer, "rt");
658 fgets(buffer, PATH_MAX-1, statfile);
661 ptr = (char *)strrchr(buffer, ')');
663 memset(procname, 0, sizeof procname);
664 sscanf(buffer, "%d (%15c", &pid, procname); /* comm[16] in kernel */
666 set_processname(procname);
669 /* =========================================================================
670 Internal function definitions
671 ========================================================================= */
673 static char *get_command_name(char *commandpath)
676 #ifdef DEBUG_OUTPUT_TO_SCREEN
677 printf("getting command name %s\n",commandpath);
679 ptr = (char *)strrchr(commandpath, '/');
685 #ifdef DEBUG_OUTPUT_TO_SCREEN
686 printf("Concluded %s\n", ptr);
691 void workout_what_to_print(struct what_to_print_array *what_to_print,
692 struct tag_log_file_data *log_struct)
694 /* is this a syslog entry? */
695 if (log_struct->log_filename[0]==0)
697 what_to_print->print_datetime = false;
698 what_to_print->print_processname = false;
699 what_to_print->print_pid = false;
703 what_to_print->print_datetime = true;
704 what_to_print->print_processname = true;
706 /* pid is dealt with at the syslog level if we're syslogging */
707 what_to_print->print_pid =
708 (((log_struct->display_options & logoption_pid) == 0)?false:true);
711 what_to_print->print_srcfile =
712 (((log_struct->display_options & logoption_nfile) == 0)?true:false);
713 what_to_print->print_srcline =
714 (((log_struct->display_options & logoption_nline) == 0)?true:false);
716 what_to_print->print_errlevel = true;
717 what_to_print->print_errtype = true;
720 void generate_message_details(char *message_details_buffer,
721 int message_details_buffer_length,
722 struct tag_log_file_data *log_struct,
723 enum loglevels loglevel, enum logtypes logtype)
726 char processinfo[64];
728 char *ptr = message_details_buffer;
730 int len = message_details_buffer_length;
732 char log_buffer[MAXLOGSIZE];
733 const char *logtype_string;
735 char loglevel_string[12]; /* max int size is 2 billion, or 10 digits */
737 struct what_to_print_array what_to_print;
739 workout_what_to_print(&what_to_print, log_struct);
741 #ifdef DEBUG_OUTPUT_TO_SCREEN
742 printf("Making MessageDetails\n");
751 if (what_to_print.print_datetime)
756 /* some people might prefer localtime() to gmtime() */
757 strftime(ptr, len, "%b %d %H:%M:%S", localtime(&thetime));
758 #ifdef DEBUG_OUTPUT_TO_SCREEN
759 printf("date is %s\n", ptr);
762 templen = strlen(ptr);
764 if (what_to_print.print_processname || what_to_print.print_pid)
765 strncat(ptr, " ", len);
767 strncat(ptr, ":", len);
779 if (what_to_print.print_processname)
781 strncpy(ptr, global_log_data.processname, len);
783 templen = strlen(ptr);
788 if (what_to_print.print_pid)
790 pid_t pid = getpid();
792 sprintf(ptr, "[%d]", pid);
794 templen = strlen(ptr);
799 if (what_to_print.print_srcfile || what_to_print.print_srcline)
801 char sprintf_buffer[8];
804 sprintf_buffer[0] = '[';
805 if (what_to_print.print_srcfile)
807 strcpy(&sprintf_buffer[1], "%s");
808 buff_ptr = &sprintf_buffer[3];
810 if (what_to_print.print_srcfile && what_to_print.print_srcline)
812 strcpy(&sprintf_buffer[3], ":");
813 buff_ptr = &sprintf_buffer[4];
815 if (what_to_print.print_srcline)
817 strcpy(buff_ptr, "%d");
818 buff_ptr = &buff_ptr[2];
820 strcpy(buff_ptr, "]");
823 ok sprintf string is ready, now is the 1st parameter src or linenumber
825 if (what_to_print.print_srcfile)
827 sprintf(ptr, sprintf_buffer,
828 global_log_data.temp_src_filename,
829 global_log_data.temp_src_linenumber);
833 sprintf(ptr, sprintf_buffer, global_log_data.temp_src_linenumber);
836 #ifdef DEBUG_OUTPUT_TO_SCREEN
837 printf("Process info is %s\n", ptr);
840 templen = strlen(ptr);
846 if (what_to_print.print_processname || what_to_print.print_pid ||
847 what_to_print.print_srcfile || what_to_print.print_srcline)
849 strncat(ptr, ": ", len);
855 loglevel_string[0] = 0;
856 ptr = loglevel_string;
859 if (what_to_print.print_errlevel)
861 if ((loglevel/10) >= (num_loglevel_chars-1))
863 sprintf(ptr, "%c%d", arr_loglevel_chars[num_loglevel_chars-1],
868 sprintf(ptr, "%c", arr_loglevel_chars[loglevel/10]);
871 templen = strlen(ptr);
876 if (what_to_print.print_errtype)
878 const char *logtype_string;
880 /* get string represnetation of the Log Type */
881 if (logtype<num_logtype_strings)
882 logtype_string = arr_logtype_strings[logtype];
886 if (what_to_print.print_errlevel)
888 strncat(ptr, ":", len);
892 sprintf(ptr, "%s", logtype_string);
895 message_details_buffer[message_details_buffer_length-1] = 0;
897 #ifdef DEBUG_OUTPUT_TO_SCREEN
898 printf("Message Details are %s\n", message_details_buffer);
901 #endif /* DISABLE_LOGGER */
903 int get_syslog_equivalent(enum loglevels loglevel)
907 /* The question is we know how bad it is for us,
908 but how should that translate in the syslogs? */
913 case 2: /* warning */
917 case 4: /* information */
924 /* void setuplog(char *logsource, char *logtype, char *loglevel, char *filename) */
925 void setuplog(char *logtype, char *loglevel, char *filename)
927 #ifndef DISABLE_LOGGER
928 /* -[un]setuplog <logtype> <loglevel> [<filename>]*/
930 This should be rewritten so that somehow logsource is assumed and everything
931 can be taken from default if needs be.
933 /* const char* sources[] = {"syslog", "filelog"}; */
934 const char *null = "";
935 int sourcenum, typenum, levelnum;
936 log_file_data_pair *logs = log_file_arr[logtype_default];
939 LOG(log_extradebug, logtype_logger, "Attempting setuplog: %s %s %s %s",
940 logsource, logtype, loglevel, filename);
942 LOG(log_info, logtype_logger, "setuplog is parsing logtype:%s, loglevel:%s, filename:%s",
943 logtype, loglevel, filename);
947 LOG(log_note, logtype_logger, "no logsource given, default is assumed");
952 for(typenum=0;typenum<num_logtype_strings;typenum++)
954 if (strcasecmp(logtype, arr_logtype_strings[typenum])==0)
957 if (typenum>=num_logtype_strings)
959 LOG(log_warning, logtype_logger, "%s is not a valid log type", logtype);
965 LOG(log_note, logtype_logger, "no loglevel given, severe is assumed");
970 for(levelnum=0;levelnum<num_loglevel_strings;levelnum++)
972 if (strcasecmp(loglevel, arr_loglevel_strings[levelnum])==0)
975 if (levelnum>=num_loglevel_strings)
977 LOG(log_warning, logtype_logger, "%s is not a valid log level", loglevel);
982 if ((typenum>=num_logtype_strings) || (levelnum>=num_loglevel_strings))
984 LOG(log_warning, logtype_logger, "sanity check failed: (%s:%d), (%s:%d)",
985 logtype, typenum, loglevel, levelnum);
989 /* now match the order of the text string with the actual enum value (10 times) */
992 /* is this a syslog setup or a filelog setup */
993 if (filename==NULL) /* must be syslog */
995 LOG(log_debug6, logtype_logger, "calling syslog_setup(%d, %d, ...)", levelnum, typenum);
996 syslog_setup(levelnum, typenum,
997 (*logs)[0].display_options,
998 global_log_data.facility);
1000 else /* this must be a filelog */
1002 LOG(log_debug6, logtype_logger, "calling log_setup(%s, %d, %d, ...)", filename, levelnum, typenum);
1003 log_setup(filename, levelnum, typenum,
1004 (*logs)[0].display_options);
1007 #endif /* DISABLE_LOGGER */