1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
/* -*- c -*-
* File: log.c
* Author: Igor Vlasenko <vlasenko@imath.kiev.ua>
* Created: Thu Sep 1 17:18:16 2005
*
* $Id$
*/
/* based on FFmpeg av_log API */
#include <stdio.h>
#include <string.h>
#include "tmpllog.h"
static int tmpl_log_level = TMPL_LOG_ERROR;
TMPLPRO_LOCAL FILE* tmpl_log_stream = NULL;
TMPLPRO_LOCAL void
tmpl_log_default_callback(int level, const char* fmt, va_list vl)
{
vfprintf(stderr, fmt, vl);
}
TMPLPRO_LOCAL void
tmpl_log_stream_callback(int level, const char* fmt, va_list vl)
{
vfprintf(tmpl_log_stream, fmt, vl);
fflush(tmpl_log_stream);
}
static void (*tmpl_log_callback)(int, const char*, va_list) = tmpl_log_default_callback;
TMPLPRO_LOCAL
void
tmpl_log(int level, const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
tmpl_vlog(level, fmt, vl);
va_end(vl);
}
TMPLPRO_LOCAL
void
tmpl_vlog(int level, const char *fmt, va_list vl)
{
if(level>tmpl_log_level) return;
tmpl_log_callback(level, fmt, vl);
}
TMPLPRO_LOCAL
int
tmpl_log_get_level(void)
{
return tmpl_log_level;
}
TMPLPRO_LOCAL
void
tmpl_log_set_level(int level)
{
tmpl_log_level = level;
}
TMPLPRO_LOCAL
void
tmpl_log_set_callback(void (*callback)(int, const char*, va_list))
{
tmpl_log_callback = callback;
}
|