Go to the source code of this file.
Functions | |
| void | msgLogInit (const char *ident) |
| void | msgLogCleanup (void) |
| void | msgLogNodeIdSet (long nodeid) |
| void | msgLogPidSet (long pid) |
| void | msgLogLocalEchoSet (int enable) |
| void | msgLogResetMsgCount (long count) |
| long | msgLogGetMsgCount () |
| void | logDebugLevelSet (unsigned int level) |
| void | logMaxRepRateSet (long max_dt_ns) |
| void | logCritical (const char *fmt,...) |
| void | logError (const char *fmt,...) |
| void | logWarn (const char *fmt,...) |
| void | logNotice (const char *fmt,...) |
| void | logInfo (const char *fmt,...) |
| void | logDebug (unsigned int level, const char *fmt,...) |
| void logCritical | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 571 of file msgLog.c.
References logMessage().
00571 { 00572 00573 va_list args; 00574 va_start(args, fmt); 00575 logMessage(LOG_CRIT, fmt, args); 00576 va_end(args); 00577 00578 } /* logCritical */
| void logDebug | ( | unsigned int | level, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 667 of file msgLog.c.
References lDebugLevel, and logMessage().
00667 { 00668 00669 va_list args; 00670 00671 /* 00672 * Check requested level against threshold - values < 1 are 00673 * prohibited and reset to one to avoid situation where some 00674 * debug messages always get through. 00675 */ 00676 if (level < 1) { 00677 level = 1; 00678 } 00679 if (level <= lDebugLevel) { 00680 va_start(args, fmt); 00681 logMessage(LOG_DEBUG, fmt, args); 00682 va_end(args); 00683 } 00684 00685 } /* logDebug */
| void logDebugLevelSet | ( | unsigned int | level | ) |
Definition at line 518 of file msgLog.c.
References lDebugLevel.
00521 { 00522 00523 lDebugLevel = level; 00524 00525 } /* logDebugLevelSet */
| void logError | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 590 of file msgLog.c.
References logMessage().
00590 { 00591 00592 va_list args; 00593 va_start(args, fmt); 00594 logMessage(LOG_ERR, fmt, args); 00595 va_end(args); 00596 00597 } /* logError */
| void logInfo | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 647 of file msgLog.c.
References logMessage().
00647 { 00648 00649 va_list args; 00650 va_start(args, fmt); 00651 logMessage(LOG_INFO, fmt, args); 00652 va_end(args); 00653 00654 } /* logInfo */
| void logMaxRepRateSet | ( | long | max_dt_ns | ) |
| void logNotice | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 628 of file msgLog.c.
References logMessage().
00628 { 00629 00630 va_list args; 00631 va_start(args, fmt); 00632 logMessage(LOG_NOTICE, fmt, args); 00633 va_end(args); 00634 00635 } /* logNotice */
| void logWarn | ( | const char * | fmt, | |
| ... | ||||
| ) |
Definition at line 609 of file msgLog.c.
References logMessage().
00609 { 00610 00611 va_list args; 00612 va_start(args, fmt); 00613 logMessage(LOG_WARNING, fmt, args); 00614 va_end(args); 00615 00616 } /* logWarn */
| void msgLogCleanup | ( | void | ) |
Definition at line 389 of file msgLog.c.
References lSocket.
00390 { 00391 00392 #ifdef VxWorks 00393 /* Clean up any existing msgLogger task and message queue */ 00394 if (lMsgLogTaskId != NULL) { 00395 taskDelete(lMsgLogTaskId); 00396 lMsgLogTaskId = NULL; 00397 } 00398 if (lMsgLogQId != NULL) { 00399 msgQDelete(lMsgLogQId); 00400 lMsgLogQId = NULL; 00401 } 00402 #endif 00403 00404 #ifndef USESYSLOG 00405 /* Close the UDP socket if it is open */ 00406 if (lSocket != 0) { 00407 close(lSocket); 00408 lSocket = 0; 00409 } 00410 #endif 00411 00412 } /* msgLogCleanup */
| long msgLogGetMsgCount | ( | ) |
Definition at line 546 of file msgLog.c.
References mdMsgLogHeader_t::count, mdMsgLogBuffer_t::hdr, and lBuffer.
00547 { 00548 #ifndef USESYSLOG 00549 #ifndef VxWorks 00550 return (lBuffer.hdr.count); 00551 #endif 00552 #else 00553 return -1; 00554 #endif 00555 } /* msgLogResetMsgCount */
| void msgLogInit | ( | const char * | ident | ) |
Definition at line 219 of file msgLog.c.
References mdMsgLogHeader_t::count, DAQ_LOG_FACILITY, DAQ_MSG_IP, ERROR, mdMsgLogBuffer_t::hdr, lastMessageTime, lBuffer, lDebugLevel, lMsgLocalEcho, lServerAddr, lSocket, MINOS_UNIDENTIFIED_CLIENT, MSGLOG_DEFAULT_IP, MSGLOG_MAXNAME, MSGLOG_PORT, NATIVE_MSG, mdMsgLogHeader_t::nodeFrom, mdMsgLogHeader_t::pid, port, and mdMsgLogHeader_t::prcName.
00222 { 00223 00224 #ifdef USESYSLOG 00225 #ifdef VxWorks 00226 /* Do nothing */ 00227 #else /* !VxWorks */ 00228 openlog(ident, LOG_PERROR | LOG_PID, DAQ_LOG_FACILITY); 00229 #endif /* VxWorks */ 00230 00231 #else /* !USESYSLOG */ 00232 00233 const char* ip; 00234 const char* portenv; 00235 int port; 00236 int sockAddrSize; 00237 int pid; 00238 00239 /*set last message time to 01/01/70 00240 * this way first message is always sent */ 00241 lastMessageTime.tv_sec = 0; 00242 lastMessageTime.tv_nsec = 0; 00243 00244 sockAddrSize = sizeof(struct sockaddr_in); 00245 00246 /* Clear socket address structure */ 00247 bzero((char *)&lServerAddr, sockAddrSize); 00248 00249 /* 00250 * For VxWorks we pull the message server IP address directly from 00251 * the boot parameters. Otherwise, the server name/IP is resolved from 00252 * environment variables or falls back to the local host 00253 */ 00254 #ifdef VxWorks 00255 { 00256 char bootString[BOOT_LINE_SIZE]; 00257 BOOT_PARAMS bootParams; 00258 00259 /* 00260 * Get the msgLogger IP adddress from the "other" field of the boot 00261 * parameters 00262 */ 00263 sysNvRamGet(bootString, BOOT_LINE_SIZE, 0); 00264 bootStringToStruct(bootString, &bootParams); 00265 ip = (char *)&(bootParams.other); 00266 port = MSGLOG_PORT; 00267 00268 if ((lServerAddr.sin_addr.s_addr = inet_addr(ip)) == ERROR) { 00269 NATIVE_MSG("msgLogInit: bad server name from boot params: %s", ip); 00270 return; 00271 } 00272 pid = taskIdSelf(); 00273 00274 /* Clean up any existing msgLogger task and message queue */ 00275 if (lMsgLogTaskId != NULL) { 00276 NATIVE_MSG("msgLogInit: deleting existing message logger task (tid=0x%x)\n", lMsgLogTaskId); 00277 taskDelete(lMsgLogTaskId); 00278 lMsgLogTaskId = NULL; 00279 } 00280 if (lMsgLogQId != NULL) { 00281 NATIVE_MSG("msgLogInit: deleting existing message logger queue (id=0x%x)\n", lMsgLogQId); 00282 msgQDelete(lMsgLogQId); 00283 lMsgLogQId = NULL; 00284 } 00285 00286 /* Create the message queue for the logging task */ 00287 lMsgLogQId = msgQCreate(MSGQ_MAX_MSGS, sizeof(mdMsgLogBuffer), MSG_Q_FIFO); 00288 if (lMsgLogQId == NULL) { 00289 NATIVE_MSG("msgLogInit: msgQCreate failed: %s", strerror(errno)); 00290 return; 00291 } 00292 /* Spawn the message logging task */ 00293 lMsgLogTaskId = taskSpawn("tMsgLogger", TASK_PRIORITY_MSGLOGGER, 0, 00294 TASK_SIZE_MSGLOGGER, (FUNCPTR)tMsgLogger, 00295 0,0,0,0,0,0,0,0,0,0); 00296 if (lMsgLogTaskId == ERROR) { 00297 NATIVE_MSG("msgLogInit: task creation failed: %s", strerror(errno)); 00298 return; 00299 } 00300 } 00301 #else /* !Vxworks */ 00302 { 00303 struct hostent *host_ptr; /*the host add*/ 00304 00305 /* 00306 * Pull the msg logger IP address and port from env vars, otherwise 00307 * take the default values 00308 */ 00309 ip = getenv(DAQ_MSG_IP); 00310 if (ip == NULL) { 00311 ip = MSGLOG_DEFAULT_IP; 00312 } 00313 portenv = getenv("DAQ_MSG_PORT"); 00314 if ( portenv == NULL){ 00315 port = MSGLOG_PORT; 00316 } else { 00317 sscanf(portenv, "%d", &port); 00318 } 00319 00320 /* Resolve server hostname to address */ 00321 host_ptr = gethostbyname(ip); 00322 if(!host_ptr ||host_ptr->h_addrtype != AF_INET ){ 00323 NATIVE_MSG( "msgLogInit: bad server name/address: %s , %s",ip, strerror(errno)); 00324 return; 00325 } 00326 memcpy(&lServerAddr.sin_addr.s_addr, host_ptr->h_addr, host_ptr->h_length); 00327 if(lServerAddr.sin_addr.s_addr == INADDR_NONE) 00328 { 00329 NATIVE_MSG( "msgLogInit: unresolved server address, unable to open msgLog socket\n"); 00330 return; 00331 } 00332 00333 /* Get current process ID */ 00334 pid = getpid(); 00335 00336 /* Open syslog connection for fallback (native) messages */ 00337 openlog(ident, LOG_PERROR | LOG_PID, DAQ_LOG_FACILITY); 00338 } 00339 #endif /* VxWorks */ 00340 00341 /* Fill in port and type in socket address structure */ 00342 /* lServerAddr.sin_len = (unsigned char)sockAddrSize; */ 00343 lServerAddr.sin_family = AF_INET; 00344 lServerAddr.sin_port = htons(port); 00345 00346 /* Close the old socket if it exists */ 00347 if (lSocket != 0) { 00348 NATIVE_MSG("msgLogInit: closing existing message logger socket (id=0x%x)\n", lSocket); 00349 close(lSocket); 00350 lSocket = 0; 00351 } 00352 00353 /* Create the UDP datagram socket */ 00354 lSocket = socket(AF_INET, SOCK_DGRAM, 0); 00355 if(lSocket == -1) { 00356 NATIVE_MSG("msgLogInit: socket() failed: %s", strerror(errno)); 00357 return; 00358 } 00359 00360 /* Initialise message header */ 00361 lBuffer.hdr.pid = pid; 00362 lBuffer.hdr.count = 0; 00363 lBuffer.hdr.nodeFrom = MINOS_UNIDENTIFIED_CLIENT; 00364 strncpy(lBuffer.hdr.prcName, ident, MSGLOG_MAXNAME); 00365 00366 /* Set local message echoing off by default */ 00367 lMsgLocalEcho = 0; 00368 00369 #endif /* USESYSLOG */ 00370 00371 /* Set default debug level to zero */ 00372 lDebugLevel = 0; 00373 00374 return; 00375 00376 } /* msgLogInit */
| void msgLogLocalEchoSet | ( | int | enable | ) |
Definition at line 475 of file msgLog.c.
References lMsgLocalEcho.
00478 { 00479 #ifdef USESYSLOG 00480 00481 #else 00482 lMsgLocalEcho = enable; 00483 #endif 00484 return; 00485 00486 } /* msgLogLocalEchoSet */
| void msgLogNodeIdSet | ( | long | nodeid | ) |
Definition at line 427 of file msgLog.c.
References mdMsgLogBuffer_t::hdr, lBuffer, and mdMsgLogHeader_t::nodeFrom.
00430 { 00431 #ifdef USESYSLOG 00432 00433 #else 00434 lBuffer.hdr.nodeFrom = nodeId; 00435 #endif 00436 return; 00437 00438 } /* msgLoNodeIdSet */
| void msgLogPidSet | ( | long | pid | ) |
Definition at line 451 of file msgLog.c.
References mdMsgLogBuffer_t::hdr, lBuffer, and mdMsgLogHeader_t::pid.
00454 { 00455 #ifdef USESYSLOG 00456 00457 #else 00458 lBuffer.hdr.pid = pid; 00459 #endif 00460 return; 00461 00462 } /* msgLogPidSet */
| void msgLogResetMsgCount | ( | long | count | ) |
Definition at line 537 of file msgLog.c.
References mdMsgLogHeader_t::count, mdMsgLogBuffer_t::hdr, and lBuffer.
00538 { 00539 #ifndef USESYSLOG 00540 #ifndef VxWorks 00541 lBuffer.hdr.count = count; 00542 #endif 00543 #endif 00544 } /* msgLogResetMsgCount */
1.4.7