forked from enlightenment/efl
Allow user provided functions for printing messages
Make the stdout print mgs function exportable Add a FILE * print msg function (useful for logging) SVN revision: 35404
This commit is contained in:
parent
bdf0f1bb71
commit
ee54713d9d
|
@ -19,6 +19,8 @@
|
||||||
#ifndef EINA_ERROR_H_
|
#ifndef EINA_ERROR_H_
|
||||||
#define EINA_ERROR_H_
|
#define EINA_ERROR_H_
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "eina_types.h"
|
#include "eina_types.h"
|
||||||
|
|
||||||
#define EINA_ERROR_PERR(fmt, ...) \
|
#define EINA_ERROR_PERR(fmt, ...) \
|
||||||
|
@ -43,6 +45,9 @@ typedef enum _Eina_Error_Level
|
||||||
} Eina_Error_Level;
|
} Eina_Error_Level;
|
||||||
|
|
||||||
typedef int Eina_Error;
|
typedef int Eina_Error;
|
||||||
|
typedef void (*Eina_Error_Print_Cb)(Eina_Error_Level level, const char *file,
|
||||||
|
const char *fnc, int line, const char *fmt, void *data,
|
||||||
|
va_list args);
|
||||||
|
|
||||||
EAPI extern int EINA_ERROR_OUT_OF_MEMORY;
|
EAPI extern int EINA_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
@ -54,6 +59,13 @@ EAPI void eina_error_set(Eina_Error err);
|
||||||
EAPI const char * eina_error_msg_get(Eina_Error error);
|
EAPI const char * eina_error_msg_get(Eina_Error error);
|
||||||
EAPI void eina_error_print(Eina_Error_Level level, const char *file,
|
EAPI void eina_error_print(Eina_Error_Level level, const char *file,
|
||||||
const char *function, int line, const char *fmt, ...);
|
const char *function, int line, const char *fmt, ...);
|
||||||
|
EAPI void eina_error_print_cb_stdout(Eina_Error_Level level, const char *file,
|
||||||
|
const char *fnc, int line, const char *fmt, void *data,
|
||||||
|
va_list args);
|
||||||
|
EAPI void eina_error_print_cb_file(Eina_Error_Level level, const char *file,
|
||||||
|
const char *fnc, int line, const char *fmt, void *data,
|
||||||
|
va_list args);
|
||||||
|
EAPI void eina_error_print_cb_set(Eina_Error_Print_Cb cb, void *data);
|
||||||
EAPI void eina_error_log_level_set(Eina_Error_Level level);
|
EAPI void eina_error_log_level_set(Eina_Error_Level level);
|
||||||
|
|
||||||
#endif /*EINA_ERROR_H_*/
|
#endif /*EINA_ERROR_H_*/
|
||||||
|
|
|
@ -33,6 +33,8 @@
|
||||||
static int _init_count = 0;
|
static int _init_count = 0;
|
||||||
static Eina_List *_error_list;
|
static Eina_List *_error_list;
|
||||||
static Eina_Error _err;
|
static Eina_Error _err;
|
||||||
|
static Eina_Error_Print_Cb _print_cb = eina_error_print_cb_stdout;
|
||||||
|
static void *_print_cb_data = NULL;
|
||||||
|
|
||||||
#define RED "\033[31;1m"
|
#define RED "\033[31;1m"
|
||||||
#define GREEN "\033[32;1m"
|
#define GREEN "\033[32;1m"
|
||||||
|
@ -55,17 +57,7 @@ static char *_colors[EINA_ERROR_LEVELS] = {
|
||||||
[EINA_ERROR_LEVEL_DBG] = GREEN,
|
[EINA_ERROR_LEVEL_DBG] = GREEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void _error_print(Eina_Error_Level level, const char *file,
|
|
||||||
const char *fnc, int line, const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
if (level <= _error_level)
|
|
||||||
{
|
|
||||||
printf("%s", _colors[level]);
|
|
||||||
printf("[%s:%d] %s() ", file, line, fnc);
|
|
||||||
printf("%s", _colors[EINA_ERROR_LEVEL_INFO]);
|
|
||||||
vprintf(fmt, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*============================================================================*
|
/*============================================================================*
|
||||||
* API *
|
* API *
|
||||||
*============================================================================*/
|
*============================================================================*/
|
||||||
|
@ -141,17 +133,50 @@ EAPI const char * eina_error_msg_get(int error)
|
||||||
return eina_list_nth(_error_list, error - 1);
|
return eina_list_nth(_error_list, error - 1);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
EAPI void eina_error_print(Eina_Error_Level level, const char *file,
|
EAPI void eina_error_print(Eina_Error_Level level, const char *file,
|
||||||
const char *fnc, int line, const char *fmt, ...)
|
const char *fnc, int line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
_error_print(level, file, fnc, line, fmt, args);
|
if (level <= _error_level)
|
||||||
|
_print_cb(level, file, fnc, line, fmt, _print_cb_data, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
EAPI void eina_error_print_cb_stdout(Eina_Error_Level level, const char *file,
|
||||||
|
const char *fnc, int line, const char *fmt, void *data,
|
||||||
|
va_list args)
|
||||||
|
{
|
||||||
|
printf("%s", _colors[level]);
|
||||||
|
printf("[%s:%d] %s() ", file, line, fnc);
|
||||||
|
printf("%s", _colors[EINA_ERROR_LEVEL_INFO]);
|
||||||
|
vprintf(fmt, args);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
EAPI void eina_error_print_cb_file(Eina_Error_Level level, const char *file,
|
||||||
|
const char *fnc, int line, const char *fmt, void *data,
|
||||||
|
va_list args)
|
||||||
|
{
|
||||||
|
FILE *f = data;
|
||||||
|
|
||||||
|
fprintf(f, "[%s:%d] %s() ", file, line, fnc);
|
||||||
|
vfprintf(f, fmt, args);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
EAPI void eina_error_print_cb_set(Eina_Error_Print_Cb cb, void *data)
|
||||||
|
{
|
||||||
|
_print_cb = cb;
|
||||||
|
_print_cb_data = data;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue