Exemplo n.º 1
0
void
_log_handler_file_message(handler_t *handler, LogLevel level,
    const char *message)
{
  time_t t;
  struct tm *tm;
  const char *l;
  char *logfile;
  FILE *fd;

  logfile = log_handler_get_option(handler, LOG_HANDLER_FILE_OPTION_LOGFILE);
  if (!logfile)
    return;

  time(&t);
  tm = localtime(&t);

  l = log_get_level_name(level);

  fd = fopen(logfile, "a");
  if (!fd)
    return;

  fprintf(fd, "[%04d-%02d-%02d %02d:%02d:%02d] [%s] %s\n", tm->tm_year + 1900,
      tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, l, message);

  fclose(fd);
}
Exemplo n.º 2
0
static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
{
	int fmt = gd->log_fmt;

	/*
	 * The output format is designed to give someone a fighting chance of
	 * figuring out which field is which:
	 *    - level is in CAPS
	 *    - cat is lower case and ends with comma
	 *    - file normally has a .c extension and ends with a colon
	 *    - line is integer and ends with a -
	 *    - function is an identifier and ends with ()
	 *    - message has a space before it unless it is on its own
	 */
	if (fmt & (1 << LOGF_LEVEL))
		printf("%s.", log_get_level_name(rec->level));
	if (fmt & (1 << LOGF_CAT))
		printf("%s,", log_get_cat_name(rec->cat));
	if (fmt & (1 << LOGF_FILE))
		printf("%s:", rec->file);
	if (fmt & (1 << LOGF_LINE))
		printf("%d-", rec->line);
	if (fmt & (1 << LOGF_FUNC))
		printf("%s()", rec->func);
	if (fmt & (1 << LOGF_MSG))
		printf("%s%s", fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);

	return 0;
}