|
| 1 | +/* |
| 2 | + * Copyright (C) 2019 Intel Corporation. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + */ |
| 5 | + |
| 6 | +#ifndef WASI_NN_LOGGER_H |
| 7 | +#define WASI_NN_LOGGER_H |
| 8 | + |
| 9 | +#include <stdio.h> |
| 10 | +#include <string.h> |
| 11 | + |
| 12 | +#define __FILENAME__ \ |
| 13 | + (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
| 14 | + |
| 15 | +/* Disable a level by removing the define */ |
| 16 | +#define ENABLE_ERR_LOG |
| 17 | +#define ENABLE_WARN_LOG |
| 18 | +#define ENABLE_DBG_LOG |
| 19 | +#define ENABLE_INFO_LOG |
| 20 | + |
| 21 | +// Definition of the levels |
| 22 | +#ifdef ENABLE_ERR_LOG |
| 23 | +#define NN_ERR_PRINTF(fmt, ...) \ |
| 24 | + do { \ |
| 25 | + printf("[%s:%d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__); \ |
| 26 | + printf("\n"); \ |
| 27 | + fflush(stdout); \ |
| 28 | + } while (0) |
| 29 | +#else |
| 30 | +#define NN_ERR_PRINTF(fmt, ...) |
| 31 | +#endif |
| 32 | +#ifdef ENABLE_WARN_LOG |
| 33 | +#define NN_WARN_PRINTF(fmt, ...) \ |
| 34 | + do { \ |
| 35 | + printf("[%s:%d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__); \ |
| 36 | + printf("\n"); \ |
| 37 | + fflush(stdout); \ |
| 38 | + } while (0) |
| 39 | +#else |
| 40 | +#define NN_WARN_PRINTF(fmt, ...) |
| 41 | +#endif |
| 42 | +#ifdef ENABLE_DBG_LOG |
| 43 | +#define NN_DBG_PRINTF(fmt, ...) \ |
| 44 | + do { \ |
| 45 | + printf("[%s:%d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__); \ |
| 46 | + printf("\n"); \ |
| 47 | + fflush(stdout); \ |
| 48 | + } while (0) |
| 49 | +#else |
| 50 | +#define NN_DBG_PRINTF(fmt, ...) |
| 51 | +#endif |
| 52 | +#ifdef ENABLE_INFO_LOG |
| 53 | +#define NN_INFO_PRINTF(fmt, ...) \ |
| 54 | + do { \ |
| 55 | + printf("[%s:%d] " fmt, __FILENAME__, __LINE__, ##__VA_ARGS__); \ |
| 56 | + printf("\n"); \ |
| 57 | + fflush(stdout); \ |
| 58 | + } while (0) |
| 59 | +#else |
| 60 | +#define NN_INFO_PRINTF(fmt, ...) |
| 61 | +#endif |
| 62 | + |
| 63 | +#endif |
0 commit comments