src/log.c
/* This function is the main log print function. It accepts a log
   level/severity, a format string, and a variable number of parameters to
   build the final output. The format string uses the same syntax as printf.

   All output is directed to stderr/stdout. */
This function is the main log print function. It accepts a log
level/severity, a format string, and a variable number of parameters to
build the final output. The format string uses the same syntax as printf.

All output is directed to stderr/stdout.
This function is the main log print function . It accepts a log level / severity a format string and a variable number of parameters to build the final output . The format string uses the same syntax as printf . All output is directed to stderr / stdout .
void lprint(log_level_t level, const char *format, ...) {
	char output_format[LOG_LEN];
	va_list args;
	va_start(args, format);
	if(strlen(format) + 10 > LOG_LEN) {
		fprintf(stderr, "[!!!] Log string is too long!\n");
		vfprintf(stdout, format, args);
		fprintf(stdout, "\n");
		va_end(args);
		return;
	}
	switch(level) {
	case DEBUG:
		strcpy(output_format, "[DEBUG] ");
		break;
	case INFO:
		strcpy(output_format, "[INFO] ");
		break;
	case WARN:
		strcpy(output_format, "[WARN] ");
		break;
	case ERROR:
		strcpy(output_format, "[ERROR] ");
		break;
	default:
		strcpy(output_format, "");
		break;
	}
	strcat(output_format, format);
	strcat(output_format, "\n");
	if(level == ERROR)
		vfprintf(stderr, output_format, args);
	else
		vfprintf(stdout, output_format, args);
	va_end(args);
}
void lprint ( log_level_t level , const char * format , ... ) { char output_format [ LOG_LEN ] ; va_list args ; va_start ( args , format ) ; if ( strlen ( format ) + 10 > LOG_LEN ) { fprintf ( stderr , " \n " ) ; vfprintf ( stdout , format , args ) ; fprintf ( stdout , " \n " ) ; va_end ( args ) ; return ; } switch ( level ) { case DEBUG : strcpy ( output_format , " " ) ; break ; case INFO : strcpy ( output_format , " " ) ; break ; case WARN : strcpy ( output_format , " " ) ; break ; case ERROR : strcpy ( output_format , " " ) ; break ; default : strcpy ( output_format , " " ) ; break ; } strcat ( output_format , format ) ; strcat ( output_format , " \n " ) ; if ( level == ERROR ) vfprintf ( stderr , output_format , args ) ; else vfprintf ( stdout , output_format , args ) ; va_end ( args ) ; }
This function is the main log print function.
This function is the main log print function .
/* This character array will contain the adjusted format that we'll pass to
	   vfprintf. We don't need to initialize this, as strcpy will  */ /* Initializes the vararg list to prepare for future vfprintf calls. */ /* Ensures that adding the severity tag and a newline to the format string
	   will not cause a buffer overflow. If this occurs, print an error and
	   print the log entry without the severity tag. */ /* Normally we concatenate a newline to the format string. Since we're
		   struggling for space we'll have to print it manually. */ /* Ends the vararg list and returns to the calling function. */ /* Selects which prefix to add to the output format string. If you would
	   like to add additional log levels, add them to the log_level_t enum in
	   log.h and insert the tag here. Please note that you may have to adjust
	   the buffer overflow check above if your tag longer than the ones
	   below. */ /* Since no valid severity has been passed, we'll need to initialize
		   the string so that we don't run into issues. */ /* Concatenate the passed format string as well as a newline to the output
	   format. */ /* If the severity is high enough, output to stderr instead of stdout. */ /* Ends the vararg list. */