23 #include "rmh_monitor.h"
28 #define PRINTBUF_SIZE 2048
29 static char printBuff[PRINTBUF_SIZE];
32 void RMH_Write(
RMHMonitor *app,
const char*buf) {
33 fputs(buf, app->out_file ? app->out_file : stdout);
40 void RMH_Print_Raw(
RMHMonitor *app,
struct timeval *time,
const char*fmt, ...) {
42 char *printString=printBuff;
45 static bool newLine =
true;
50 printSize = vsnprintf(printString, PRINTBUF_SIZE, fmt, ap);
58 if (app->printTimestamp) {
60 tm_info = localtime(&time->tv_sec);
61 snprintf(timeBuf,
sizeof(timeBuf),
"%02d.%02d.%02d %02d:%02d:%02d:%03ld ", tm_info->tm_year + 1900, tm_info->tm_mon + 1, tm_info->tm_mday, tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec, time->tv_usec/1000);
66 if (app->appPrefix &&
sizeof(timeBuf) > strlen(app->appPrefix) + strlen(timeBuf)) {
67 strcat(timeBuf, app->appPrefix);
72 while(printString[i] !=
'\0') {
75 if (app->printTimestamp) RMH_Write(app, timeBuf);
76 if (app->appPrefix) RMH_Write(app, app->appPrefix);
80 if (printString[i] ==
'\n') {
85 char tmp=printString[i+1];
86 printString[i+1]=
'\0';
87 RMH_Write(app, printString);
91 printString=&printString[i+1];
103 RMH_Write(app, printString);
106 if (printSize >= PRINTBUF_SIZE) {
107 RMH_Write(app,
"\nLog message truncated\n");
111 else if (printSize < 0 ) {
113 RMH_Write(app,
"\nInternal print error\n");