Back to index

im-sdk  12.3.91
Functions | Variables
kolelog.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "kolelog.h"

Go to the source code of this file.

Functions

void KOLE_LOG (LOGDEST dest, char *fmt,...)

Variables

static FILE * fp = NULL

Function Documentation

void KOLE_LOG ( LOGDEST  dest,
char *  fmt,
  ... 
)

Definition at line 32 of file kolelog.c.

{
  char *fname;
  int strdup_was_called = 0;
  
  va_list va;
  char buffer[1024];
  va_start (va, fmt);
  vsnprintf (buffer, sizeof (buffer), fmt, va);
  va_end (va);

  switch (dest){
  case LOGDEST_STDOUT:
    fprintf (stdout, "%s\n", buffer);
    break;
  case LOGDEST_STDERR:
    fprintf (stderr, "%s\n", buffer);
    break;
  case LOGDEST_FILE:
    fname = (char *)getenv ("LOGFILE");
    if (!fname){
      fname = (char *) strdup (LOGFILE);
      strdup_was_called = 1;
    }
    fp = fopen (fname, "a");
    
    if (!fp){
      fprintf (stderr, "error writing log to file %s\n", fname);
      fprintf (stderr, "the error msg was\n");
      fprintf (stderr, "%s\n", buffer);
      break;
    }
    fprintf (fp, "%s\n", buffer);
    fclose (fp);
    if (strdup_was_called)
      free (fname);
    break;
  default:
    break;
  }
}

Variable Documentation

FILE* fp = NULL [static]

Definition at line 29 of file kolelog.c.