Back to index

im-sdk  12.3.91
Defines | Enumerations | Functions
kolelog.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define LOGFILE   "/tmp/kole.log"

Enumerations

enum  LOGDEST { LOGDEST_STDOUT, LOGDEST_STDERR, LOGDEST_FILE }

Functions

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

Define Documentation

#define LOGFILE   "/tmp/kole.log"

Definition at line 25 of file kolelog.h.


Enumeration Type Documentation

enum LOGDEST
Enumerator:
LOGDEST_STDOUT 
LOGDEST_STDERR 
LOGDEST_FILE 

Definition at line 27 of file kolelog.h.


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;
  }
}