kmediad 0.5.0a
A cross-platform Web-based audio player
Functions | Variables
klib_log.c File Reference

Implementation of klib logging functions. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include "klib_log.h"
#include "klib_object.h"
#include "klib_string.h"
#include "klib_error.h"

Functions

void klib_log_set_output_callback (klib_Log_OutputProc proc, void *data)
 Set the function that will be called when the logger has formatted data.
void klib_log_set_level (int l)
 Set the global log level.
void klib_log (int level, const char *fmt,...)
 Log a message at the specified level, format as for printf()
int klib_log_get_level (void)
 Get the global log level.
void klib_log_error (const klib_Error *error)
const char * klib_log_level_to_string (int level)

Variables

int klib_log_level = 0
 Global variable to set overall log verbosity.

Detailed Description

Implementation of klib logging functions.


Function Documentation

void klib_log ( int  level,
const char *  fmt,
  ... 
)

Log a message at the specified level, format as for printf()

  {
  if (level > klib_log_level) return;

  va_list ap;
  va_start (ap, fmt);
  klib_String *sss = klib_string_new_empty();
  klib_string_vprintf (sss, fmt, ap);
  va_end (ap);

  if (output_proc)
    output_proc (level, sss->str, output_proc_data);
  else
    printf ("%s\n", sss->str);

  klib_object_unref ((klib_Object *)sss);
  }
void klib_log_error ( const klib_Error error)
int klib_log_get_level ( void  )

Get the global log level.

  {
  return klib_log_level;
  }
const char* klib_log_level_to_string ( int  level)
  {
  switch (level)
    {
    case KLIB_LOG_ERROR: return "error";
    case KLIB_LOG_WARNING: return "warning";
    case KLIB_LOG_INFO: return "info";
    }
  return "trace";
  }
void klib_log_set_level ( int  l)

Set the global log level.

  {
  klib_log_level = l;
  }
void klib_log_set_output_callback ( klib_Log_OutputProc  proc,
void *  data 
)

Set the function that will be called when the logger has formatted data.

Defaults to writing to stderr

  {
  output_proc = proc;
  output_proc_data = data;
  }

Variable Documentation

int klib_log_level = 0

Global variable to set overall log verbosity.

Callers should use klib_log_set_level and klib_log_get_level