var scope reduction
[trinity.git] / include / log.h
bloba4d9e17f122f9635cbb1330a5067465dba66963a
1 #pragma once
3 #include <unistd.h>
4 #include "types.h"
5 #include "exit.h"
6 #include "shm.h"
8 #define ANSI_RED "\e[1;31m"
9 #define ANSI_GREEN "\e[1;32m"
10 #define ANSI_YELLOW "\e[1;33m"
11 #define ANSI_BLUE "\e[1;34m"
12 #define ANSI_MAGENTA "\e[1;35m"
13 #define ANSI_CYAN "\e[1;36m"
14 #define ANSI_WHITE "\e[1;37m"
15 #define ANSI_RESET "\e[0m"
17 #define RED if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_RED);
18 #define GREEN if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_GREEN);
19 #define YELLOW if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_YELLOW);
20 #define BLUE if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_BLUE);
21 #define MAGENTA if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_MAGENTA);
22 #define CYAN if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_CYAN);
23 #define WHITE if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_WHITE);
24 #define CRESET if (monochrome == FALSE) sptr += sprintf(sptr, "%s", ANSI_RESET);
26 #define REDFD if (mono == FALSE) fprintf(fd, "%s", ANSI_RED);
27 #define GREENFD if (mono == FALSE) fprintf(fd, "%s", ANSI_GREEN);
28 #define CRESETFD if (mono == FALSE) fprintf(fd, "%s", ANSI_RESET);
30 #define MAX_LOGLEVEL 3
31 unsigned int highest_logfile(void);
32 void synclogs(void);
33 void output(unsigned char level, const char *fmt, ...);
34 void outputerr(const char *fmt, ...);
35 void outputstd(const char *fmt, ...);
36 void output_syscall_prefix(const unsigned int childno, const unsigned int syscallno);
37 void output_syscall_postfix(unsigned long ret, int errno_saved, bool err);
39 void open_logfiles(void);
40 void close_logfiles(void);
41 void debugf(const char *fmt, ...);
43 #define __stringify_1(x...) #x
44 #define __stringify(x...) __stringify_1(x)
46 #ifndef GIT_VERSION
47 #define BUGTXT ANSI_RED "BUG!: " ANSI_RESET
48 #else
49 #define BUGTXT ANSI_RED "BUG!: " ANSI_RESET GIT_VERSION
50 #endif
52 #define BUG(bugtxt) { \
53 printf("[%d] %s:%s:%d %s", getpid(), __FILE__, __func__, __LINE__, bugtxt); \
54 while(1) { \
55 if (shm->exit_reason == EXIT_SIGINT) \
56 exit(EXIT_FAILURE); \
57 sleep(1); \
61 #define BUG_ON(condition) do { if ((condition)) BUG(BUGTXT); } while (0)