62 lines
1.1 KiB
C
62 lines
1.1 KiB
C
#pragma once
|
|
|
|
#include <stdio.h>
|
|
|
|
#define NTR_LEVEL_NONE (0)
|
|
#define NTR_LEVEL_ERROR (1)
|
|
#define NTR_LEVEL_WARNING (2)
|
|
#define NTR_LEVEL_INFO (3)
|
|
#define NTR_LEVEL_DEBUG (4)
|
|
#define NTR_LEVEL_DEFAULT (NTR_LEVEL_WARNING)
|
|
|
|
#define NTR_DEP_NTR (0)
|
|
#define NTR_DEP_USER1 (1)
|
|
#define NTR_DEP_USER2 (2)
|
|
#define NTR_DEP_USER3 (3)
|
|
#define NTR_DEP_USER4 (4)
|
|
#define NTR_DEP_USER5 (5)
|
|
#define NTR_DEP_MAX (NTR_DEP_USER5 + 1)
|
|
|
|
#define NTR_DECL_IMPL \
|
|
int ntr_log_levels[NTR_DEP_MAX] = {NTR_LEVEL_DEFAULT}; \
|
|
FILE * ntr_out = stdout
|
|
|
|
extern int ntr_log_levels[];
|
|
extern FILE * ntr_out;
|
|
|
|
static inline
|
|
void ntr(int dep, int level, const char * fmt, ...)
|
|
{
|
|
va_list vl;
|
|
va_start(vl, fmt);
|
|
if (dep < NTR_DEP_MAX && level <= ntr_log_levels[dep]) {
|
|
vfprintf(ntr_out, fmt, vl);
|
|
}
|
|
va_end(vl);
|
|
}
|
|
|
|
static inline
|
|
void ntr_set_level(int dep, int level)
|
|
{
|
|
if (dep < NTR_DEP_MAX) {
|
|
ntr_log_levels[dep] = level;
|
|
}
|
|
}
|
|
|
|
static inline
|
|
void ntr_set_output(FILE * f)
|
|
{
|
|
if (f != NULL) {
|
|
ntr_out = f;
|
|
}
|
|
}
|
|
|
|
static inline
|
|
int ntr_get_level(int dep)
|
|
{
|
|
if (dep < NTR_DEP_MAX) {
|
|
return ntr_log_levels[dep];
|
|
}
|
|
return 0;
|
|
}
|