log.c
void log_init(enum log_level level, int colorful)
{
  struct sigaction sa;

  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = log_level_handler;

  sigaction(SIGRTMIN + LOG_LEVEL_ERROR,   &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_WARNING, &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_INFO,    &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_DEBUG,   &sa, NULL);

  if (colorful)
    {
      strcpy(colors[LOG_LEVEL_ERROR],   "\033[31m");
      strcpy(colors[LOG_LEVEL_WARNING], "\033[35m");
      strcpy(colors[LOG_LEVEL_INFO],    "\033[32m");
      strcpy(colors[LOG_LEVEL_DEBUG],   "\033[34m");
      strcpy(colors[COLOR_RESET],       "\033[0m");
    }

  if (level >= LOG_LEVEL_ERR)
    {
      fprintf(stderr, "E/Given log level is wrong, passed: %d\n", level);
      return;
    }

  log_level = level;
}
/*****************************************************************************
 * Name: log_init
 *
 * Description:
 *   Initializes logger and signal handlers for logger level
 *
 * Input Parameters:
 *   level:    Initial log level (can be changed later using signals)
 *   colorful: Makes prints look nice on colorful terminals
 ****************************************************************************/
log_init
Description:
Initializes logger and signal handlers for logger level

Input Parameters:
level:    Initial log level (can be changed later using signals)
colorful: Makes prints look nice on colorful terminals
log_init Description : Initializes logger and signal handlers for logger level Input Parameters : level : Initial log level ( can be changed later using signals ) colorful : Makes prints look nice on colorful terminals
void log_init(enum log_level level, int colorful)
{
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = log_level_handler;
  sigaction(SIGRTMIN + LOG_LEVEL_ERROR,   &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_WARNING, &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_INFO,    &sa, NULL);
  sigaction(SIGRTMIN + LOG_LEVEL_DEBUG,   &sa, NULL);
  if (colorful)
    {
      strcpy(colors[LOG_LEVEL_ERROR],   "\033[31m");
      strcpy(colors[LOG_LEVEL_WARNING], "\033[35m");
      strcpy(colors[LOG_LEVEL_INFO],    "\033[32m");
      strcpy(colors[LOG_LEVEL_DEBUG],   "\033[34m");
      strcpy(colors[COLOR_RESET],       "\033[0m");
    }
  if (level >= LOG_LEVEL_ERR)
    {
      fprintf(stderr, "E/Given log level is wrong, passed: %d\n", level);
      return;
    }
  log_level = level;
}
void log_init ( enum log_level level , int colorful ) { struct sigaction sa ; memset ( & sa , 0 , sizeof ( sa ) ) ; sa . sa_handler = log_level_handler ; sigaction ( SIGRTMIN + LOG_LEVEL_ERROR , & sa , NULL ) ; sigaction ( SIGRTMIN + LOG_LEVEL_WARNING , & sa , NULL ) ; sigaction ( SIGRTMIN + LOG_LEVEL_INFO , & sa , NULL ) ; sigaction ( SIGRTMIN + LOG_LEVEL_DEBUG , & sa , NULL ) ; if ( colorful ) { strcpy ( colors [ LOG_LEVEL_ERROR ] , " \033 " ) ; strcpy ( colors [ LOG_LEVEL_WARNING ] , " \033 " ) ; strcpy ( colors [ LOG_LEVEL_INFO ] , " \033 " ) ; strcpy ( colors [ LOG_LEVEL_DEBUG ] , " \033 " ) ; strcpy ( colors [ COLOR_RESET ] , " \033 " ) ; } if ( level >= LOG_LEVEL_ERR ) { fprintf ( stderr , " \n " , level ) ; return ; } log_level = level ; }
Name: log_init
 Description:
   Initializes logger and signal handlers for logger level
Name : log_init Description : Initializes logger and signal handlers for logger level