SpriteHTTPD - embedded HTTP server with read-only filesystem and templating, originally developed for ESP8266, now stand-alone and POSIX compatible.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spritehttpd/espfsbuilder/logging.h

125 lines
2.5 KiB

#pragma once
#include <stdio.h>
#ifndef VERBOSE_LOGGING
#define VERBOSE_LOGGING 1
#endif
#ifndef LOG_EOL
#define LOG_EOL "\n"
#endif
/**
* Print a startup banner message (printf syntax)
* Uses bright green color
*/
#define banner(fmt, ...) \
do { \
fprintf(stderr, LOG_EOL "\x1b[32;1m[i] " fmt "\x1b[0m" LOG_EOL, ##__VA_ARGS__); \
} while(0)
/**
* Same as 'info()', but enabled even if verbose logging is disabled.
* This can be used to print version etc under the banner.
*/
#define banner_info(fmt, ...) \
do { \
fprintf(stderr, "\x1b[32m[i] " fmt "\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
/**
* Empty line in the headers
*/
#define banner_gap() \
do { \
fprintf(stderr, LOG_EOL); \
} while(0)
#if VERBOSE_LOGGING
/**
* Print a debug log message (printf format)
*/
#define dbg(fmt, ...) \
do { \
fprintf(stderr, "[ ] " fmt LOG_EOL, ##__VA_ARGS__); \
} while(0)
/**
* Print a info log message (printf format)
* Uses bright green color
*/
#define info(fmt, ...) \
do { \
fprintf(stderr, "[i] " fmt "\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
#else
#define dbg(fmt, ...)
#define info(fmt, ...)
#endif
/**
* Print a error log message (printf format)
* Uses bright red color
*/
#define error(fmt, ...) \
do { \
fprintf(stderr, "[E] " fmt "\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
/**
* Print a warning log message (printf format)
* Uses bright yellow color
*/
#define warn(fmt, ...) \
do { \
fprintf(stderr, "[W] " fmt "\x1b[0m"LOG_EOL, ##__VA_ARGS__); \
} while(0)
// --------------- logging categories --------------------
#ifndef DEBUG_ESPFS
#define DEBUG_ESPFS 1
#endif
#ifndef DEBUG_HEATSHRINK
#define DEBUG_HEATSHRINK 1
#endif
#ifndef DEBUG_MALLOC
#define DEBUG_MALLOC 0
#endif
// filesystem
#if DEBUG_ESPFS
#define espfs_warn(...) warn(__VA_ARGS__)
#define espfs_dbg(...) dbg(__VA_ARGS__)
#define espfs_error(...) error(__VA_ARGS__)
#define espfs_info(...) info(__VA_ARGS__)
#else
#define espfs_dbg(...)
#define espfs_warn(...)
#define espfs_error(...)
#define espfs_info(...)
#endif
// captive portal
#if DEBUG_HEATSHRINK
#define heatshrink_warn(...) warn(__VA_ARGS__)
#define heatshrink_dbg(...) dbg(__VA_ARGS__)
#define heatshrink_error(...) error(__VA_ARGS__)
#define heatshrink_info(...) info(__VA_ARGS__)
#else
#define heatshrink_dbg(...)
#define heatshrink_warn(...)
#define heatshrink_error(...)
#define heatshrink_info(...)
#endif
// all malloc usage
#if DEBUG_MALLOC
#define mem_dbg(...) dbg(__VA_ARGS__)
#else
#define mem_dbg(...)
#endif