static int logger_routine(void *p) { natv_logger_t *nl = (natv_logger_t *)p; swapi_message_t msg; while(1) { swapi_queue_wait(nl->nl_queue, &msg); logger_output((char*)msg.sm_ptr, msg.sm_size); if(nl->nl_fd != NULL) { fwrite((void*)msg.sm_ptr, msg.sm_size, 1, nl->nl_fd); fflush(nl->nl_fd); printf("%s\n", (char*)msg.sm_ptr); } free(msg.sm_ptr); } return 0; }
/* Decide if a message should be logged based on the logger configuration * and the message tag. If it's enabled for logging, print: * [The message severity] (The origin system) The message * * Message severity tags: * [R] Interrupt service routine (ISR) * [I] Informational * [W] Warning * [E] Error */ void logger_system_filter( char *logsys, logger_level_t loglevel, char *logmsg ) { char sysname[LOGGER_BUFFERSIZE]; struct system_struct *system_array_ptr = system_array; // Go through all systems looking for a match to the system name while (strcmp( system_array_ptr -> name, "" ) != 0) { if (strcmp( logsys, system_array_ptr -> name ) == 0) { // We've found a matching system if ((logger_config_ptr -> enable) & (1<< (system_array_ptr -> bitshift))) { /* The system is enabled for logging. Send three strings * to the logging device: * 1. [Severity] * 1. (System name) * 2. Log message */ switch( loglevel ) { case log_level_ISR: logger_output("[R]"); break; case log_level_INFO: logger_output("[I]"); break; case log_level_WARNING: sound_play_warn(); logger_output("[W]"); break; case log_level_ERROR: sound_play_error(); logger_output("[E]"); break; } snprintf(sysname,LOGGER_BUFFERSIZE,"(%s) ", system_array_ptr -> name); logger_output(sysname); logger_output(logmsg); break; } } system_array_ptr++; } return; }