File size: 1,563 Bytes
8739cbb | 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 71 72 73 74 75 76 | #ifndef CELOG_H
#define CELOG_H
#include <stdio.h>
#include <stdarg.h>
#ifdef ANDROID
int __android_log_vprint(int prio, const char* tag, const char* fmt, __builtin_va_list ap)
__attribute__((__format__(printf, 3, 0)));
#ifndef LOG_TAG
#define LOG_TAG "CELOG"
#endif
#define LOGD(fmt, args...) __android_log_vprint(3, LOG_TAG, fmt, ##args)
#endif
#ifdef _WIN32
void __stdcall OutputDebugStringA(char* msg);
#endif
#ifdef __APPLE__
void openlog(char *ident, int logopt, int facility);
int setlogmask(int mskptr);
//int vsyslog(int priority, char* message, __builtin_va_list args);
void syslog(int priority, const char *message, ...);
#define LOG_USER 1 << 3
#define LOG_DEBUG 7
#define LOG_UPTO(pri) ((1 << (pri+1))-1)
#define LOG_NOTICE 5
int openedlog;
#endif
//stdio: int vsnprintf(char *str, int size, const char restrict *format, __builtin_va_list ap);
void debug_log(const char restrict * format , ...)
{
__builtin_va_list list;
__builtin_va_start(list,format);
#ifdef ANDROID
LOGD(format,list);
#elif __APPLE__
if (!openedlog)
{
openlog("CELOG",0,LOG_USER);
setlogmask(LOG_UPTO(LOG_DEBUG));
openedlog=1;
}
char log[256];
vsnprintf(log, 255, format, list);
log[255]=0;
syslog(LOG_NOTICE, log); //vsyslog didn't work as planned
#elif _WIN32
char log[256];
vsnprintf(log, 255, format, list);
log[256]=0;
OutputDebugStringA(log);
#endif
__builtin_va_end(list);
return;
}
#endif //CELOG_H
|