mgxapp/lib/tools.c
/*
	Write a message if the level is >= the selected level.
*/
Write a message if the level is >= the selected level.
Write a message if the level is > = the selected level .
extern void mt_log( int vlevel, const char* fmt, ... ) {
	static int	pid = 0;
	va_list		argp;			
	char		msg[4096];
	char*		nl;
	if( vlevel > mt_log_vlevel ) {
		return;
	}
	if( !pid ) {
		pid = getpid();
		mt_log_init();					
	}
	va_start( argp, fmt );
	vsnprintf( msg, sizeof( msg ),  fmt, argp );		
	va_end( argp );
	if( (nl = strchr( msg, '\n' )) != NULL ) {		
		*nl = 0;
	}
	if( mt_hr_msgs ) {
		char*	vstr = "UNK";
		switch( vlevel ) {
			case MT_LOG_CRIT:
				vstr = "[CRIT]";
				break;
			case MT_LOG_ERR:
				vstr = "[ERR] ";
				break;
			case MT_LOG_WARN:
				vstr = "[WARN]";
				break;
			case MT_LOG_INFO:
				vstr = "[INFO]";
				break;
			case MT_LOG_DEBUG:
				vstr = "[DBUG]";
				break;
		}
		fprintf( mt_log_dest, "%10d  %d/%s %s %s\n", (int) time( NULL ), pid, "munchkin",  vstr, msg );
	} else {
		mdclog_write( mt_mdc_level, "%s", msg );
	}
}
extern void mt_log ( int vlevel , const char * fmt , ... ) { static int pid = 0 ; va_list argp ; char msg [ 4096 ] ; char * nl ; if ( vlevel > mt_log_vlevel ) { return ; } if ( ! pid ) { pid = getpid ( ) ; mt_log_init ( ) ; } va_start ( argp , fmt ) ; vsnprintf ( msg , sizeof ( msg ) , fmt , argp ) ; va_end ( argp ) ; if ( ( nl = strchr ( msg , ' \n ' ) ) != NULL ) { * nl = 0 ; } if ( mt_hr_msgs ) { char * vstr = " " ; switch ( vlevel ) { case MT_LOG_CRIT : vstr = " " ; break ; case MT_LOG_ERR : vstr = " " ; break ; case MT_LOG_WARN : vstr = " " ; break ; case MT_LOG_INFO : vstr = " " ; break ; case MT_LOG_DEBUG : vstr = " " ; break ; } fprintf ( mt_log_dest , " \n " , ( int ) time ( NULL ) , pid , " " , vstr , msg ) ; } else { mdclog_write ( mt_mdc_level , " " , msg ) ; } }
Write a message if the level is >= the selected level.
Write a message if the level is > = the selected level .
// variable arg pointer // likely not initialised either // format user's message // newlines not allowed -- truncate at first