FACT++  1.0
void createLogMessage ( unsigned int  type,
char *  description,
char *  origin 
)

Definition at line 1530 of file feeserver.c.

References checkLogLevel(), checkReplicatedLogMessage(), dis_update_service, message, time, and type.

Referenced by ack_service(), allocateMemory(), command_handler(), createHeader(), createMemoryNode(), dim_dummy_exit_handler(), dim_error_msg_handler(), fee_exit_handler(), freeMemory(), getDeadband(), getIssueTimeout(), getLogLevel(), getUpdateRate(), initialize(), leaveCommandHandler(), marshallHeader(), monitorIntValues(), monitorValues(), runLogWatchDog(), setDeadband(), setFeeProperty(), setIssueTimeout(), setLogLevel(), setUpdateRate(), start(), startMonitorThread(), threadIssue(), triggerRestart(), unlockIssueMutex(), updateFeeServer(), and updateFeeService().

1530  {
1531  int status = -1; // for mutex
1532  int descLength = 0;
1533  int originLength = 0;
1534  time_t timeVal;
1535  struct tm* now = 0;
1536 
1537  // check if not in COLLECTING state
1538  if (state == COLLECTING) {
1539  return; // no log channel available at that time
1540  }
1541 
1542  //lock access with mutex due to the fact that FeeServer & CE can use it
1543  status = pthread_mutex_lock(&log_mut);
1544  // discard eventual error, this would cause more problems
1545  // in each case, do NOT call createLogMessage ;) !
1546 # ifdef __DEBUG
1547  if (status != 0) {
1548  printf("Lock log mutex error: %d\n", status);
1549  fflush(stdout);
1550  }
1551 # endif
1552 
1553  if (!checkLogLevel(type)) { //if not -> unlock mutex -> return
1554  //unlock mutex
1555  status = pthread_mutex_unlock(&log_mut);
1556  // discard eventual error, this would cause more problems
1557  // in each case, do NOT call createLogMessage ;)
1558 # ifdef __DEBUG
1559  if (status != 0) {
1560  printf("Unlock log mutex error: %d\n", status);
1561  fflush(stdout);
1562  }
1563 # endif
1564  return;
1565  }
1566 
1567  // check if message is a replicate of the last log message
1568  if ((logWatchDogRunning) && (strncmp(description, lastMessage.description,
1569  (MSG_DESCRIPTION_SIZE - 1)) == 0)) {
1571 
1572  //unlock mutex
1573  status = pthread_mutex_unlock(&log_mut);
1574  // discard eventual error, this would cause more problems
1575  // in each case, do NOT call createLogMessage ;)
1576 # ifdef __DEBUG
1577  if (status != 0) {
1578  printf("Unlock log mutex error: %d\n", status);
1579  fflush(stdout);
1580  }
1581 # endif
1582  // message is a replicate of last message, leave Messenger
1583  return;
1584  } else {
1585  // message is not a replicate of last one send,
1586  // check if replicated log messages are pending
1587  if (checkReplicatedLogMessage()) {
1588  // sleep a small amount to let Dim update channel
1589 // usleep(1000);
1590  }
1591  }
1592 
1593  // prepare data (cut off overlength)
1594  if (description != 0) {
1595  // limit description to maximum of field in message struct if longer
1596  descLength = ((strlen(description) >= MSG_DESCRIPTION_SIZE)
1597  ? (MSG_DESCRIPTION_SIZE - 1) : strlen(description));
1598  }
1599  if (origin != 0) {
1600  // limit origin to maximum of field in message struct if longer
1601  // be aware that "source" also contains server name and a slash
1602  originLength = ((strlen(origin) >= MSG_SOURCE_SIZE - serverNameLength - 1)
1603  ? (MSG_SOURCE_SIZE - serverNameLength - 2) : strlen(origin));
1604  }
1605 
1606  //set type
1607  message.eventType = type;
1608  //set detector
1609  memcpy(message.detector, LOCAL_DETECTOR, MSG_DETECTOR_SIZE);
1610  //set origin
1611  strcpy(message.source, serverName);
1612  if (origin != 0) {
1613  // append slash
1614  strcpy(message.source + serverNameLength, "/");
1615  // append origin maximum til end of source field in message struct
1616  strncpy(message.source + serverNameLength + 1, origin, originLength);
1617  // terminate with '\0'
1618  message.source[serverNameLength + 1 + originLength] = 0;
1619  }
1620  //set description
1621  if (description != 0) {
1622  // fill description field of message struct maximum til end
1623  strncpy(message.description, description, descLength);
1624  // terminate with '\0'
1625  message.description[descLength] = 0;
1626  } else {
1627  strcpy(message.description, "No description specified.");
1628  }
1629  //set current date and time
1630  time(&timeVal);
1631  now = localtime(&timeVal);
1632  message.date[strftime(message.date, MSG_DATE_SIZE, "%Y-%m-%d %H:%M:%S",
1633  now)] = 0;
1634 
1635  //updateService
1637 
1638  // copy send message to storage of last message
1639  lastMessage = message;
1640 
1641  //unlock mutex
1642  status = pthread_mutex_unlock(&log_mut);
1643  // discard eventual error, this would cause more problems
1644  // in each case, do NOT call createLogMessage ;)
1645 # ifdef __DEBUG
1646  if (status != 0) {
1647  printf("Unlock log mutex error: %d\n", status);
1648  fflush(stdout);
1649  }
1650 # endif
1651 }
static MessageStruct message
Definition: feeserver.c:101
bool checkLogLevel(int event)
Definition: feeserver.c:1653
static int serverNameLength
Definition: feeserver.c:189
bool checkReplicatedLogMessage()
Definition: feeserver.c:2202
int type
static pthread_mutex_t log_mut
Definition: feeserver.c:272
#define dis_update_service
Definition: dis.h:18
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
static char * serverName
Definition: feeserver.c:183
static unsigned short replicatedMsgCount
Definition: feeserver.c:114
static bool logWatchDogRunning
Definition: feeserver.c:122
static MessageStruct lastMessage
Definition: feeserver.c:108
static unsigned int messageServiceID
Definition: feeserver.c:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function: