github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/nsenter/log.h (about) 1 #ifndef NSENTER_LOG_H 2 #define NSENTER_LOG_H 3 4 #include <stdio.h> 5 6 /* 7 * Log levels are the same as in logrus. 8 */ 9 #define PANIC 0 10 #define FATAL 1 11 #define ERROR 2 12 #define WARNING 3 13 #define INFO 4 14 #define DEBUG 5 15 #define TRACE 6 16 17 /* 18 * Sets up logging by getting log fd and log level from the environment, 19 * if available. 20 */ 21 void setup_logpipe(void); 22 23 void write_log(int level, const char *format, ...) __attribute__((format(printf, 2, 3))); 24 25 extern int logfd; 26 #define bail(fmt, ...) \ 27 do { \ 28 if (logfd < 0) \ 29 fprintf(stderr, "FATAL: " fmt ": %m\n", \ 30 ##__VA_ARGS__); \ 31 else \ 32 write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \ 33 exit(1); \ 34 } while(0) 35 36 37 #endif /* NSENTER_LOG_H */