Exemplo n.º 1
0
/**
 * Log a message.  If possible, all messages should be indexed by message number, and
 * the use of the format string should be minimized or negated altogether.  If format is
 * provided, the message number is only used as a message label.
 * @param log_level the log level of the message
 * @param msgno the id of the message to use if the format string is NULL
 * @param aFormat the printf format string to be used if the message id does not exist
 * @param ... the printf inserts
 */
void Log(int log_level, int msgno, char* format, ...)
{
	char* temp = NULL;
	static char msg_buf[512];

	if (log_level >= trace_settings.trace_level)
	{
		va_list args;

		if (format == NULL && (temp = Messages_get(msgno, log_level)) != NULL)
			format = temp;

		va_start(args, format);
		vsnprintf(msg_buf, sizeof(msg_buf), format, args);

		Log_trace(log_level, msg_buf);
		va_end(args);
	}

	/*if (log_level >= LOG_ERROR)
	{
		char* filename = NULL;
		Log_recordFFDC(&msg_buf[7]);
	}

	if (log_level == LOG_FATAL)
		exit(-1);*/
}
Exemplo n.º 2
0
/**
 * Log a message.  If possible, all messages should be indexed by message number, and
 * the use of the format string should be minimized or negated altogether.  If format is
 * provided, the message number is only used as a message label.
 * @param log_level the log level of the message
 * @param msgno the id of the message to use if the format string is NULL
 * @param aFormat the printf format string to be used if the message id does not exist
 * @param ... the printf inserts
 */
void Log(int log_level, int msgno, char* format, ...)
{
	if (log_level >= trace_settings.trace_level)
	{
		char* temp = NULL;
		static char msg_buf[512];
		va_list args;

		/* we're using a static character buffer, so we need to make sure only one thread uses it at a time */
		Thread_lock_mutex(log_mutex); 
		if (format == NULL && (temp = Messages_get(msgno, log_level)) != NULL)
			format = temp;

		va_start(args, format);
		vsnprintf(msg_buf, sizeof(msg_buf), format, args);

		Log_trace(log_level, msg_buf);
		va_end(args);
		Thread_unlock_mutex(log_mutex); 
	}

	/*if (log_level >= LOG_ERROR)
	{
		char* filename = NULL;
		Log_recordFFDC(&msg_buf[7]);
	}
	*/
}
Exemplo n.º 3
0
/**
 * Log a message.  If possible, all messages should be indexed by message number, and
 * the use of the format string should be minimized or negated altogether.  If format is
 * provided, the message number is only used as a message label.
 * @param log_level the log level of the message
 * @param msgno the id of the message to use if the format string is NULL
 * @param aFormat the printf format string to be used if the message id does not exist
 * @param ... the printf inserts
 */
void Log(int log_level, int msgno, char* format, ...)
{
	int islogmsg = 1;
	char* temp = NULL;
	static char msg_buf[256];

	if (log_level < LOG_CONFIG)
		islogmsg = 0;

#if defined(HIGH_PERFORMANCE)
	if (!islogmsg)
#else
	if (!islogmsg && log_level < trace_settings.trace_level)
#endif
		return;

	if (islogmsg &&	log_level < trace_settings.log_level)
		return;

	if (format == NULL && (temp = Messages_get(msgno, log_level)) != NULL)
		format = temp;

	if (!islogmsg)
	{
		static char trace_msg_buf[256];
		va_list args;

		va_start(args, format);
		vsnprintf(trace_msg_buf, sizeof(trace_msg_buf), format, args);
		Log_trace(log_level, trace_msg_buf);
		va_end(args);
		return;
	}

	if (Log_recurse_flag == 0)
	{
		struct tm *timeinfo;
		char level_char = ' ';
		int buf_pos = 31;
		va_list args;

#if defined(GETTIMEOFDAY)
		gettimeofday(&ts, NULL);
		timeinfo = localtime(&ts.tv_sec);
#else
		ftime(&ts);
		timeinfo = localtime(&ts.time);
#endif
		strftime(&msg_buf[7], 80, "%Y%m%d %H%M%S ", timeinfo);
#if defined(GETTIMEOFDAY)
		sprintf(&msg_buf[22], ".%.3lu ", ts.tv_usec / 1000L);
#else
		sprintf(&msg_buf[22], ".%.3hu ", ts.millitm);
#endif
		buf_pos = 27;

#if defined(GETTIMEOFDAY)
		if (ts.tv_sec == last_ts.tv_sec && ts.tv_usec == last_ts.tv_usec)
#else
		if (ts.time == last_ts.time && ts.millitm == last_ts.millitm)
#endif
			++sametime_count; /* this message has the same timestamp as the last, so increase the sequence no */
		else
		{
			sametime_count = 0;
			last_ts = ts;
		}
		sprintf(msg_buf, "(%.4d)", sametime_count);
		msg_buf[6] = ' ';

		level_char = "     CDIAWESF"[log_level];
		sprintf(&msg_buf[buf_pos], "%s%.4d%c ", MSG_PREFIX, msgno, level_char);
		buf_pos += 11;

		va_start(args, format);
		vsnprintf(&msg_buf[buf_pos], sizeof(msg_buf)-buf_pos, format, args);
		va_end(args);

		if (log_level >= LOG_ERROR)
		{
			char* filename = NULL;
			Log_recurse_flag = 1;
			filename = Broker_recordFFDC(&msg_buf[7]);
			Log_recurse_flag = 0;
			snprintf(&msg_buf[buf_pos], sizeof(msg_buf)-buf_pos, Messages_get(13, LOG_WARN), filename);
		}

		addToBuffer(log_buffer, msg_buf);
#if !defined(WIN32)
		if (trace_settings.isdaemon)
		{
			static char priorities[] = { 7, 7, 7, 7, 6, 6, 5, 5, 4, 3, 1, 0};
			syslog(priorities[log_level], "%s", &msg_buf[22]);
		}
		else
		{
#endif
			printf("%s\n", &msg_buf[7]);
			fflush(stdout);
#if !defined(WIN32)
		}
#endif
		if (Log_publishFlag)
		{
			#define MAX_LOG_TOPIC_NAME_LEN 25
			static char topic_buf[MAX_LOG_TOPIC_NAME_LEN];
			sprintf(topic_buf, "$SYS/broker/log/%c/%.4d", level_char, msgno);
			Log_recurse_flag = 1;
			Log_Publish(topic_buf, &msg_buf[7]);
			Log_recurse_flag = 0;
		}
	}

	if (log_level == LOG_FATAL)
		exit(-1);
}